def test_partial_taxonomic_with_synonymy(self): "exporting one genus which is not an accepted name." f = self.session.query( Family).filter( Family.family == u'Orchidaceae').one() bu = Genus(family=f, genus=u'Bulbophyllum') # accepted zy = Genus(family=f, genus=u'Zygoglossum') # synonym bu.synonyms.append(zy) self.session.add_all([f, bu, zy]) self.session.commit() selection = self.session.query(Genus).filter( Genus.genus == u'Zygoglossum').all() mock_view.set_selection(selection) exporter = JSONExporter(mock_view) exporter.start(self.temp_path, selection) result = json.load(open(self.temp_path)) self.assertEquals(len(result), 1) self.assertEquals(result[0]['rank'], 'genus') self.assertEquals(result[0]['epithet'], 'Zygoglossum') self.assertEquals(result[0]['ht-rank'], 'familia') self.assertEquals(result[0]['ht-epithet'], 'Orchidaceae') accepted = result[0].get('accepted') self.assertTrue(isinstance(accepted, dict)) self.assertEquals(accepted['rank'], 'genus') self.assertEquals(accepted['epithet'], 'Bulbophyllum') self.assertEquals(accepted['ht-rank'], 'familia') self.assertEquals(accepted['ht-epithet'], 'Orchidaceae')
def test_writes_complete_database(self): "exporting without specifying what: export complete database" mock_view.set_selection([]) exporter = JSONExporter(mock_view) exporter.start(self.temp_path) ## must still check content of generated file! result = json.load(open(self.temp_path)) self.assertEquals(len(result), 5) families = [i for i in result if i['rank'] == 'familia'] self.assertEquals(len(families), 2) genera = [i for i in result if i['rank'] == 'genus'] self.assertEquals(len(genera), 2) species = [i for i in result if i['rank'] == 'species'] self.assertEquals(len(species), 1) self.assertEquals(open(self.temp_path).read(), """\ [{"epithet": "Orchidaceae", "object": "taxon", "rank": "familia"}, {"epithet": "Myrtaceae", "object": "taxon", "rank": "familia"}, {"author": "R. Br.", "epithet": "Calopogon", "ht-epithet": "Orchidaceae", \ "ht-rank": "familia", "object": "taxon", "rank": "genus"}, {"author": "", "epithet": "Panisea", "ht-epithet": "Orchidaceae", \ "ht-rank": "familia", "object": "taxon", "rank": "genus"}, {"epithet": "tuberosus", "ht-epithet": "Calopogon", "ht-rank": "genus", \ "hybrid": false, "object": "taxon", "rank": "species"}]""")
def test_writes_full_taxonomic_info(self): "exporting one family: export full taxonomic information below family" selection = self.session.query(Family).filter( Family.family == u'Orchidaceae').all() mock_view.set_selection(selection) exporter = JSONExporter(mock_view) exporter.start(self.temp_path, selection) result = json.load(open(self.temp_path)) self.assertEquals(len(result), 1) self.assertEquals(result[0]['rank'], 'familia') self.assertEquals(result[0]['epithet'], 'Orchidaceae')
def test_writes_partial_taxonomic_info(self): "exporting one genus: all species below genus" selection = self.session.query(Genus).filter( Genus.genus == u'Calopogon').all() mock_view.set_selection(selection) exporter = JSONExporter(mock_view) exporter.start(self.temp_path, selection) result = json.load(open(self.temp_path)) self.assertEquals(len(result), 1) self.assertEquals(result[0]['rank'], 'genus') self.assertEquals(result[0]['epithet'], 'Calopogon') self.assertEquals(result[0]['ht-rank'], 'familia') self.assertEquals(result[0]['ht-epithet'], 'Orchidaceae') self.assertEquals(result[0]['author'], 'R. Br.')
def test_writes_partial_taxonomic_info_species(self): "exporting one species: all species below species" selection = self.session.query( Species).filter(Species.sp == u'tuberosus').join( Genus).filter(Genus.genus == u"Calopogon").all() mock_view.set_selection(selection) exporter = JSONExporter(mock_view) exporter.start(self.temp_path, selection) result = json.load(open(self.temp_path)) self.assertEquals(len(result), 1) self.assertEquals(result[0]['rank'], 'species') self.assertEquals(result[0]['epithet'], 'tuberosus') self.assertEquals(result[0]['ht-rank'], 'genus') self.assertEquals(result[0]['ht-epithet'], 'Calopogon') self.assertEquals(result[0]['hybrid'], False)