def test_schema_tool_supported_database(): if get_current_db_type() != 'mysql': with pytest.raises(UnsupportedDBError): SchemaTool() return assert SchemaTool()
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) if options['tables']: result = dict(apps={}) for app_label in args: result['apps'] = { 'name': app_label, 'tables': self.schema_tool.get_app_tables(app_label), } self.stdout.write(jsonify(result)) else: result = dict(apps={}) for app_label in args: result['apps'][app_label] = { 'name': app_label, 'tables': {} } for table_name in self.schema_tool.get_app_tables(app_label): result['apps'][app_label]['tables'].update( self.handle_table(table_name, **options) ) self.stdout.write(jsonify(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 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 test_schema_table(capfd): call_command('schema', 'table', 'pootle_store_store') out, err = capfd.readouterr() schema_tool = SchemaTool() assert jsonify(schema_tool.get_table_fields('pootle_store_store')) in out assert jsonify(schema_tool.get_table_indices('pootle_store_store')) in out assert jsonify( schema_tool.get_table_constraints('pootle_store_store')) in out
def test_schema_app(capfd): call_command('schema', 'app', 'pootle_store') out, err = capfd.readouterr() schema_tool = SchemaTool('pootle_store') for table_name in schema_tool.get_tables(): assert jsonify(schema_tool.get_table_fields(table_name)) in out assert jsonify(schema_tool.get_table_indices(table_name)) in out assert jsonify(schema_tool.get_table_constraints(table_name)) in out
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_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 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 handle(self, *args, **options): self.schema_tool = SchemaTool() 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 = {} for table_name in args: result.update( self.handle_table(table_name, **options) ) self.stdout.write(jsonify(result))
def test_schema_tool(): if get_current_db_type() != 'mysql': pytest.skip("unsupported database") schema_tool = SchemaTool() defaults = schema_tool.get_defaults() assert set(defaults.keys()) == TEST_MYSQL_SCHEMA_PARAM_NAMES['defaults'] for app_label in schema_tool.app_configs: for table in schema_tool.get_app_tables(app_label): row = schema_tool.get_table_fields(table).values()[0] assert (set([x.lower() for x in row.keys()]).issubset( TEST_MYSQL_SCHEMA_PARAM_NAMES['tables']['fields'])) row = schema_tool.get_table_indices(table).values()[0] assert (set([x.lower() for x in row.keys()]).issubset( TEST_MYSQL_SCHEMA_PARAM_NAMES['tables']['indices'])) row = schema_tool.get_table_constraints(table).values()[0] assert (set([x.lower() for x in row.keys()]).issubset( TEST_MYSQL_SCHEMA_PARAM_NAMES['tables']['constraints']))
def test_schema_tool(): schema_tool = SchemaTool() if isinstance(schema_tool.schema_dumper, MySQLSchemaDumper): defaults = schema_tool.get_defaults() assert set( defaults.keys()) == TEST_MYSQL_SCHEMA_PARAM_NAMES['defaults'] for app_label in schema_tool.app_configs: for table in schema_tool.get_app_tables(app_label): row = schema_tool.get_table_fields(table)[0] assert (set([ x.lower() for x in row.keys() ]) == TEST_MYSQL_SCHEMA_PARAM_NAMES['tables']['fields']) row = schema_tool.get_table_indices(table)[0] assert (set([ x.lower() for x in row.keys() ]) == TEST_MYSQL_SCHEMA_PARAM_NAMES['tables']['indices']) row = schema_tool.get_table_constraints(table)[0] assert (set([ x.lower() for x in row.keys() ]) == TEST_MYSQL_SCHEMA_PARAM_NAMES['tables']['constraints'])
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 test_schema(capfd): call_command('schema') out, err = capfd.readouterr() schema_tool = SchemaTool() assert jsonify(schema_tool.get_defaults()) in out
def test_schema_tables(capfd): call_command('schema', '--tables') out, err = capfd.readouterr() schema_tool = SchemaTool() assert jsonify(schema_tool.get_tables()) in out
def test_schema_app_tables(capfd): call_command('schema', 'app', 'pootle_store', '--tables') out, err = capfd.readouterr() schema_tool = SchemaTool('pootle_store') assert jsonify(schema_tool.get_tables()) in out
def handle(self, **options): schema_tool = SchemaTool() if options['tables']: self.stdout.write(jsonify(schema_tool.get_tables())) else: self.stdout.write(jsonify(schema_tool.get_defaults()))