コード例 #1
0
    def itest_editor(self):
        # import default geography data
        import bauble.paths as paths
        default_path = os.path.join(paths.lib_dir(), "plugins", "plants",
                                "default")
        filenames = [os.path.join(default_path, f) for f in 'geography.txt',
                     'habit.txt']
        from bauble.plugins.imex.csv_ import CSVImporter
        importer = CSVImporter()
        importer.start(filenames, force=True)

        f = Family(family=u'family')
        g2 = Genus(genus=u'genus2', family=f)
        g = Genus(genus=u'genus', family=f)
        g2.synonyms.append(g)
        self.session.add(f)
        self.session.commit()
        sp = Species(genus=g, sp=u'sp')
        e = SpeciesEditor(model=sp)
        e.start()
        del e
        assert utils.gc_objects_by_type('SpeciesEditor') == [], \
            'SpeciesEditor not deleted'
        assert utils.gc_objects_by_type('SpeciesEditorPresenter') == [], \
            'SpeciesEditorPresenter not deleted'
        assert utils.gc_objects_by_type('SpeciesEditorView') == [], \
            'SpeciesEditorView not deleted'
コード例 #2
0
 def install(cls, import_defaults=True):
     import bauble.paths as paths
     if not import_defaults:
         return
     path = os.path.join(paths.lib_dir(), "plugins", "plants",
                         "default")
     filenames = os.path.join(path, 'family.txt')
     from bauble.plugins.imex.csv_ import CSVImporter
     csv = CSVImporter()
     try:
         csv.start([filenames], metadata=db.metadata, force=True)
     except Exception, e:
         logger.error(e)
         raise
コード例 #3
0
 def install(cls, import_defaults=True):
     import bauble.paths as paths
     if not import_defaults:
         return
     path = os.path.join(paths.lib_dir(), "plugins", "plants",
                         "default")
     filenames = os.path.join(path, 'family.txt')
     from bauble.plugins.imex.csv_ import CSVImporter
     csv = CSVImporter()
     try:
         csv.start([filenames], metadata=db.metadata,
                   force=True)
     except Exception, e:
         error(e)
         raise
コード例 #4
0
    def install(cls, import_defaults=True):
        """
        Do any setup and configuration required by this plugin like
        creating tables, etc...
        """
        if not import_defaults:
            return
        path = os.path.join(paths.lib_dir(), "plugins", "plants", "default")
        filenames = [os.path.join(path, f) for f in 'family.txt',
                     'genus.txt', 'genus_synonym.txt', 'geography.txt',
                     'habit.txt']

        from bauble.plugins.imex.csv_ import CSVImporter
        csv = CSVImporter()
        #import_error = False
        #import_exc = None
        csv.start(filenames, metadata=db.metadata, force=True)
コード例 #5
0
ファイル: __init__.py プロジェクト: RoDuth/bauble.classic
    def install(cls, import_defaults=True):
        """
        Do any setup and configuration required by this plugin like
        creating tables, etc...
        """
        if not import_defaults:
            return
        path = os.path.join(paths.lib_dir(), "plugins", "plants", "default")
        filenames = [
            os.path.join(path, f) for f in 'family.txt', 'family_synonym.txt',
            'genus.txt', 'genus_synonym.txt', 'geography.txt', 'habit.txt'
        ]

        from bauble.plugins.imex.csv_ import CSVImporter
        csv = CSVImporter()
        #import_error = False
        #import_exc = None
        csv.start(filenames, metadata=db.metadata, force=True)
コード例 #6
0
ファイル: test.py プロジェクト: outsider1984/bauble.classic
    def test_get_species(self):
        # import default geography data
        import bauble.paths as paths

        filename = os.path.join(paths.lib_dir(), "plugins", "plants", "default", "geography.txt")
        from bauble.plugins.imex.csv_ import CSVImporter

        importer = CSVImporter()
        importer.start([filename], force=True)

        mexico_id = 53
        mexico_central_id = 267
        oaxaca_id = 665
        northern_america_id = 7
        western_canada_id = 45

        # create a some species
        sp1 = Species(genus=self.genus, sp=u"sp1")
        dist = SpeciesDistribution(geography_id=mexico_central_id)
        sp1.distribution.append(dist)

        sp2 = Species(genus=self.genus, sp=u"sp2")
        dist = SpeciesDistribution(geography_id=oaxaca_id)
        sp2.distribution.append(dist)

        sp3 = Species(genus=self.genus, sp=u"sp3")
        dist = SpeciesDistribution(geography_id=western_canada_id)
        sp3.distribution.append(dist)

        self.session.commit()

        oaxaca = self.session.query(Geography).get(oaxaca_id)
        species = get_species_in_geography(oaxaca)
        self.assert_([s.id for s in species] == [sp2.id])

        mexico = self.session.query(Geography).get(mexico_id)
        species = get_species_in_geography(mexico)
        self.assert_([s.id for s in species] == [sp1.id, sp2.id])

        north_america = self.session.query(Geography).get(northern_america_id)
        species = get_species_in_geography(north_america)
        self.assert_([s.id for s in species] == [sp1.id, sp2.id, sp3.id])
