@pytest.mark.parametrize('relations_config,expected_filter', [([{'relation_regex': 'ix.*', 'schemas': ['public', 's1', 's2']}, {'relation_regex': 'ibx.*', 'schemas': ['public']}, {'relation_regex': 'icx.*', 'schemas': ['public']}], "( relname ~ 'ix.*' AND schemaname = ANY(array['public','s1','s2']::text[]) ) OR ( relname ~ 'ibx.*' AND schemaname = ANY(array['public']::text[]) ) OR ( relname ~ 'icx.*' AND schemaname = ANY(array['public']::text[]) )"), ([{'relation_regex': '.+_archive'}], "( relname ~ '.+_archive' )"), ([{'relation_name': 'my_table', 'schemas': ['public', 'app'], 'relkind': ['r']}, {'relation_name': 'my_table2', 'relkind': ['p', 'r']}, {'relation_regex': 'table.*'}], "( relname = 'my_table' AND schemaname = ANY(array['public','app']::text[]) ) OR ( relname = 'my_table2' ) OR ( relname ~ 'table.*' )"), (['table1', 'table2'], "( relname = 'table1' ) OR ( relname = 'table2' )")])
def test_relations_cases(relations_config, expected_filter):
    query = '{relations}'
    relations = RelationsManager(relations_config)
    query_filter = relations.filter_relation_query(query, SCHEMA_NAME)
    assert (query_filter == expected_filter)
@pytest.mark.parametrize('relations_config,expected_filter', [([{'relation_regex': 'ix.*', 'schemas': ['public', 's1', 's2']}, {'relation_regex': 'ibx.*', 'schemas': ['public']}, {'relation_regex': 'icx.*', 'schemas': ['public']}], "( relname ~ 'ix.*' AND schemaname = ANY(array['public','s1','s2']::text[]) ) OR ( relname ~ 'ibx.*' AND schemaname = ANY(array['public']::text[]) ) OR ( relname ~ 'icx.*' AND schemaname = ANY(array['public']::text[]) )"), ([{'relation_regex': '.+_archive'}], "( relname ~ '.+_archive' )"), ([{'relation_name': 'my_table', 'schemas': ['public', 'app'], 'relkind': ['r']}, {'relation_name': 'my_table2', 'relkind': ['p', 'r']}, {'relation_regex': 'table.*'}], "( relname = 'my_table' AND schemaname = ANY(array['public','app']::text[]) ) OR ( relname = 'my_table2' ) OR ( relname ~ 'table.*' )"), (['table1', 'table2'], "( relname = 'table1' ) OR ( relname = 'table2' )")])
def test_relations_cases(relations_config, expected_filter):
    query = '{relations}'
    relations = RelationsManager(relations_config)
    query_filter = relations.filter_relation_query(query, SCHEMA_NAME)
    assert (query_filter == expected_filter)