コード例 #1
0
    def setUp(self):
        self.db_config = TestDatabaseConfiguration(protocol=self.protocol)
        self.db_config_node = self.db_config._database_configuration_node()
        self.db_server = DatabaseServer(self.db_config)

        self.test_db = 'OpusDatabaseTestDatabase'

        self.export_from_cache_opus_path = "opus_core.tools.do_export_cache_to_sql"
        self.export_to_cache_opus_path = "opus_core.tools.do_export_sql_to_cache"
        self.year = 1000

        self.temp_dir = tempfile.mkdtemp(prefix='opus_tmp')
        self.test_data = {
            self.year: {
                'table_a': {
                    'tablea_id': array([1, 2, 3]),
                    'tablea_id_name': array(['1', '2', '3']),
                    'value1': array([1.0, 2.001, 3], dtype='float'),
                    'value2':
                    array([True, False, False], dtype='i'
                          ),  ## sqlit is having problem handling bool type
                },
                'table_b': {
                    'tableb_id': array([1, 2, 3]),
                    'tableb_id_name': array(['one', 'two', 'three']),
                    'value3': array([1.0, 2.001, 3], dtype='float'),
                },
            },
        }
        cache_creator = CreateTestAttributeCache()
        cache_creator.create_attribute_cache_with_data(self.temp_dir,
                                                       self.test_data)
コード例 #2
0
    def test_attributes(self):
        from opus_core.database_management.configurations.test_database_configuration import TestDatabaseConfiguration
        
        c1 = TestDatabaseConfiguration(protocol='prot', host_name='h', user_name='fred', 
            password='******')
        self.assertEqual(c1.protocol, 'prot')
        self.assertEqual(c1.host_name, 'h')
        self.assertEqual(c1.user_name, 'fred')
        self.assertEqual(c1.password, 'secret')

        c3 = TestDatabaseConfiguration(protocol = 'mysql', user_name = 'fred')
        self.assertEqual(c3.protocol, 'mysql')
        self.assertEqual(c3.host_name, 'localhost')
        self.assertEqual(c3.user_name, 'fred')
        self.assertEqual(c3.password, os.environ.get('SQLPASSWORD', ''))
コード例 #3
0
    def test_combine_tables(self):
        CombineTables().combine_tables(
            TestDatabaseConfiguration(protocol='mysql'), self.db_name,
            [i[0] for i in self.from_tables], self.to_table)

        expected_rows = 0
        for table, type in self.from_tables:
            count = self.db.GetResultsFromQuery('select count(*) from %s' %
                                                table)[1:][0][0]
            expected_rows += count

        try:
            count = self.db.GetResultsFromQuery('select count(*) from %s;' %
                                                self.to_table)[1:][0][0]
        except:
            self.fail('Expected output table %s does not exist.' %
                      self.to_table)

        if (expected_rows != count):
            for table_name, type in self.from_tables:
                self._print_table(table_name)
            self._print_table(self.to_table)

        self.assert_(
            expected_rows == count,
            'Incorrect number of rows in output. Expected %s; received %s.' %
            (expected_rows, count))
コード例 #4
0
 def setUp(self):
     self.db_name = 'test_create_table'
     
     self.db_server = DatabaseServer(TestDatabaseConfiguration(protocol = 'mysql'))
     self.db_server.drop_database(self.db_name)
     self.db_server.create_database(self.db_name)
     self.db = self.db_server.get_database(self.db_name)
