def test_add_single_synonym(self): synonym_key = "synonym_key_1" TaxonomyManager.register_synonym_key("synonym_key_1") data = [ { 'id': 0, 'full_name': 'Family One', 'rank_name': 'One', 'rank': niamoto_db_meta.TaxonRankEnum.FAMILIA, 'parent_id': None, 'synonyms': {}, 'mptt_left': 0, 'mptt_right': 0, 'mptt_tree_id': 0, 'mptt_depth': 0, }, ] ins = niamoto_db_meta.taxon.insert().values(data) with Connector.get_connection() as connection: connection.execute(ins) TaxonomyManager.add_synonym_for_single_taxon(0, synonym_key, 1) df1 = TaxonomyManager.get_raw_taxon_dataframe() self.assertEqual(df1.loc[0]['synonyms'], {synonym_key: 1}) TaxonomyManager.add_synonym_for_single_taxon(0, synonym_key, 2) df2 = TaxonomyManager.get_raw_taxon_dataframe() self.assertEqual(df2.loc[0]['synonyms'], { synonym_key: 1, synonym_key: 2, })
def test_duplicate_synonym(self): synonym_key = "synonym_key_1" TaxonomyManager.register_synonym_key("synonym_key_1") data = [ { 'id': 0, 'full_name': 'Family One', 'rank_name': 'One', 'rank': niamoto_db_meta.TaxonRankEnum.FAMILIA, 'parent_id': None, 'synonyms': {}, 'mptt_left': 0, 'mptt_right': 0, 'mptt_tree_id': 0, 'mptt_depth': 0, }, { 'id': 1, 'full_name': 'Family Two', 'rank_name': 'Two', 'rank': niamoto_db_meta.TaxonRankEnum.FAMILIA, 'parent_id': None, 'synonyms': {}, 'mptt_left': 0, 'mptt_right': 0, 'mptt_tree_id': 0, 'mptt_depth': 0, }, ] ins = niamoto_db_meta.taxon.insert().values(data) with Connector.get_connection() as connection: connection.execute(ins) TaxonomyManager.add_synonym_for_single_taxon(0, synonym_key, 1) self.assertRaises( IntegrityError, TaxonomyManager.add_synonym_for_single_taxon, 1, synonym_key, 1, )