def test_all_to_intermediary(): tables, relationships = all_to_intermediary(Base) check_intermediary_representation_simple_table(tables, relationships) db_uri = create_db() tables, relationships = all_to_intermediary(db_uri) check_intermediary_representation_simple_table(tables, relationships) with pytest.raises(ValueError): tables, relationships = all_to_intermediary('plop')
def test_database_to_intermediary_with_schema(): db_uri = create_db() tables, relationships = database_to_intermediary(db_uri, schema='test') assert len(tables) == 3 assert len(relationships) == 2 assert all(isinstance(t, Table) for t in tables) assert all(isinstance(r, Relation) for r in relationships) # Not in because different schema. assert relation not in relationships assert exclude_relation not in relationships
def test_table_names_in_relationships(): db_uri = create_db() tables, relationships = database_to_intermediary(db_uri) table_names = [t.name for t in tables] # Assert column names are table names assert all(r.right_col in table_names for r in relationships) assert all(r.left_col in table_names for r in relationships) # Assert column names match table names for r in relationships: r_name = table_names[table_names.index(r.right_col)] l_name = table_names[table_names.index(r.left_col)] # Table name in relationship should *NOT* have a schema assert (r_name.find('.') == -1) assert (l_name.find('.') == -1)
def test_table_names_in_relationships_with_schema(): db_uri = create_db() schema_name = 'test' matcher = re.compile(r"{}\.[\S+]".format(schema_name), re.I) tables, relationships = database_to_intermediary(db_uri, schema=schema_name) table_names = [t.name for t in tables] # Assert column names match table names, including schema assert all(r.right_col in table_names for r in relationships) assert all(r.left_col in table_names for r in relationships) # Assert column names match table names, including schema for r in relationships: r_name = table_names[table_names.index(r.right_col)] l_name = table_names[table_names.index(r.left_col)] # Table name in relationship *SHOULD* have a schema assert (re.match(matcher, r_name) is not None) assert (re.match(matcher, l_name) is not None)
def test_all_to_intermediary_db(): db_uri = create_db() tables, relationships = all_to_intermediary(db_uri) check_intermediary_representation_simple_table(tables, relationships)
def test_all_to_intermediary_db_sqlite(): db_uri = create_db(db_uri="sqlite:///test.db", use_sqlite=True) tables, relationships = all_to_intermediary(db_uri) check_intermediary_representation_simple_table(tables, relationships)