def test_schema_tables(capfd): if get_current_db_type() != 'mysql': pytest.skip("unsupported database") call_command('schema', '--tables') out, err = capfd.readouterr() schema_tool = SchemaTool() result = SchemaDump() result.load(json.loads(out)) assert schema_tool.get_tables() == result.tables
def test_schema_app(capfd): if get_current_db_type() != 'mysql': pytest.skip("unsupported database") call_command('schema', 'app', 'pootle_store') out, err = capfd.readouterr() result = SchemaDump() result.load(json.loads(out)) schema_tool = SchemaTool('pootle_store') for table_name in schema_tool.get_tables(): table_result = result.apps['pootle_store'].tables[table_name] _test_table_result(schema_tool, table_result, table_name)
def test_schema_table(capfd): if get_current_db_type() != 'mysql': pytest.skip("unsupported database") call_command('schema', 'table', 'pootle_store_store') out, err = capfd.readouterr() schema_tool = SchemaTool() result = SchemaDump() result.load(json.loads(out)) app_label = schema_tool.get_app_by_table('pootle_store_store') table_result = result.apps[app_label].tables['pootle_store_store'] _test_table_result(schema_tool, table_result, 'pootle_store_store')
def handle(self, **options): try: schema_tool = SchemaTool() except UnsupportedDBError as e: raise CommandError(e) result = SchemaDump() if options['tables']: result.set_table_list(schema_tool.get_tables()) self.stdout.write(str(result)) else: result.load({'defaults': schema_tool.get_defaults()}) for app_label in schema_tool.app_configs: app_dump = SchemaAppDump(app_label) table_names = schema_tool.get_app_tables(app_label) for table_name in table_names: table_dump = SchemaTableDump(table_name) table_dump.load({ 'fields': schema_tool.get_table_fields(table_name), 'indices': schema_tool.get_table_indices(table_name), 'constraints': schema_tool.get_table_constraints(table_name) }) app_dump.add_table(table_dump) if table_names: result.add_app(app_dump) self.stdout.write(str(result))
def handle(self, *args, **options): try: self.schema_tool = SchemaTool(*args) except (LookupError, ImportError) as e: raise CommandError("%s. Are you sure your INSTALLED_APPS " "setting is correct?" % e) except UnsupportedDBError as e: raise CommandError(e) if options['tables']: result = SchemaDump() for app_label in args: result.set_table_list( self.schema_tool.get_app_tables(app_label)) self.stdout.write(str(result)) else: result = SchemaDump() for app_label in args: app_result = SchemaAppDump(app_label) for table_name in self.schema_tool.get_app_tables(app_label): app_result.add_table( self.handle_table(table_name, **options)) result.add_app(app_result) self.stdout.write(str(result))
def handle(self, **options): try: schema_tool = SchemaTool() except UnsupportedDBError as e: raise CommandError(e) result = SchemaDump() if options['tables']: result.set_table_list(schema_tool.get_tables()) self.stdout.write(str(result)) else: result.load({ 'defaults': schema_tool.get_defaults()}) for app_label in schema_tool.app_configs: app_dump = SchemaAppDump(app_label) table_names = schema_tool.get_app_tables(app_label) for table_name in table_names: table_dump = SchemaTableDump(table_name) table_dump.load({ 'fields': schema_tool.get_table_fields(table_name), 'indices': schema_tool.get_table_indices(table_name), 'constraints': schema_tool.get_table_constraints(table_name)}) app_dump.add_table(table_dump) if table_names: result.add_app(app_dump) self.stdout.write(str(result))
def test_schema_dump(test_fs): if get_current_db_type() != 'mysql': pytest.skip("unsupported database") schema_tool = SchemaTool() expected_result = SchemaDump() with test_fs.open(['data', 'schema.json']) as f: expected_result.load(data=json.loads(f.read())) assert expected_result.defaults == schema_tool.get_defaults() for app_label in schema_tool.app_configs: expected_app_result = expected_result.get_app(app_label) for table_name in schema_tool.get_app_tables(app_label): expected_table_result = expected_app_result.get_table(table_name) assert (schema_tool.get_table_fields(table_name) == expected_table_result.fields) assert (schema_tool.get_table_indices(table_name) == expected_table_result.indices) assert (schema_tool.get_table_constraints(table_name) == expected_table_result.constraints)
def handle(self, *args, **options): try: self.schema_tool = SchemaTool() except UnsupportedDBError as e: raise CommandError(e) all_tables = self.schema_tool.get_tables() if not set(args).issubset(set(all_tables)): raise CommandError("Unrecognized tables: %s" % list(set(args) - set(all_tables))) result = SchemaDump() for table_name in args: app_label = self.schema_tool.get_app_by_table(table_name) if not result.app_exists(app_label): app_result = SchemaAppDump(app_label) result.add_app(app_result) else: app_result = result.get_app(app_label) app_result.add_table( self.handle_table(table_name, **options)) self.stdout.write(str(result))
def handle(self, *args, **options): try: self.schema_tool = SchemaTool() except UnsupportedDBError as e: raise CommandError(e) all_tables = self.schema_tool.get_tables() if not set(args).issubset(set(all_tables)): raise CommandError("Unrecognized tables: %s" % list(set(args) - set(all_tables))) result = SchemaDump() for table_name in args: app_label = self.schema_tool.get_app_by_table(table_name) if not result.app_exists(app_label): app_result = SchemaAppDump(app_label) result.add_app(app_result) else: app_result = result.get_app(app_label) app_result.add_table(self.handle_table(table_name, **options)) self.stdout.write(str(result))