Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

without short manes of instrument and platform//two new unittests are … #80

Merged
merged 6 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions geospaas/catalog/fixtures/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"pk": 1,
"model": "catalog.source",
"fields": {
"platform": ["AQUA"],
"instrument": ["MODIS"],
"platform": 102,
"instrument": 526,
"specs": "Nothing special"
}
},{
Expand Down
50 changes: 50 additions & 0 deletions geospaas/catalog/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,56 @@ def test_source(self):
i = Instrument.objects.get(short_name='MODIS')
source = Source(platform=p, instrument=i)
source.save()

def test_without_short_names(self):
''' retrieving objects without short_name from the database and creating source
based on them'''
p = Platform.objects.get(pk=168)
i = Instrument.objects.get(pk=140)
source = Source(platform=p, instrument=i)
source.save()
self.assertEqual(source.platform.short_name, "")
self.assertEqual(source.platform.series_entity, "Earth Explorers")
self.assertEqual(source.instrument.short_name, "")
self.assertEqual(source.instrument.subtype, "Lidar/Laser Spectrometers")

def test_empty_short_names(self):
''' creating objects without short_name and creating source
based on them'''
platform2=Platform(category = '',
series_entity = '',
short_name = '',
long_name = '')
instrument2=Instrument(
category ='',
instrument_class = '',
type = '',
subtype = '',
short_name = '',
long_name = '')
platform2.save()
instrument2.save()
source2 = Source(platform=platform2, instrument=instrument2)
source2.save()
self.assertEqual(source2.platform.long_name, "")
self.assertEqual(source2.platform.series_entity, "")
self.assertEqual(source2.instrument.long_name, "")
self.assertEqual(source2.instrument.category, "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is important to have one more test :

Use get_or_create to add one Source pointing to one Instrument and one Latform with short names.
Use get_or_create to add exactly the same source. Test assert that create equals False in this case and source2 is equal to source 1.

Use get_or_create to add Source with the same Instrument but a different Platform (also with empty short name). Test assert that in that case create equals True and source 3 is not equal source 1.


def test_source_uniqueness(self):

plat1 = Platform.objects.get(pk=661) # "short_name": ""
inst1 = Instrument.objects.get(pk=139)# "short_name": ""
source, created1 = Source.objects.get_or_create(platform=plat1, instrument=inst1)
source2, created2 = Source.objects.get_or_create(platform=plat1, instrument=inst1)
self.assertTrue(created1)
self.assertFalse(created2)
self.assertEqual(source2, source)
inst2 = Instrument.objects.get(pk=160)# "short_name": ""
source3,_ = Source.objects.get_or_create(platform=plat1, instrument=inst2)
self.assertNotEqual(source3, source2)



class TestCountCommand(TestCase):
fixtures = ['vocabularies', 'catalog']
Expand Down
4 changes: 0 additions & 4 deletions geospaas/vocabularies/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ class PlatformManager(VocabularyManager):
short_name='Short_Name',
long_name='Long_Name')

def get_by_natural_key(self, short_name):
return self.get(short_name=short_name)


class InstrumentManager(VocabularyManager):
Expand All @@ -133,8 +131,6 @@ class InstrumentManager(VocabularyManager):
short_name='Short_Name',
long_name='Long_Name')

def get_by_natural_key(self, short_name):
return self.get(short_name=short_name)


class ScienceKeywordManager(VocabularyManager):
Expand Down
6 changes: 2 additions & 4 deletions geospaas/vocabularies/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class Platform(models.Model):
def __str__(self):
return str(self.short_name)

def natural_key(self):
return (self.short_name)


class Instrument(models.Model):

Expand All @@ -44,8 +43,7 @@ class Instrument(models.Model):
def __str__(self):
return str(self.short_name)

def natural_key(self):
return (self.short_name)


class ISOTopicCategory(models.Model):
'''
Expand Down