From c5cfcca8709cdd7df646b576d6a2713d9f6279b8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 24 Mar 2020 18:26:16 +0100 Subject: [PATCH 1/6] without shortmanes of instrument and platform//two new unittests are added --- geospaas/catalog/fixtures/catalog.json | 4 +-- geospaas/catalog/tests.py | 31 +++++++++++++++++++ .../vocabularies/fixtures/vocabularies.json | 22 +++++++++++++ geospaas/vocabularies/managers.py | 8 ++--- geospaas/vocabularies/models.py | 8 ++--- 5 files changed, 63 insertions(+), 10 deletions(-) diff --git a/geospaas/catalog/fixtures/catalog.json b/geospaas/catalog/fixtures/catalog.json index b3f0ca3d..bff55511 100644 --- a/geospaas/catalog/fixtures/catalog.json +++ b/geospaas/catalog/fixtures/catalog.json @@ -2,8 +2,8 @@ "pk": 1, "model": "catalog.source", "fields": { - "platform": ["AQUA"], - "instrument": ["MODIS"], + "platform": 102, + "instrument": 526, "specs": "Nothing special" } },{ diff --git a/geospaas/catalog/tests.py b/geospaas/catalog/tests.py index f510b2bf..b340546a 100644 --- a/geospaas/catalog/tests.py +++ b/geospaas/catalog/tests.py @@ -206,6 +206,37 @@ def test_source(self): i = Instrument.objects.get(short_name='MODIS') source = Source(platform=p, instrument=i) source.save() + + def test_source_without_short_names(self): + p = Platform.objects.get(pk=796) + i = Instrument.objects.get(pk=1458) + source = Source(platform=p, instrument=i) + source.save() + self.assertEqual(source.platform.long_name, "") + self.assertEqual(source.platform.series_entity, "series_entity_without_short_name") + self.assertEqual(source.instrument.long_name, "") + self.assertEqual(source.instrument.category, "category_without_short_name") + + def test_source_empty_without_short_names(self): + 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, "") class TestCountCommand(TestCase): fixtures = ['vocabularies', 'catalog'] diff --git a/geospaas/vocabularies/fixtures/vocabularies.json b/geospaas/vocabularies/fixtures/vocabularies.json index 7889b9b4..5916a3fe 100644 --- a/geospaas/vocabularies/fixtures/vocabularies.json +++ b/geospaas/vocabularies/fixtures/vocabularies.json @@ -17483,6 +17483,18 @@ "model": "vocabularies.instrument", "pk": 1457 }, +{ + "fields": { + "category": "category_without_short_name", + "short_name": "", + "long_name": "", + "subtype": "", + "type": "", + "instrument_class": "" + }, + "model": "vocabularies.instrument", + "pk": 1458 +}, { "fields": { "category": "Aircraft", @@ -25433,6 +25445,16 @@ "model": "vocabularies.platform", "pk": 795 }, +{ + "fields": { + "category": "", + "long_name": "", + "series_entity": "series_entity_without_short_name", + "short_name": "" + }, + "model": "vocabularies.platform", + "pk": 796 +}, { "fields": { "category": "EARTH SCIENCE", diff --git a/geospaas/vocabularies/managers.py b/geospaas/vocabularies/managers.py index 1846b135..29e565ef 100644 --- a/geospaas/vocabularies/managers.py +++ b/geospaas/vocabularies/managers.py @@ -119,8 +119,8 @@ 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) + #def get_by_natural_key(self, short_name): + # return self.get(short_name=short_name) class InstrumentManager(VocabularyManager): @@ -133,8 +133,8 @@ 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) + #def get_by_natural_key(self, short_name): + # return self.get(short_name=short_name) class ScienceKeywordManager(VocabularyManager): diff --git a/geospaas/vocabularies/models.py b/geospaas/vocabularies/models.py index 721c15b3..f523f414 100644 --- a/geospaas/vocabularies/models.py +++ b/geospaas/vocabularies/models.py @@ -27,8 +27,8 @@ class Platform(models.Model): def __str__(self): return str(self.short_name) - def natural_key(self): - return (self.short_name) + #def natural_key(self): + # return (self.short_name) class Instrument(models.Model): @@ -44,8 +44,8 @@ class Instrument(models.Model): def __str__(self): return str(self.short_name) - def natural_key(self): - return (self.short_name) + #def natural_key(self): + # return (self.short_name) class ISOTopicCategory(models.Model): ''' From 7aecf5b1474db909a07890ac942553a1cae8736b Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 26 Mar 2020 14:43:40 +0100 Subject: [PATCH 2/6] #1 the third test for investigating the uniqueness of source is added from get_or_create method --- geospaas/catalog/tests.py | 34 ++++++++++++++----- .../vocabularies/fixtures/vocabularies.json | 22 ------------ geospaas/vocabularies/managers.py | 4 --- geospaas/vocabularies/models.py | 6 ++-- 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/geospaas/catalog/tests.py b/geospaas/catalog/tests.py index b340546a..9340d998 100644 --- a/geospaas/catalog/tests.py +++ b/geospaas/catalog/tests.py @@ -207,17 +207,21 @@ def test_source(self): source = Source(platform=p, instrument=i) source.save() - def test_source_without_short_names(self): - p = Platform.objects.get(pk=796) - i = Instrument.objects.get(pk=1458) + 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.long_name, "") - self.assertEqual(source.platform.series_entity, "series_entity_without_short_name") - self.assertEqual(source.instrument.long_name, "") - self.assertEqual(source.instrument.category, "category_without_short_name") + 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_source_empty_without_short_names(self): + def test_empty_short_names(self): + ''' creating objects without short_name and creating source + based on them''' Platform2=Platform(category = '', series_entity = '', short_name = '', @@ -238,6 +242,20 @@ def test_source_empty_without_short_names(self): self.assertEqual(source2.instrument.long_name, "") self.assertEqual(source2.instrument.category, "") + def test_source_uniqueness(self): + + p = Platform.objects.get(pk=661) # "short_name": "" + i = Instrument.objects.get(pk=139)# "short_name": "" + source,_ = Source.objects.get_or_create(platform=p, instrument=i) + source2, created = Source.objects.get_or_create(platform=p, instrument=i) + self.assertEqual(created, 0) + self.assertEqual(source2, source) + i2 = Instrument.objects.get(pk=136)# "short_name": "SCATTEROMETERS" + source3,_ = Source.objects.get_or_create(platform=p, instrument=i2) + self.assertNotEqual(source3, source2) + + + class TestCountCommand(TestCase): fixtures = ['vocabularies', 'catalog'] def test_count_command(self): diff --git a/geospaas/vocabularies/fixtures/vocabularies.json b/geospaas/vocabularies/fixtures/vocabularies.json index 5916a3fe..7889b9b4 100644 --- a/geospaas/vocabularies/fixtures/vocabularies.json +++ b/geospaas/vocabularies/fixtures/vocabularies.json @@ -17483,18 +17483,6 @@ "model": "vocabularies.instrument", "pk": 1457 }, -{ - "fields": { - "category": "category_without_short_name", - "short_name": "", - "long_name": "", - "subtype": "", - "type": "", - "instrument_class": "" - }, - "model": "vocabularies.instrument", - "pk": 1458 -}, { "fields": { "category": "Aircraft", @@ -25445,16 +25433,6 @@ "model": "vocabularies.platform", "pk": 795 }, -{ - "fields": { - "category": "", - "long_name": "", - "series_entity": "series_entity_without_short_name", - "short_name": "" - }, - "model": "vocabularies.platform", - "pk": 796 -}, { "fields": { "category": "EARTH SCIENCE", diff --git a/geospaas/vocabularies/managers.py b/geospaas/vocabularies/managers.py index 29e565ef..33b6f19b 100644 --- a/geospaas/vocabularies/managers.py +++ b/geospaas/vocabularies/managers.py @@ -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): @@ -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): diff --git a/geospaas/vocabularies/models.py b/geospaas/vocabularies/models.py index f523f414..51ac0090 100644 --- a/geospaas/vocabularies/models.py +++ b/geospaas/vocabularies/models.py @@ -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): @@ -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): ''' From 4e90168151003a4e05b7597e5c0931bb932384e7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 27 Mar 2020 14:42:12 +0100 Subject: [PATCH 3/6] the name of variable are modified in the tests in order to be standard naming --- geospaas/catalog/tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/geospaas/catalog/tests.py b/geospaas/catalog/tests.py index 9340d998..31bd6189 100644 --- a/geospaas/catalog/tests.py +++ b/geospaas/catalog/tests.py @@ -233,9 +233,9 @@ def test_empty_short_names(self): subtype = '', short_name = '', long_name = '') - Platform2.save() - Instrument2.save() - source2 = Source(platform=Platform2, instrument=Instrument2) + platform2.save() + instrument2.save() + source2 = Source(platform=platform2, instrument=instrument2) source2.save() self.assertEqual(source2.platform.long_name, "") self.assertEqual(source2.platform.series_entity, "") From fc593133a381e2bc3edfaf40b890481b3ff5ec9d Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 27 Mar 2020 14:53:15 +0100 Subject: [PATCH 4/6] #80 the name of variable are modified in the tests in order to be standard naming --- geospaas/catalog/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/geospaas/catalog/tests.py b/geospaas/catalog/tests.py index 31bd6189..589f2817 100644 --- a/geospaas/catalog/tests.py +++ b/geospaas/catalog/tests.py @@ -222,11 +222,11 @@ def test_without_short_names(self): def test_empty_short_names(self): ''' creating objects without short_name and creating source based on them''' - Platform2=Platform(category = '', + platform2=Platform(category = '', series_entity = '', short_name = '', long_name = '') - Instrument2=Instrument( + instrument2=Instrument( category ='', instrument_class = '', type = '', From 9c9b085f6166e2d12acdc6b48fb8a36e7911c1e3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 27 Mar 2020 14:56:13 +0100 Subject: [PATCH 5/6] #80 the name of variable are modified in the tests in order to be standard naming --- geospaas/catalog/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geospaas/catalog/tests.py b/geospaas/catalog/tests.py index 589f2817..880c35fe 100644 --- a/geospaas/catalog/tests.py +++ b/geospaas/catalog/tests.py @@ -248,7 +248,7 @@ def test_source_uniqueness(self): i = Instrument.objects.get(pk=139)# "short_name": "" source,_ = Source.objects.get_or_create(platform=p, instrument=i) source2, created = Source.objects.get_or_create(platform=p, instrument=i) - self.assertEqual(created, 0) + self.assertFalse(created) self.assertEqual(source2, source) i2 = Instrument.objects.get(pk=136)# "short_name": "SCATTEROMETERS" source3,_ = Source.objects.get_or_create(platform=p, instrument=i2) From 77b7905942449f507dd5869285f54e167114bdcb Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 30 Mar 2020 13:21:15 +0200 Subject: [PATCH 6/6] #80 assertFlase is also added and the names are chagned based on pep --- geospaas/catalog/tests.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/geospaas/catalog/tests.py b/geospaas/catalog/tests.py index 880c35fe..80d9f273 100644 --- a/geospaas/catalog/tests.py +++ b/geospaas/catalog/tests.py @@ -244,14 +244,15 @@ def test_empty_short_names(self): def test_source_uniqueness(self): - p = Platform.objects.get(pk=661) # "short_name": "" - i = Instrument.objects.get(pk=139)# "short_name": "" - source,_ = Source.objects.get_or_create(platform=p, instrument=i) - source2, created = Source.objects.get_or_create(platform=p, instrument=i) - self.assertFalse(created) + 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) - i2 = Instrument.objects.get(pk=136)# "short_name": "SCATTEROMETERS" - source3,_ = Source.objects.get_or_create(platform=p, instrument=i2) + inst2 = Instrument.objects.get(pk=160)# "short_name": "" + source3,_ = Source.objects.get_or_create(platform=plat1, instrument=inst2) self.assertNotEqual(source3, source2)