Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_suggest_qualified_aliasable_tables_and_views(expression):
suggestions = suggest_type(expression, expression)
assert set(suggestions) == set([Table(schema="sch"), View(schema="sch")])
def test_function_arguments_with_alias_given():
suggestions = suggest_type("SELECT avg(x. FROM tbl x, tbl2 y", "SELECT avg(x.")
assert set(suggestions) == set(
[
Column(
table_refs=(TableReference(None, "tbl", "x", False),),
local_tables=(),
qualifiable=False,
),
Table(schema="x"),
View(schema="x"),
Function(schema="x"),
]
Table(schema="t1"),
View(schema="t1"),
Column(table_refs=((None, "tabl1", "t1", False),)),
Function(schema="t1"),
],
),
],
)
def test_named_query_completion(text, before, expected):
suggestions = suggest_type(text, before)
assert set(expected) == set(suggestions)
def test_dot_suggests_cols_of_an_alias(sql):
suggestions = suggest_type(sql, "SELECT t1.")
assert set(suggestions) == set(
[
Table(schema="t1"),
View(schema="t1"),
Column(table_refs=((None, "tabl1", "t1", False),)),
Function(schema="t1"),
]
def test_suggest_qualified_tables_and_views(expression):
suggestions = suggest_type(expression, expression)
assert set(suggestions) == set([Table(schema="sch"), View(schema="sch")])
def test_join_alias_dot_suggests_cols1(sql):
suggestions = suggest_type(sql, sql)
tables = ((None, "abc", "a", False), (None, "def", "d", False))
assert set(suggestions) == set(
[
Column(table_refs=((None, "abc", "a", False),)),
Table(schema="a"),
View(schema="a"),
Function(schema="a"),
JoinCondition(table_refs=tables, parent=(None, "abc", "a", False)),
]
def test_drop_schema_qualified_table_suggests_only_tables():
text = "DROP TABLE schema_name.table_name"
suggestions = suggest_type(text, text)
assert suggestions == (Table(schema="schema_name"),)