コード例 #5
0
 def setUp(self):
     self.db_name = 'test_rename_commercial_and_industrial'
     
     self.db_server = DatabaseServer(TestDatabaseConfiguration(protocol = 'mysql'))
     
     self.db_server.drop_database(self.db_name)
     self.db_server.create_database(self.db_name)
     self.db = self.db_server.get_database(self.db_name)
     
     self.tables_to_convert = (
         'employment_commercial_location_choice_model_specification',
         'employment_commercial_location_choice_model_coefficients',
         'employment_industrial_location_choice_model_specification',
         'employment_industrial_location_choice_model_coefficients',
         )
         
     self.other_tables = (
         'i_am_not_to_be_renamed_location_choice_model_specifications',
         'i_am_not_to_be_renamed_location_choice_model_coefficients',
         'employment_industrial_location_choice_model_coefficients_old',
         )
     
     for table in self.tables_to_convert + self.other_tables:
         self.db.DoQuery('CREATE TABLE %s (id INT);' % table)
         
     self.output_tables = (
         'commercial_employment_location_choice_model_specification',
         'commercial_employment_location_choice_model_coefficients',
         'industrial_employment_location_choice_model_specification',
         'industrial_employment_location_choice_model_coefficients',
         )
コード例 #6
0
    def setUp(self):
        self.db_config = TestDatabaseConfiguration(protocol = self.protocol)
        self.db_config_node = self.db_config._database_configuration_node()
        self.db_server = DatabaseServer(self.db_config)

        self.test_db = 'OpusDatabaseTestDatabase'
        
        self.export_from_cache_opus_path = "opus_core.tools.do_export_cache_to_sql"
        self.export_to_cache_opus_path = "opus_core.tools.do_export_sql_to_cache"
        self.year = 1000
        
        self.temp_dir = tempfile.mkdtemp(prefix='opus_tmp')
        self.test_data = {
            self.year:{
                'table_a':{
                    'tablea_id':array([1,2,3]),
                    'tablea_id_name': array(['1','2','3']),
                    'value1': array([1.0, 2.001, 3], dtype='float'),
                    'value2': array([True, False, False], dtype='i'),  ## sqlit is having problem handling bool type
                    },
                'table_b':{
                    'tableb_id':array([1,2,3]),
                    'tableb_id_name': array(['one','two','three']),
                    'value3': array([1.0, 2.001, 3], dtype='float'),
                    },
                },
            }
        cache_creator = CreateTestAttributeCache()
        cache_creator.create_attribute_cache_with_data(self.temp_dir, self.test_data)
コード例 #7
0
        def setUp(self):

            db_configs = []
            for engine in get_testable_engines():
                config = TestDatabaseConfiguration(protocol=engine)
                db_configs.append(config)

            self.database_name = 'test_database'
            self.dbs = []
            for config in db_configs:
                try:
                    server = DatabaseServer(config)
                    if server.has_database(self.database_name):
                        server.drop_database(self.database_name)
                    server.create_database(self.database_name)
                    self.assertTrue(
                        server.has_database(database_name=self.database_name))
                    db = OpusDatabase(database_server_configuration=config,
                                      database_name=self.database_name)
                    storage = sql_storage(storage_location=db)
                    self.dbs.append((db, server, storage))
                    self.storage = storage
                except:
                    import traceback
                    traceback.print_exc()

                    print 'WARNING: could not start server for protocol %s' % config.protocol
コード例 #8
0
    def setUp(self):
        db_configs = []
        for engine in _get_installed_database_engines():
            config = TestDatabaseConfiguration(protocol=engine)
            db_configs.append(config)

        self.test_db = 'OpusDatabaseTestDatabase'
        test_table = 'test_table'

        self.dbs = []
        for config in db_configs:
            try:
                server = DatabaseServer(config)
                if server.has_database(self.test_db):
                    server.drop_database(self.test_db)
                server.create_database(self.test_db)
                self.assertTrue(
                    server.has_database(database_name=self.test_db))
                db = OpusDatabase(database_server_configuration=config,
                                  database_name=self.test_db)
                self.assertFalse(db.table_exists(test_table))
                self.dbs.append((db, server))
            except:
                import traceback
                traceback.print_exc()

                logger.log_warning('Could not start server for protocol %s' %
                                   config.protocol)
コード例 #9
0
    def test_create_table(self):
        CombineTables().combine_tables(
            TestDatabaseConfiguration(protocol='mysql'), self.db_name,
            [i[0] for i in self.from_tables], self.to_table)

        try:
            self.db.DoQuery('select * from %s;' % self.to_table)
        except:
            self.fail('Output table %s not created.' % self.to_table)
