def test_import_create_no_update(self): 'existing remains untouched, not existing is created' ## T_0 ataceae = Family(family=u'Anacampserotaceae') # Eggli & Nyffeler linnaeus = Genus(family=ataceae, genus=u'Anacampseros') # L. self.session.add_all([ataceae, linnaeus]) self.session.commit() ## offer two objects for import importer = JSONImporter(MockImportView()) json_string = '[{"author": "L.", "epithet": "Anacampseros", '\ '"ht-epithet": "Anacampserotaceae", "ht-rank": "familia", '\ '"object": "taxon", "rank": "genus"}, {"author": "L.", '\ '"epithet": "Sedum", "ht-epithet": "Crassulaceae", '\ '"ht-rank": "familia", "object": "taxon", '\ '"rank": "genus"}]' with open(self.temp_path, "w") as f: f.write(json_string) importer.filename = self.temp_path importer.create = True importer.update = False importer.on_btnok_clicked(None) self.session.commit() ## T_1 sedum = Genus.retrieve_or_create( self.session, {'epithet': u"Sedum"}, create=False) self.assertEquals(sedum.__class__, Genus) self.assertEquals(sedum.author, u'L.') anacampseros = Genus.retrieve_or_create( self.session, {'epithet': u"Anacampseros"}, create=False) self.assertEquals(anacampseros.__class__, Genus) self.assertEquals(anacampseros.author, u'')
def test_use_author_to_break_ties(self): "importing homonym taxon is possible if authorship breaks ties" # Anacampseros was used twice, by Linnaeus, and by Miller ataceae = Family(family=u'Anacampserotaceae') # Eggli & Nyffeler linnaeus = Genus(family=ataceae, genus=u'Anacampseros', author=u'L.') claceae = Family(family=u'Crassulaceae') # J. St.-Hil. miller = Genus(family=claceae, genus=u'Anacampseros', author=u'Mill.') self.session.add_all([claceae, ataceae, linnaeus, miller]) self.session.commit() ## T_0 accepted = Genus.retrieve_or_create( self.session, {'epithet': u"Sedum"}, create=False) self.assertEquals(accepted, None) self.assertEquals(miller.accepted, None) ## what if we update Anacampseros Mill., with `accepted` information? json_string = ' {"author": "Mill.", "epithet": "Anacampseros", '\ '"ht-epithet": "Crassulaceae", "ht-rank": "familia", '\ '"object": "taxon", "rank": "genus", "accepted": {'\ '"author": "L.", "epithet": "Sedum", "ht-epithet": '\ '"Crassulaceae", "ht-rank": "familia", "object": "taxon", '\ '"rank": "genus"}}' with open(self.temp_path, "w") as f: f.write(json_string) importer = JSONImporter(MockImportView()) importer.filename = self.temp_path importer.on_btnok_clicked(None) self.session.commit() ## T_1 accepted = Genus.retrieve_or_create( self.session, {'epithet': u"Sedum"}, create=False) self.assertEquals(accepted.__class__, Genus) self.assertEquals(miller.accepted, accepted)
def test_import_ignores_id_new(self): "importing taxon disregards id value if present (new taxon)." previously = Genus.retrieve_or_create( self.session, {'epithet': u"Neogyna"}) self.assertEquals(previously, None) json_string = '[{"rank": "Genus", "epithet": "Neogyna", '\ '"ht-rank": "Familia", "ht-epithet": "Orchidaceae", '\ '"author": "Rchb. f.", "id": 1}]' with open(self.temp_path, "w") as f: f.write(json_string) importer = JSONImporter(MockImportView()) importer.filename = self.temp_path importer.on_btnok_clicked(None) self.session.commit() real_id = Genus.retrieve_or_create(self.session, {'epithet': u"Neogyna"}).id self.assertTrue(real_id != 1)
def test_import_with_synonym(self): "importing taxon with `accepted` field imports both taxa" json_string = '[{"rank": "Genus", "epithet": "Zygoglossum", '\ '"ht-rank": "Familia", "ht-epithet": "Orchidaceae", '\ '"author": "Reinw.", "accepted": {"rank": "Genus", '\ '"epithet": "Bulbophyllum", "ht-rank": "Familia", '\ '"ht-epithet": "Orchidaceae", "author": "Thouars"}}]' with open(self.temp_path, "w") as f: f.write(json_string) importer = JSONImporter(MockImportView()) importer.filename = self.temp_path importer.on_btnok_clicked(None) self.session.commit() synonym = Genus.retrieve_or_create( self.session, {'epithet': u"Zygoglossum"}) self.assertEquals(synonym.accepted.__class__, Genus) accepted = Genus.retrieve_or_create( self.session, {'epithet': u"Bulbophyllum"}) self.assertEquals(synonym.accepted, accepted)