コード例 #7
0
ファイル: test.py プロジェクト: odalissalazar/bauble.classic
    def test_import(self):
        # TODO: create a test to check that we aren't using an insert
        # statement for import that assumes a column value from the previous
        # insert values, could probably create an insert statement from a
        # row in the test data and then create an insert statement from some
        # other dummy data that has different columns from the test data and
        # see if any of the columns from the second insert statement has values
        # from the first statement

        # TODO: this test doesn't really test yet that any of the data was
        # correctly imported or exported, only that export and importing
        # run successfuly

        # 1. write the test data to a temporary file or files
        # 2. import the data and make sure the objects match field for field

        # the exporters and importers show logging information, turn it off
        logging.getLogger('bauble.info').setLevel(logging.ERROR)
        import tempfile
        tempdir = tempfile.mkdtemp()

        # export all the testdata
        exporter = CSVExporter()
        exporter.start(tempdir)

        # import all the files in the temp directory
        filenames = os.listdir(tempdir)
        importer = CSVImporter()
        # import twice to check for regression Launchpad #???
        importer.start([os.path.join(tempdir, name) for name in filenames],
                       force=True)
        importer.start([os.path.join(tempdir, name) for name in filenames],
                       force=True)
コード例 #8
0
ファイル: test.py プロジェクト: odalissalazar/bauble.classic
    def test_sequences(self):
        """
        Test that the sequences are set correctly after an import,
        bauble.util.test already has a method to test
        utils.reset_sequence but this test makes sure that it works
        correctly after an import

        This test requires the PlantPlugin
        """
        # turn off logger
        logging.getLogger('bauble.info').setLevel(logging.ERROR)
        # import the family data
        filename = os.path.join('bauble', 'plugins', 'plants', 'default',
                                'family.txt')
        importer = CSVImporter()
        importer.start([filename], force=True)
        # the highest id number in the family file is assumed to be
        # num(lines)-1 since the id numbers are sequential and
        # subtract for the file header
        highest_id = len(open(filename).readlines())-1
        currval = None
        conn = db.engine.contextual_connect()
        if db.engine.name == 'postgres':
            stmt = "SELECT currval('family_id_seq');"
            currval = conn.execute(stmt).fetchone()[0]
            self.assertEquals(currval, 0)
        elif db.engine.name == 'sqlite':
            # max(id) isn't really safe in production use but is ok for a test
            stmt = "SELECT max(id) from family;"
            nextval = conn.execute(stmt).fetchone()[0] + 1
        else:
            raise "no test for engine type: %s" % db.engine.name

        #debug(list(conn.execute("SELECT * FROM family").fetchall()))
        maxid = conn.execute("SELECT max(id) FROM family").fetchone()[0]
        assert nextval > highest_id, \
            "bad sequence: highest_id(%s) > nexval(%s) -- %s" % \
            (highest_id, nextval, maxid)
コード例 #9
0
ファイル: test.py プロジェクト: outsider1984/bauble.classic
    def test_editor(self):
        raise SkipTest("Not Implemented")
        # import default geography data
        import bauble.paths as paths

        default_path = os.path.join(paths.lib_dir(), "plugins", "plants", "default")
        filenames = [os.path.join(default_path, f) for f in "geography.txt", "habit.txt"]
        from bauble.plugins.imex.csv_ import CSVImporter

        importer = CSVImporter()
        importer.start(filenames, force=True)

        f = Family(family=u"family")
        g2 = Genus(genus=u"genus2", family=f)
        g = Genus(genus=u"genus", family=f)
        g2.synonyms.append(g)
        self.session.add(f)
        self.session.commit()
        sp = Species(genus=g, sp=u"sp")
        edit_species(model=sp)
        assert utils.gc_objects_by_type("SpeciesEditorMenuItem") == [], "SpeciesEditor not deleted"
        assert utils.gc_objects_by_type("SpeciesEditorPresenter") == [], "SpeciesEditorPresenter not deleted"
        assert utils.gc_objects_by_type("SpeciesEditorView") == [], "SpeciesEditorView not deleted"