コード例 #10
0
    def test_create_table(self):
        CreateJobBuildingTypesTable().create_building_types_table(
            TestDatabaseConfiguration(protocol='mysql'), self.db_name)

        try:
            self.db.DoQuery('select * from job_building_types;')
        except:
            self.fail(
                'Expected output table job_building_types does not exist.')
コード例 #11
0
 def test_rename_tables(self):
     r = RenameBySwappingEmploymentAndCommercialOrIndustrialOrHomeBasedForElcm()
     r.rename_by_swapping_employment_and_commercial_or_industrial_or_home_based_for_elcm(
         TestDatabaseConfiguration(protocol = 'mysql'), self.db_name)
     
     for table in self.output_tables + self.other_tables:
         if not self.db.table_exists(table):
             self.fail('Expected output table %s does not exist.' % table)
                 
     for table in self.tables_to_convert:
         if self.db.table_exists(table):
             self.fail('Input table %s still exists.' % table)
コード例 #12
0
    def test_convert_databases(self):
        ConvertDatabase().convert_databases(
            TestDatabaseConfiguration(protocol='mysql'), self.config)

        for db_name in self.config['databases']:
            db = self.db_server.get_database(db_name)

            tables = self.config['tables'][db_name]
            for table in tables:
                results = db.GetResultsFromQuery('select * from %s;' % table)
                self.assert_(
                    results == self.expected_output_changed,
                    "Convert failed %s (%s) -- incorrect conversion."
                    " Expected %s. Recieved %s." %
                    (db_name, table, self.expected_output_changed, results))
コード例 #13
0
    def setUp(self):
        self.database_name = 'test_travel_model_input_file_writer'

        self.dbconfig = TestDatabaseConfiguration()

        self.db_server = DatabaseServer(self.dbconfig)

        self.db_server.drop_database(self.database_name)
        self.db_server.create_database(self.database_name)
        self.database = self.db_server.get_database(self.database_name)

        self.create_jobs_table(self.database)
        self.create_zones_table(self.database)
        self.create_employment_sector_groups_table(self.database)
        self.create_constant_taz_columns_table(self.database)
        self.create_households_table(self.database)
        self.tempdir_path = tempfile.mkdtemp(prefix='opus_tmp')
コード例 #14
0
    def test_create_table(self):
        creator = TableCreator()
        db = creator._get_db(TestDatabaseConfiguration(protocol = 'mysql'), self.db_name)
        self.assert_(not db.table_exists('test_table'))
        self.assert_(not db.table_exists('test_table_bak'))
        
        db.DoQuery('CREATE TABLE test_table '
                '(id INT, name varchar(50), units varchar(50));')
        self.assert_(db.table_exists('test_table'))
        self.assert_(not db.table_exists('test_table_bak'))

        creator._backup_table(db, 'test_table')
        self.assert_(db.table_exists('test_table'))
        self.assert_(db.table_exists('test_table_bak'))
        
        creator._drop_table(db, 'test_table')
        self.assert_(not db.table_exists('test_table'))
        self.assert_(db.table_exists('test_table_bak'))
