Exemple #1
0
    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'')
Exemple #2
0
    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()
        exporter = JSONExporter(MockView())
        exporter.view.selection = selection
        exporter.selection_based_on == 'sbo_selection'
        exporter.include_private = True
        exporter.filename = self.temp_path
        exporter.run()
        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')
Exemple #3
0
    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)
Exemple #4
0
    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')
Exemple #5
0
    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)
Exemple #6
0
    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)
Exemple #7
0
 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()
Exemple #8
0
 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()
Exemple #9
0
 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()