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(self): """ Test the HistoryMapperExtension """ from bauble.plugins.plants import Family f = Family(epithet=u'Family') self.session.add(f) self.session.commit() q = self.session.query(db.History).\ order_by(db.History.timestamp.desc()) history = q.first() base_count = q.count() self.assertEquals(history.table_name, 'family') self.assertEquals(history.operation, 'insert') f.author = u'L.' self.session.commit() q = self.session.query(db.History).\ order_by(db.History.timestamp.desc()) history = q.first() self.assertEquals(q.count(), base_count + 1) self.assertEquals(history.table_name, 'family') self.assertEquals(history.operation, 'update') f.author = u'Rch.' self.session.commit() q = self.session.query(db.History).\ order_by(db.History.timestamp.desc()) history = q.first() self.assertEquals(q.count(), base_count + 2) self.assertEquals(history.table_name, 'family') self.assertEquals(history.operation, 'update') f.epithet = u'CanWeRename' self.session.commit() q = self.session.query(db.History).\ order_by(db.History.timestamp.desc()) history = q.first() self.assertEquals(q.count(), base_count + 3) self.assertEquals(history.table_name, 'family') self.assertEquals(history.operation, 'update') self.session.delete(f) self.session.commit() q = self.session.query(db.History).\ order_by(db.History.timestamp.desc()) history = q.first() self.assertEquals(q.count(), base_count + 4) self.assertEquals(history.table_name, 'family') self.assertEquals(history.operation, 'delete')
def test_get_tag_ids(self): family2 = Family(family=u'family2') self.session.add(family2) self.session.commit() tag_plugin.tag_objects('test', [self.family, family2]) tag_plugin.tag_objects('test2', [self.family]) # test we only return the ids the objects have in common #sel = select([tag_table.c.id], tag_table.c.tag==u'test') results = self.session.query(Tag.id).filter_by(tag=u'test') test_id = [r[0] for r in results] # should only return id for "test" ids = tag_plugin.get_tag_ids([self.family, family2]) self.assert_(ids == test_id, '%s==%s' % (ids, test_id)) # test that we return multiple tag ids if the objs share tags tag_plugin.tag_objects('test2', [family2]) #sel = select([tag_table.c.id], or_(tag_table.c.tag==u'test', # tag_table.c.tag==u'test2')) results = self.session.query(Tag.id).filter( or_(Tag.tag == u'test', Tag.tag == u'test2')) test_id = sorted([r[0] for r in results]) # should return ids for both test and test2 ids = sorted(tag_plugin.get_tag_ids([self.family, family2])) self.assert_(ids == test_id, '%s == %s' % (ids, test_id))
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_export_with_vernacular(self): "exporting one genus which is not an accepted name." ## precondition sola = Family(family='Solanaceae') brug = Genus(family=sola, genus=u'Brugmansia') arbo = Species(genus=brug, sp=u'arborea') vern = VernacularName(species=arbo, language=u"es", name=u"Floripondio") self.session.add_all([sola, brug, arbo, vern]) self.session.commit() ## action exporter = JSONExporter(MockView()) exporter.view.selection = None exporter.selection_based_on = 'sbo_taxa' exporter.include_private = False exporter.filename = self.temp_path exporter.run() ## check result = json.load(open(self.temp_path)) vern_from_json = [i for i in result if i['object'] == 'vernacular_name'] self.assertEquals(len(vern_from_json), 1) self.assertEquals(vern_from_json[0]['language'], 'es')
def test_tag_objects(self): family2 = Family(epithet=u'family2') self.session.add(family2) self.session.commit() family1_id = self.family.id family2_id = family2.id tag_plugin.tag_objects('test', [self.family, family2]) # we do not offer gettin object by string # get object by tag tag = self.session.query(Tag).filter_by(tag=u'test').one() tagged_objs = tag.objects sorted_pairs = sorted([(type(o), o.id) for o in tagged_objs]) self.assertEquals(sorted([(Family, family1_id), (Family, family2_id)]), sorted_pairs) tag_plugin.tag_objects('test', [self.family, family2]) self.assertEquals(tag.objects, [self.family, family2]) # # now untag everything # tag_plugin.untag_objects('test', [self.family, family2]) # get object by tag tag = self.session.query(Tag).filter_by(tag=u'test').one() tagged_objs = tag.objects self.assertEquals(tagged_objs, [])
def setUp(self): super(AttachedToTests, self).setUp() obj1 = Tag(tag=u'medicinal') obj2 = Tag(tag=u'maderable') obj3 = Tag(tag=u'frutal') fam = Family(family=u'Solanaceae') self.session.add_all([obj1, obj2, obj3, fam]) self.session.commit()
def test(self): """ Test the HistoryMapperExtension """ from bauble.plugins.plants import Family f = Family(family=u"Family") self.session.add(f) self.session.commit() history = self.session.query(db.History).order_by(db.History.timestamp.desc()).first() assert history.table_name == "family" and history.operation == "insert" f.family = u"Family2" self.session.commit() history = self.session.query(db.History).order_by(db.History.timestamp.desc()).first() assert history.table_name == "family" and history.operation == "update" self.session.delete(f) self.session.commit() history = self.session.query(db.History).order_by(db.History.timestamp.desc()).first() assert history.table_name == "family" and history.operation == "delete"
def test(self): """ Test the HistoryMapperExtension """ from bauble.plugins.plants import Family f = Family(family=u'Family') self.session.add(f) self.session.commit() history = self.session.query(db.History).\ order_by(db.History.timestamp.desc()).first() assert history.table_name == 'family' and history.operation == 'insert' f.family = u'Family2' self.session.commit() history = self.session.query(db.History).\ order_by(db.History.timestamp.desc()).first() assert history.table_name == 'family' and history.operation == 'update' self.session.delete(f) self.session.commit() history = self.session.query(db.History).\ order_by(db.History.timestamp.desc()).first() assert history.table_name == 'family' and history.operation == 'delete'
def setUp(self, *args): super(MakoFormatterTests, self).setUp() fctr = gctr = sctr = actr = pctr = 0 for f in xrange(2): fctr += 1 family = Family(id=fctr, epithet=u'fam%s' % fctr) self.session.add(family) for g in range(2): gctr += 1 genus = Genus(id=gctr, family=family, epithet=u'gen%s' % gctr) self.session.add(genus) for s in range(2): sctr += 1 sp = Species(id=sctr, genus=genus, epithet=u'sp%s' % sctr) # TODO: why doesn't this geography, species # distribution stuff seem to work geo = Geography(id=sctr, name=u'Mexico%s' % sctr) dist = SpeciesDistribution(geography_id=sctr) sp.distribution.append(dist) vn = VernacularName(id=sctr, species=sp, name=u'name%s' % sctr) self.session.add_all([sp, geo, dist, vn]) for a in range(2): actr += 1 acc = Accession(id=actr, species=sp, code=u'%s' % actr) self.session.add(acc) for p in range(2): pctr += 1 loc = Location(id=pctr, code=u'%s' % pctr, name=u'site%s' % pctr) plant = Plant(id=pctr, accession=acc, location=loc, code=u'%s' % pctr, quantity=1) #debug('fctr: %s, gctr: %s, actr: %s, pctr: %s' \ # % (fctr, gctr, actr, pctr)) self.session.add_all([loc, plant]) self.session.commit()
def test_infopage(self): raise SkipTest('Not Implemented') from bauble.plugins.plants import Family, Genus, Species email = '' passwd = '' album = 'Plants' if email: token = picasa.get_auth_token(email, passwd) picasa.update_meta(email=email, album=album, token=token) f = Family(family=u'Orchidaceae') g = Genus(family=f, genus=u'Maxillaria') sp = Species(genus=g, sp=u'elatior') self.session.add_all([f, g, sp]) self.session.commit() self.dialog = gtk.Dialog() self.dialog.set_size_request(250, 700) page = picasa.PicasaInfoPage() page.update(sp) self.dialog.vbox.pack_start(page) self.dialog.show_all() self.dialog.run()
def test_tag_objects(self): family2 = Family(family=u'family2') self.session.add(family2) self.session.commit() family1_id = self.family.id family2_id = family2.id tag_plugin.tag_objects('test', [self.family, family2]) # get object by string tagged_objs = tag_plugin.get_tagged_objects('test') sorted_pairs = sorted([(type(o), o.id) for o in tagged_objs], cmp=lambda x, y: cmp(x[0], y[0])) self.assert_( sorted_pairs == [(Family, family1_id), (Family, family2_id)], sorted_pairs) # get object by tag tag = self.session.query(Tag).filter_by(tag=u'test').one() tagged_objs = tag_plugin.get_tagged_objects(tag) sorted_pairs = sorted([(type(o), o.id) for o in tagged_objs], cmp=lambda x, y: cmp(x[0], y[0])) self.assert_( sorted_pairs == [(Family, family1_id), (Family, family2_id)], sorted_pairs) tag_plugin.tag_objects('test', [self.family, family2]) # # now untag everything # tag_plugin.untag_objects('test', [self.family, family2]) # get object by string tagged_objs = tag_plugin.get_tagged_objects('test') pairs = [(type(o), o.id) for o in tagged_objs] self.assert_(pairs == [], pairs) # get object by tag tag = self.session.query(Tag).filter_by(tag=u'test').one() tagged_objs = tag_plugin.get_tagged_objects(tag)
def setUp(self): super(ReportTests, self).setUp() fctr = gctr = sctr = actr = pctr = 0 for f in xrange(2): fctr += 1 family = Family(id=fctr, epithet=u'fam%s' % fctr) self.session.add(family) for g in range(2): gctr += 1 genus = Genus(id=gctr, family=family, epithet=u'gen%s' % gctr) self.session.add(genus) for s in range(2): sctr += 1 sp = Species(id=sctr, genus=genus, epithet=u'sp%s' % sctr) vn = VernacularName(id=sctr, species=sp, name=u'name%s' % sctr) self.session.add_all([sp, vn]) for a in range(2): actr += 1 acc = Accession(id=actr, species=sp, code=u'%s' % actr) self.session.add(acc) for p in range(2): pctr += 1 loc = Location(id=pctr, code=u'%s' % pctr, name=u'site%s' % pctr) plant = Plant(id=pctr, accession=acc, location=loc, code=u'%s' % pctr, quantity=1) #debug('fctr: %s, gctr: %s, actr: %s, pctr: %s' \ # % (fctr, gctr, actr, pctr)) self.session.add_all([loc, plant]) self.session.commit()
def setUp(self): super(TagTests, self).setUp() self.family = Family(family=u'family') self.session.add(self.family) self.session.commit()