コード例 #15
0
    def setUp(self):
        self.db_server = DatabaseServer(
            TestDatabaseConfiguration(protocol='mysql'))
        self.db_name = 'test_combine_tables'
        self.db_server.drop_database(self.db_name)
        self.db_server.create_database(self.db_name)
        self.db = self.db_server.get_database(self.db_name)

        self.from_tables = (
            ('table_a', 'A'),
            ('table_b', 'B'),
            ('table_c', 'C'),
            ('table_d', 'D'),
        )
        table_ids = {
            'table_a': [1],
            'table_b': [2, 3],
            'table_c': [4, 5, 6, 7],
            'table_d': [8, 9, 10, 11, 12, 13, 14, 15],
        }
        self.to_table = 'to_table'

        for table, type in self.from_tables:
            self.db.DoQuery('CREATE TABLE %s (job_id INT, sector_id INT, '
                            'grid_id INT, sic INT, building_type varchar(5), '
                            'home_based tinyint(4), impute_flag tinyint(4));' %
                            table)

            values = ','.join([
                '(%(j)s, %(j)s, %(j)s, %(j)s, "%(type)s", %(j)s, %(j)s)' % {
                    'j': j,
                    'type': type
                } for j in table_ids[table]
            ])
            self.db.DoQuery(
                'INSERT INTO %(table_name)s (job_id, sector_id, '
                'grid_id, sic, building_type, home_based, impute_flag) VALUES '
                '%(values)s;' % {
                    'table_name': table,
                    'values': values,
                })
            number_rows = self.db.GetResultsFromQuery(
                'SELECT count(*) FROM %s' % table)[1][0]
            self.assertEqual(number_rows, len(table_ids[table]))
コード例 #16
0
    def setUp(self):
        self.databases = ['db_chain_son', 'db_chain_dad', 'db_chain_granddad']

        self.config = TestDatabaseConfiguration(
            protocol=get_default_database_engine())
        self.server = DatabaseServer(self.config)
        self._create_databases()
        self.db_chain_granddad = self.server.get_database('db_chain_granddad')
        self.db_chain_dad = self.server.get_database('db_chain_dad')
        self.db_chain_son = self.server.get_database('db_chain_son')

        self._create_tables()
        self.granddad_schema = self.db_chain_granddad.get_table('base_schema')
        self.dad_schema = self.db_chain_dad.get_table('base_schema')
        self.granddad_schema2 = self.db_chain_granddad.get_table(
            'base_schema2')
        self.son_schema2 = self.db_chain_son.get_table('base_schema2')

        self._seed_values()
コード例 #17
0
    def test_values(self):
        CreateJobBuildingTypesTable().create_building_types_table(
            TestDatabaseConfiguration(protocol='mysql'), self.db_name)

        expected_results = [['id', 'name', 'home_based'], [1, "commercial", 0],
                            [3, "industrial", 0], [2, "governmental", 0],
                            [4, "home_based", 1]]

        try:
            results = self.db.GetResultsFromQuery(
                'select * from job_building_types;')
        except:
            self.fail(
                'Expected output table job_building_types does not exist.')

        self.assert_(
            expected_results == results,
            "Table job_building_types has incorrect values! "
            "Expected: %s. Received: %s" % (expected_results, results))
コード例 #18
0
 def setUp(self):
     self.config = TestDatabaseConfiguration(
         database_name='eugene_services_test')
     self.temp_dir = tempfile.mkdtemp(prefix='opus_tmp')
コード例 #19
0
 def setUp(self):
     self.database_name = 'test_services_database'
     self.config = TestDatabaseConfiguration(
         database_name=self.database_name)
     self.db_server = DatabaseServer(self.config)
