def test_suggested_cased_always_qualified_column_names(completer): text = 'SELECT from users' position = len('SELECT ') cols = [column('users.' + c) for c in cased_users_col_names] result = result_set(completer, text, position) assert result == set(cased_funcs + cols + testdata.builtin_functions() + testdata.keywords())
def test_columns_before_keywords(completer): text = 'SELECT * FROM orders WHERE s' completions = get_result(completer, text) col = column('status', -1) kw = keyword('SELECT', -1) assert completions.index(col) < completions.index(kw)
def test_column_alias_search_qualified(completer): result = get_result(completer, 'SELECT E.ei FROM blog.Entries E', len('SELECT E.ei')) cols = ('EntryID', 'EntryTitle') assert result[:3] == [column(c, -2) for c in cols]
def test_column_alias_search(completer): result = get_result(completer, 'SELECT et FROM blog.Entries E', len('SELECT et')) cols = ('EntryText', 'EntryTitle', 'EntryID') assert result[:3] == [column(c, -2) for c in cols]
def test_suggested_column_names_from_cte(completer, text): result = result_set(completer, text, text.find(' ') + 1) assert result == set([column('foo')] + testdata.functions_and_keywords())
def test_join_using_suggests_columns_after_first_column(completer, text): result = result_set(completer, text) assert result == set([column('id'), column('email')])
def test_join_using_suggests_from_last_table(completer, text): position = text.index('()') + 1 result = result_set(completer, text, position) assert result == set([column('id'), column('email')])
def test_suggest_columns_after_three_way_join(completer): text = '''SELECT * FROM users u1 INNER JOIN users u2 ON u1.id = u2.id INNER JOIN users u3 ON u2.id = u3.''' result = result_set(completer, text) assert (column('id') in result)
def test_no_column_qualification(text, completer): cols = [column(c) for c in cased_users_col_names] result = result_set(completer, text) assert result == set(cols)
def test_suggested_auto_qualified_column_names_two_tables(text, completer): position = text.index(' ') + 1 cols = [column('U.' + c.lower()) for c in cased_users_col_names] cols += [column('"Users".' + c.lower()) for c in cased_users2_col_names] result = result_set(completer, text, position) assert result == set(cols + testdata.functions_and_keywords())
] cased_tbls = ['Users', 'Orders'] cased_views = ['User_Emails', 'Functions'] casing = (['SELECT', 'PUBLIC'] + cased_func_names + cased_tbls + cased_views + cased_users_col_names + cased_users2_col_names) # Lists for use in assertions cased_funcs = [ function(f) for f in ('Custom_Fun()', '_custom_fun()', 'Custom_Func1()', 'custom_func2()') ] + [ function('set_returning_func(x := , y := )', display='set_returning_func(x, y)') ] cased_tbls = [table(t) for t in (cased_tbls + ['"Users"', '"select"'])] cased_rels = [view(t) for t in cased_views] + cased_funcs + cased_tbls cased_users_cols = [column(c) for c in cased_users_col_names] aliased_rels = [ table(t) for t in ('users u', '"Users" U', 'orders o', '"select" s') ] + [view('user_emails ue'), view('functions f')] + [ function(f) for f in ('_custom_fun() cf', 'custom_fun() cf', 'custom_func1() cf', 'custom_func2() cf') ] + [ function('set_returning_func(x := , y := ) srf', display='set_returning_func(x, y) srf') ] cased_aliased_rels = [ table(t) for t in ('Users U', '"Users" U', 'Orders O', '"select" s') ] + [view('User_Emails UE'), view('Functions F')] + [ function(f) for f in ('_custom_fun() cf', 'Custom_Fun() CF', 'Custom_Func1() CF', 'custom_func2() cf') ] + [