示例#1
0
    def test_import_species_to_new_genus_and_family(self):
        "species referring to non existing genus (family is specified)"

        ## precondition: the species is not there
        sp = self.session.query(Species).filter(
            Species.sp == u'lawrenceae').join(Genus).filter(
            Genus.genus == u'Aerides').all()
        self.assertEquals(sp, [])

        json_string = '[{"rank": "Species", "epithet": "lawrenceae", '\
            '"ht-rank": "Genus", "ht-epithet": "Aerides", '\
            '"familia": "Orchidaceae", "author" : "Rchb. f."}]'
        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()
        ## postcondition: the species is there
        sp = self.session.query(Species).filter(
            Species.sp == u'lawrenceae').join(Genus).filter(
            Genus.genus == u'Aerides').all()
        self.assertEquals(len(sp), 1)
        sp = sp[0]
        genus = self.session.query(Genus).filter(
            Genus.genus == u'Aerides').first()
        family = self.session.query(Family).filter(
            Family.family == u'Orchidaceae').first()
        self.assertEquals(sp.genus, genus)
        self.assertEquals(genus.family, family)
示例#2
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)
示例#3
0
 def test_import_new_inserts_lowercase(self):
     "importing new taxon adds it to database, rank name can be\
     all lower case."
     json_string = '[{"rank": "genus", "epithet": "Neogyna", "ht-rank"'\
         ': "familia", "ht-epithet": "Orchidaceae", "author": "Rchb. f."}]'
     with open(self.temp_path, "w") as f:
         f.write(json_string)
     self.assertEquals(len(self.session.query(Genus).filter(
         Genus.genus == u"Neogyna").all()), 0)
     importer = JSONImporter(MockImportView())
     importer.filename = self.temp_path
     importer.on_btnok_clicked(None)
     self.assertEquals(len(self.session.query(Genus).filter(
         Genus.genus == u"Neogyna").all()), 1)
示例#4
0
    def test_import_species_to_new_genus_fails(self):
        "importing new species referring to non existing genus logs a warning."
        json_string = '[{"rank": "Species", "epithet": "lawrenceae", '\
            '"ht-rank": "Genus", "ht-epithet": "Aerides", "author": '\
            '"Rchb. f."}]'
        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)

        ## should check the logs
        ## check the species is still not there
        sp = self.session.query(Species).filter(
            Species.sp == u'lawrenceae').join(Genus).filter(
            Genus.genus == u'Aerides').all()
        self.assertEquals(sp, [])
示例#5
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'')
示例#6
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)
示例#7
0
    def test_import_ignores_id_updating(self):
        "importing taxon disregards id value if present (updating taxon)."
        previously = Species.retrieve_or_create(self.session,
                                                {'ht-epithet': u"Calopogon",
                                                 'epithet': u"tuberosus"}).id
        json_string = '[{"rank": "Species", "epithet": "tuberosus", '\
            '"ht-rank": "Genus", "ht-epithet": "Calopogon", "hybrid": false, '\
            '"id": 8}]'
        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()
        afterwards = Species.retrieve_or_create(self.session,
                                                {'ht-epithet': u"Calopogon",
                                                 'epithet': u"tuberosus"}).id
        self.assertEquals(previously, afterwards)
示例#8
0
 def test_import_existing_updates(self):
     "importing existing taxon updates it"
     json_string = '[{"rank": "Species", "epithet": "tuberosus", "ht-rank"'\
         ': "Genus", "ht-epithet": "Calopogon", "hybrid": false, "author"'\
         ': "Britton et al."}]'
     with open(self.temp_path, "w") as f:
         f.write(json_string)
     previously = Species.retrieve_or_create(
         self.session, {'ht-epithet': u"Calopogon",
                        'epithet': u"tuberosus"})
     self.assertEquals(previously.sp_author, None)
     importer = JSONImporter(MockImportView())
     importer.filename = self.temp_path
     importer.on_btnok_clicked(None)
     self.session.commit()
     afterwards = Species.retrieve_or_create(
         self.session, {'ht-epithet': u"Calopogon",
                        'epithet': u"tuberosus"})
     self.assertEquals(afterwards.sp_author, u"Britton et al.")
示例#9
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)
示例#10
0
 def test_on_btnbrowse_clicked(self):
     view = MockView()
     exporter = JSONImporter(view)
     view.reply_file_chooser_dialog = ['/tmp/test.json']
     exporter.on_btnbrowse_clicked('button')
     exporter.on_text_entry_changed('input_filename')
     self.assertEquals(exporter.filename, '/tmp/test.json')
     self.assertEquals(JSONImporter.last_folder, '/tmp')