コード例 #20
0
class AbstractFunctionalTest(object):
    protocol = ''

    def setUp(self):
        self.db_config = TestDatabaseConfiguration(protocol=self.protocol)
        self.db_config_node = self.db_config._database_configuration_node()
        self.db_server = DatabaseServer(self.db_config)

        self.test_db = 'OpusDatabaseTestDatabase'

        self.export_from_cache_opus_path = "opus_core.tools.do_export_cache_to_sql"
        self.export_to_cache_opus_path = "opus_core.tools.do_export_sql_to_cache"
        self.year = 1000

        self.temp_dir = tempfile.mkdtemp(prefix='opus_tmp')
        self.test_data = {
            self.year: {
                'table_a': {
                    'tablea_id': array([1, 2, 3]),
                    'tablea_id_name': array(['1', '2', '3']),
                    'value1': array([1.0, 2.001, 3], dtype='float'),
                    'value2':
                    array([True, False, False], dtype='i'
                          ),  ## sqlit is having problem handling bool type
                },
                'table_b': {
                    'tableb_id': array([1, 2, 3]),
                    'tableb_id_name': array(['one', 'two', 'three']),
                    'value3': array([1.0, 2.001, 3], dtype='float'),
                },
            },
        }
        cache_creator = CreateTestAttributeCache()
        cache_creator.create_attribute_cache_with_data(self.temp_dir,
                                                       self.test_data)

    def tearDown(self):
        if self.db_server.has_database(self.test_db):
            self.db_server.drop_database(self.test_db)
        self.db_server.close()
        if os.path.exists(self.temp_dir):
            rmtree(self.temp_dir)

    def test_export_all_tables(self):
        logger.log_status("Test export all tables for %s with %s" %
                          (self.protocol, self.__class__))
        optional_args = [
            '-c',
            os.path.join(self.temp_dir, str(self.year)), '-d', self.test_db,
            '--database_configuration=%s' % self.db_config_node
        ]
        self._call_script(self.export_from_cache_opus_path, args=optional_args)

        self.assertTrue(
            self.db_server.has_database(database_name=self.test_db))
        db = OpusDatabase(database_server_configuration=self.db_config,
                          database_name=self.test_db)

        table_names = self.test_data[self.year].keys()
        existing_tables = db.get_tables_in_database()
        self.assertEqual(set(existing_tables), set(table_names))

        ## export data from db to cache
        export_year = str(self.year + 100)
        exp_dir = os.path.join(self.temp_dir, export_year)

        optional_args = [
            '-d', self.test_db, '-c', self.temp_dir, '-y', export_year,
            '--database_configuration=%s' % self.db_config_node
        ]
        self._call_script(self.export_to_cache_opus_path, args=optional_args)

        exported_datasets = [os.path.split(f)[1] for f in glob(exp_dir + '/*')]
        self.assertEqual(set(exported_datasets), set(table_names))

        org_dir = os.path.join(self.temp_dir, str(self.year))
        self._two_caches_are_identical(org_dir, exp_dir)

        db.close()
        self.db_server.drop_database(self.test_db)
        rmtree(exp_dir)

    def test_export_one_table(self):
        logger.log_status("Test export single table for %s with %s" %
                          (self.protocol, self.__class__))
        for table_name in self.test_data[self.year].keys():
            self._test_export_one_table(table_name)

    def _test_export_one_table(self, table_name):
        optional_args = [
            '-c',
            os.path.join(self.temp_dir, str(self.year)), '-d', self.test_db,
            '-t', table_name,
            '--database_configuration=%s' % self.db_config_node
        ]
        self._call_script(self.export_from_cache_opus_path, args=optional_args)

        self.assertTrue(
            self.db_server.has_database(database_name=self.test_db))
        db = OpusDatabase(database_server_configuration=self.db_config,
                          database_name=self.test_db)
        existing_tables = db.get_tables_in_database()
        self.assertEqual(set(existing_tables), set([table_name]))

        export_year = str(self.year + 100)
        exp_dir = os.path.join(self.temp_dir, export_year)

        optional_args = [
            '-d', self.test_db, '-c', self.temp_dir, '-y', export_year, '-t',
            table_name,
            '--database_configuration=%s' % self.db_config_node
        ]
        self._call_script(self.export_to_cache_opus_path, args=optional_args)

        exported_datasets = [
            os.path.split(f)[1]
            for f in glob(os.path.join(self.temp_dir, export_year) + '/*')
        ]
        self.assertEqual(set(exported_datasets), set([table_name]))

        org_dir = os.path.join(self.temp_dir, str(self.year))
        self._two_caches_are_identical(org_dir,
                                       exp_dir,
                                       table_names=[table_name])

        db.close()
        self.db_server.drop_database(self.test_db)
        rmtree(exp_dir)

    def _call_script(self, opus_path, args):
        Popen(" %s %s %s" %
              (sys.executable, module_path_from_opus_path(opus_path),
               ' '.join(args)),
              shell=True).communicate()

    def _two_caches_are_identical(self, cache_a, cache_b, table_names=None):
        """ Check to see if two caches contains identical datasets 
        even though their data types can be different
        """
        if table_names is None:
            table_names = os.listdir(cache_a)
        for table_name in table_names:
            field_names_a = glob(os.path.join(cache_a, table_name) + '/*')
            field_names_b = glob(os.path.join(cache_b, table_name) + '/*')
            self.assertEqual(len(field_names_a), len(field_names_b))
            field_names_a.sort()
            field_names_b.sort()
            [
                self.assertTrue(cmp(f_a, f_b))
                for f_a, f_b in zip(field_names_a, field_names_b)
            ]
