-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
But we still have unique_together in the Source model. I guess that should stay like it is. But we have to test if it is working. That's why I suggested to add one more test.
Please add this test and fix small things here and there.
geospaas/catalog/tests.py
Outdated
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better not to add new entries to vocabularies fixtures and rather to use existing entries with empty short_name, long_name, etc.
geospaas/catalog/tests.py
Outdated
self.assertEqual(source.instrument.category, "category_without_short_name") | ||
|
||
def test_source_empty_without_short_names(self): | ||
Platform2=Platform(category = '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use conventional for variable naming: variable names start from block letters. Class names from capital. Read more here:
http://www.python.org/dev/peps/pep-0008/
And here:
https://nansat.readthedocs.io/en/latest/source/conventions.html
self.assertEqual(source2.platform.long_name, "") | ||
self.assertEqual(source2.platform.series_entity, "") | ||
self.assertEqual(source2.instrument.long_name, "") | ||
self.assertEqual(source2.instrument.category, "") |
There was a problem hiding this comment.
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.
@@ -17483,6 +17483,18 @@ | |||
"model": "vocabularies.instrument", | |||
"pk": 1457 | |||
}, | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed. We have already enough instruments and platforms with empty fields in fixtures.
geospaas/vocabularies/managers.py
Outdated
@@ -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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to remove completely rather than comment out. We wills still have it in git history. And the code remains cleaner without.
One minor comment. Please use conventions for branch naming as well next time. It could have been named e.g. issue1-natural-key, or something similar. |
… from get_or_create method
@akorosov |
Yeah, test is good. Please also change other things. |
@akorosov |
Not yet. Next time it would be easier if you click on 'Commit suggestion' so that it disappears from the discussion above. |
geospaas/catalog/tests.py
Outdated
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here short_name should also be empty. But it should be instrument other than 139.
geospaas/catalog/tests.py
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.assertEqual(created, 0) | |
self.assertFalse(created2) |
geospaas/catalog/tests.py
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source2, created = Source.objects.get_or_create(platform=p, instrument=i) | |
source2, created2 = Source.objects.get_or_create(platform=p, instrument=i) |
geospaas/catalog/tests.py
Outdated
|
||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source,_ = Source.objects.get_or_create(platform=p, instrument=i) | |
source,create1 = Source.objects.get_or_create(platform=p, instrument=i) | |
self.assertTrue(create1) |
geospaas/catalog/tests.py
Outdated
def test_empty_short_names(self): | ||
''' creating objects without short_name and creating source | ||
based on them''' | ||
Platform2=Platform(category = '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Platform2=Platform(category = '', | |
platform2=Platform(category = '', |
Great job, thank you @aanersc ! |
…added