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_insert_into_lparen_comma_suggests_cols():
suggestions = suggest_type("INSERT INTO abc (id,", "INSERT INTO abc (id,")
assert suggestions == (
Column(table_refs=((None, "abc", None, False),), context="insert"),
)
def test_handle_unrecognized_kw_generously():
sql = "SELECT * FROM sessions WHERE session = 1 AND "
suggestions = suggest_type(sql, sql)
expected = Column(table_refs=((None, "sessions", None, False),), qualifiable=True)
assert expected in set(suggestions)
def test_dot_suggests_cols_of_an_alias_where(sql):
suggestions = suggest_type(sql, sql)
assert set(suggestions) == set(
[
Table(schema="t1"),
View(schema="t1"),
Column(table_refs=((None, "tabl1", "t1", False),)),
Function(schema="t1"),
]
Column(table_refs=(), qualifiable=True),
Function(schema=None),
Keyword("SELECT"),
],
),
("\\ns abc SELECT foo ", "SELECT foo ", (Keyword(),)),
(
"\\ns abc SELECT t1. FROM tabl1 t1",
"SELECT t1.",
[
Table(schema="t1"),
View(schema="t1"),
Column(table_refs=((None, "tabl1", "t1", False),)),
Function(schema="t1"),
],
),
],
def test_suggest_columns_after_multiple_joins():
sql = """select * from t1
inner join t2 ON
t1.id = t2.t1_id
inner join t3 ON
t2.id = t3."""
suggestions = suggest_type(sql, sql)
assert Column(table_refs=((None, "t3", None, False),)) in set(suggestions)
def cols_etc(
table, schema=None, alias=None, is_function=False, parent=None, last_keyword=None
):
"""Returns the expected select-clause suggestions for a single-table
select."""
return set(
[
Column(
table_refs=(TableReference(schema, table, alias, is_function),),
qualifiable=True,
),
Function(schema=parent),
Keyword(last_keyword),
]
def test_column_keyword_suggests_columns(sql):
suggestions = suggest_type(sql, sql)
assert set(suggestions) == set([Column(table_refs=((None, "foo", None, False),))])
def test_insert_into_lparen_partial_text_suggests_cols():
suggestions = suggest_type("INSERT INTO abc (i", "INSERT INTO abc (i")
assert suggestions == (
Column(table_refs=((None, "abc", None, False),), context="insert"),
)
def test_sub_select_dot_col_name_completion():
suggestions = suggest_type(
"SELECT * FROM (SELECT t. FROM tabl t", "SELECT * FROM (SELECT t."
)
assert set(suggestions) == set(
[
Column(table_refs=((None, "tabl", "t", False),)),
Table(schema="t"),
View(schema="t"),
Function(schema="t"),
]
def test_join_alias_dot_suggests_cols2(sql):
suggestion = suggest_type(sql, sql)
assert set(suggestion) == set(
[
Column(table_refs=((None, "def", "d", False),)),
Table(schema="d"),
View(schema="d"),
Function(schema="d"),
]