コード例 #21
0
class AbstractFunctionalTest(object):
    protocol = ''
    def setUp(self):
        self.db_config = TestDatabaseConfiguration(protocol = self.protocol)
        self.db_config_node = self.db_config._database_configuration_node()
        self.db_server = DatabaseServer(self.db_config)

        self.test_db = 'OpusDatabaseTestDatabase'
        
        self.export_from_cache_opus_path = "opus_core.tools.do_export_cache_to_sql"
        self.export_to_cache_opus_path = "opus_core.tools.do_export_sql_to_cache"
        self.year = 1000
        
        self.temp_dir = tempfile.mkdtemp(prefix='opus_tmp')
        self.test_data = {
            self.year:{
                'table_a':{
                    'tablea_id':array([1,2,3]),
                    'tablea_id_name': array(['1','2','3']),
                    'value1': array([1.0, 2.001, 3], dtype='float'),
                    'value2': array([True, False, False], dtype='i'),  ## sqlit is having problem handling bool type
                    },
                'table_b':{
                    'tableb_id':array([1,2,3]),
                    'tableb_id_name': array(['one','two','three']),
                    'value3': array([1.0, 2.001, 3], dtype='float'),
                    },
                },
            }
        cache_creator = CreateTestAttributeCache()
        cache_creator.create_attribute_cache_with_data(self.temp_dir, self.test_data)
                
    def tearDown(self):
        if self.db_server.has_database(self.test_db):
            self.db_server.drop_database(self.test_db)
        self.db_server.close()
        if os.path.exists(self.temp_dir):
            rmtree(self.temp_dir)

    def test_export_all_tables(self):
        logger.log_status("Test export all tables for %s with %s" % (self.protocol, self.__class__))
        optional_args = ['-c', os.path.join(self.temp_dir, str(self.year)), 
                         '-d', self.test_db, 
                         '--database_configuration=%s' % self.db_config_node ]
        self._call_script(self.export_from_cache_opus_path,
                          args = optional_args)

        
        self.assertTrue(self.db_server.has_database(database_name = self.test_db))
        db = OpusDatabase(database_server_configuration = self.db_config, 
                          database_name = self.test_db)
        
        table_names = self.test_data[self.year].keys()
        existing_tables = db.get_tables_in_database()        
        self.assertEqual( set(existing_tables), set(table_names) )

        ## export data from db to cache
        export_year = str(self.year + 100)        
        exp_dir = os.path.join(self.temp_dir, export_year)

        optional_args = ['-d', self.test_db, 
                         '-c', self.temp_dir, 
                         '-y', export_year,
                         '--database_configuration=%s' % self.db_config_node ]
        self._call_script(self.export_to_cache_opus_path,
                          args = optional_args)

        exported_datasets = [os.path.split(f)[1] for f in glob(exp_dir + '/*')]
        self.assertEqual( set(exported_datasets), set(table_names))
        
        org_dir = os.path.join(self.temp_dir, str(self.year))
        self._two_caches_are_identical(org_dir, exp_dir)

        db.close()
        self.db_server.drop_database(self.test_db)
        rmtree(exp_dir)
        
    def test_export_one_table(self):
        logger.log_status("Test export single table for %s with %s" % (self.protocol, self.__class__))
        for table_name in self.test_data[self.year].keys():
            self._test_export_one_table(table_name)
            
    def _test_export_one_table(self, table_name):
        optional_args = ['-c', os.path.join(self.temp_dir, str(self.year)), 
                         '-d', self.test_db,
                         '-t', table_name,
                         '--database_configuration=%s' % self.db_config_node ]
        self._call_script(self.export_from_cache_opus_path,
                          args = optional_args)
        
        self.assertTrue(self.db_server.has_database(database_name = self.test_db))
        db = OpusDatabase(database_server_configuration = self.db_config, 
                          database_name = self.test_db)
        existing_tables = db.get_tables_in_database()
        self.assertEqual( set(existing_tables), set([table_name]) )
        
        export_year = str(self.year + 100)        
        exp_dir = os.path.join(self.temp_dir, export_year)
        
        optional_args = ['-d', self.test_db, 
                         '-c', self.temp_dir, 
                         '-y', export_year,
                         '-t', table_name,
                         '--database_configuration=%s' % self.db_config_node ]
        self._call_script(self.export_to_cache_opus_path,
                          args = optional_args)

        exported_datasets = [os.path.split(f)[1] for f in glob(os.path.join(self.temp_dir, export_year) + '/*')]
        self.assertEqual( set(exported_datasets), set([table_name]))
        
        org_dir = os.path.join(self.temp_dir, str(self.year))
        self._two_caches_are_identical(org_dir, exp_dir, table_names=[table_name])

        db.close()
        self.db_server.drop_database(self.test_db)
        rmtree(exp_dir)

    def _call_script(self, opus_path, args):
            Popen( " %s %s %s" % (sys.executable, module_path_from_opus_path(opus_path), ' '.join(args)),
                   shell = True
                 ).communicate()        

    def _two_caches_are_identical(self, cache_a, cache_b, table_names=None):
        """ Check to see if two caches contains identical datasets 
        even though their data types can be different
        """
        if table_names is None:
            table_names = os.listdir(cache_a)
        for table_name in table_names:
            field_names_a = glob(os.path.join(cache_a, table_name) + '/*')
            field_names_b = glob(os.path.join(cache_b, table_name) + '/*')
            self.assertEqual(len(field_names_a), len(field_names_b))
            field_names_a.sort(); field_names_b.sort()
            [self.assertTrue(cmp(f_a, f_b)) for f_a, f_b in zip(field_names_a, field_names_b)]        
