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, **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_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_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 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_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']) )