コード例 #22
0
 def get_postgres_server(self):
     server_config = TestDatabaseConfiguration(
         protocol = 'postgres')
     return DatabaseServer(server_config) 
コード例 #23
0
 def get_mssql_server(self):
     server_config = TestDatabaseConfiguration(
         protocol = 'mssql')
     s = DatabaseServer(server_config)     
     return s
コード例 #24
0
    def setUp(self):
        self.test_db_names = [
            'convert_database_test_db1',
            'convert_database_test_db2',
        ]

        self.test_table_names = [
            'table1',
            'table2',
            'table3',
        ]

        table_schema = 'id INT, do_not_change_this_column TEXT, variable_name TEXT'
        table_data = ('(1,"Does not match P A T T E R N.","Matches pattern."),'
                      '(2,"Matches pattern.","Does not match P A T T E R N."),'
                      '(3,NULL,NULL),'
                      '(4,"","")')

        self.expected_output_unchanged = [
            ['id', 'do_not_change_this_column', 'variable_name'],
            [1, "Does not match P A T T E R N.", "Matches pattern."],
            [2, "Matches pattern.", "Does not match P A T T E R N."],
            [3, None, None], [4, "", ""]
        ]

        self.patterns = [(r'(pattern)(\.)', r'\1 well\2'),
                         (r'^Matches pattern well\.$',
                          r'Matches pattern perfectly!')]

        self.expected_output_changed = [
            ['id', 'do_not_change_this_column', 'variable_name'],
            [1, "Does not match P A T T E R N.", "Matches pattern perfectly!"],
            [2, "Matches pattern.", "Does not match P A T T E R N."],
            [3, None, None], [4, "", ""]
        ]

        insert_items_template = ("insert into %(table)s values %(data)s;")

        table_list = {}
        for db_name in self.test_db_names:
            table_list[db_name] = []
            for table in self.test_table_names:
                table_list[db_name] += [table]

        self.config = {
            'databases': self.test_db_names,
            'tables': table_list,
            'backup': True,
            'backup_postfix': '_old',
        }

        self.db_server = DatabaseServer(
            TestDatabaseConfiguration(protocol='mysql'))

        self.dbs = []
        for db_name in self.test_db_names:
            self.db_server.drop_database(db_name)
            self.db_server.create_database(db_name)
            self.dbs += [self.db_server.get_database(db_name)]

        for db in self.dbs:
            for table_name in self.test_table_names:
                db.DoQuery('create table %s (%s)' % (table_name, table_schema))

                db.DoQuery(insert_items_template % {
                    'table': table_name,
                    'data': table_data
                })
コード例 #25
0
    def setUp(self):
        self.test_db_names = [
            'convert_database_test_db1',
            'convert_database_test_db2',
        ]

        self.test_table_names = [
            'table1',
            'table2',
            'table3',
        ]

        table_structure = 'id INT, do_not_change_this_column TEXT, variable_name TEXT'
        table_data = (
            '(1,"No opus dot.","constant"),'
            '(2,"opus.core.miscellaneous","No opus dot."),'
            '(3,"opus.urbansim.gridcell.percent_water",'
            '"gc_cbd = gridcell.disaggregate('
            'opus.psrc.zone.generalized_cost_hbw_am_drive_alone_to_129)"),'
            '(4,"","")')

        self.expected_output_unchanged = [
            ['id', 'do_not_change_this_column', 'variable_name'],
            [1, "No opus dot.", "constant"],
            [2, "opus.core.miscellaneous", "No opus dot."],
            [
                3, "opus.urbansim.gridcell.percent_water",
                "gc_cbd = gridcell.disaggregate("
                "opus.psrc.zone.generalized_cost_hbw_am_drive_alone_to_129)"
            ], [4, "", ""]
        ]

        self.expected_output_changed = [
            ['id', 'do_not_change_this_column', 'variable_name'],
            [1, "No opus dot.", "constant"],
            [2, "opus.core.miscellaneous", "No opus dot."],
            [
                3, "opus.urbansim.gridcell.percent_water",
                "gc_cbd = gridcell.disaggregate("
                "psrc.zone.generalized_cost_hbw_am_drive_alone_to_129)"
            ], [4, "", ""]
        ]

        insert_items_template = ("insert into %(table)s values %(data)s;")

        table_list = {}
        for db_name in self.test_db_names:
            table_list[db_name] = []
            for table in self.test_table_names:
                table_list[db_name] += [table]

        self.config = {
            'databases': self.test_db_names,
            'tables': table_list,
            'backup': True,
            'backup_postfix': '_old',
        }

        self.db_server = DatabaseServer(
            TestDatabaseConfiguration(protocol='mysql'))

        self.dbs = []
        for db_name in self.test_db_names:
            self.db_server.drop_database(db_name)
            self.db_server.create_database(db_name)
            self.dbs += [self.db_server.get_database(db_name)]

        for db in self.dbs:
            for table_name in self.test_table_names:
                db.DoQuery('create table %s (%s)' %
                           (table_name, table_structure))

                db.DoQuery(insert_items_template % {
                    'table': table_name,
                    'data': table_data
                })
コード例 #26
0
 def test_create_table(self):
     CreateBuildingTypesTable().create_building_types_table(
         TestDatabaseConfiguration(protocol = 'mysql'), self.db_name)
     
     self.assert_(self.db.table_exists('building_types'))
コード例 #27
0
 def get_sqlite_server(self):
     server_config = TestDatabaseConfiguration(
         protocol = 'sqlite')
     s = DatabaseServer(server_config)     
     return s