예제 #1
0
def test_table_casing(completer, text):
    result = result_set(completer, text)
    assert result == set(cased_schemas + [
        table('users'),
        table('Orders'),
        table('"select"'),
        function('Func1()'),
        function('func2()')])
def test_aliases_with_casing(completer, text):
    result = get_result(completer, text)
    assert completions_to_set(result) == completions_to_set(cased_schemas + [
        table('users u'),
        table('Orders O' if text == 'SELECT * FROM ' else 'Orders O2'),
        table('"select" s'),
        function('Func1() F'),
        function('func2() f')])
예제 #3
0
def test_aliases_with_casing(completer, text):
    result = result_set(completer, text)
    assert result == set(cased_schemas + [
        table('users u'),
        table('Orders O' if text == 'SELECT * FROM ' else 'Orders O2'),
        table('"select" s'),
        function('Func1() F'),
        function('func2() f')])
예제 #4
0
def test_table_aliases(completer, text):
    result = result_set(completer, text)
    assert result == set(testdata.schemas() + [
        table('users u'),
        table('orders o' if text == 'SELECT * FROM ' else 'orders o2'),
        table('"select" s'),
        function('func1() f'),
        function('func2() f')])
def test_table_casing(completer, text):
    result = get_result(completer, text)
    assert completions_to_set(result) == completions_to_set(cased_schemas + [
        table('users'),
        table('Orders'),
        table('"select"'),
        function('Func1()'),
        function('func2()')])
def test_table_aliases(completer, text):
    result = get_result(completer, text)
    assert completions_to_set(result) == completions_to_set(testdata.schemas() + [
        table('users u'),
        table('orders o' if text == 'SELECT * FROM ' else 'orders o2'),
        table('"select" s'),
        function('func1() f'),
        function('func2() f')])
예제 #7
0
def test_table_casing(completer, text):
    result = get_result(completer, text)
    assert completions_to_set(result) == completions_to_set(cased_schemas + [
        table('users'),
        table('Orders'),
        table('"select"'),
        function('Func1()'),
        function('func2()')
    ])
def test_table_aliases(completer_with_aliases, complete_event, text):
    result = completer_with_aliases.get_completions(
        Document(text=text), complete_event)
    assert set(result) == set(testdata.schemas() + [
        table('users u'),
        table('orders o' if text == 'SELECT * FROM ' else 'orders o2'),
        table('"select" s'),
        function('func1() f'),
        function('func2() f')])
def test_table_aliases(completer_with_aliases, complete_event, text):
    result = completer_with_aliases.get_completions(
        Document(text=text), complete_event)
    assert set(result) == set(testdata.schemas() + [
        table('users u'),
        table('orders o' if text == 'SELECT * FROM ' else 'orders o2'),
        table('"select" s'),
        function('func1() f'),
        function('func2() f')])
def test_table_casing(completer_with_casing, complete_event, text):
    result = completer_with_casing.get_completions(
        Document(text=text), complete_event)
    assert set(result) == set(cased_schemas + [
        table('users'),
        table('Orders'),
        table('"select"'),
        function('Func1()'),
        function('func2()')])
def test_aliases_with_casing(completer_aliases_casing, complete_event, text):
    result = completer_aliases_casing.get_completions(
        Document(text=text), complete_event)
    assert set(result) == set(cased_schemas + [
        table('users u'),
        table('Orders O' if text == 'SELECT * FROM ' else 'Orders O2'),
        table('"select" s'),
        function('Func1() F'),
        function('func2() f')])
예제 #12
0
def test_aliases_with_casing(completer, text):
    result = get_result(completer, text)
    assert completions_to_set(result) == completions_to_set(cased_schemas + [
        table("users u"),
        table("Orders O" if text == "SELECT * FROM " else "Orders O2"),
        table('"select" s'),
        function("Func1() F"),
        function("func2() f"),
    ])
예제 #13
0
def test_table_casing(completer, text):
    result = get_result(completer, text)
    assert completions_to_set(result) == completions_to_set(cased_schemas + [
        table("users"),
        table("Orders"),
        table('"select"'),
        function("Func1()"),
        function("func2()"),
    ])
예제 #14
0
def test_table_aliases(completer, text):
    result = get_result(completer, text)
    assert completions_to_set(result) == completions_to_set(
        testdata.schemas() + [
            table("users u"),
            table("orders o" if text == "SELECT * FROM " else "orders o2"),
            table('"select" s'),
            function("func1() f"),
            function("func2() f"),
        ])
def test_aliases_with_casing(completer_aliases_casing, complete_event, text):
    result = completer_aliases_casing.get_completions(
        Document(text=text), complete_event)
    assert set(result) == set([
        schema('public'),
        schema('CUSTOM'),
        schema('"Custom"'),
        table('users u'),
        table('Orders O' if text == 'SELECT * FROM ' else 'Orders O2'),
        table('"select" s'),
        function('Func1() F'),
        function('func2() f')])
def test_table_casing(completer_with_casing, complete_event, text):
    result = completer_with_casing.get_completions(
        Document(text=text), complete_event)
    assert set(result) == set([
        schema('public'),
        schema('CUSTOM'),
        schema('"Custom"'),
        table('users'),
        table('Orders'),
        table('"select"'),
        function('Func1()'),
        function('func2()')])
def test_learn_table_names(completer):
    history = 'SELECT * FROM users; SELECT * FROM orders; SELECT * FROM users'
    completer.extend_query_history(history)

    text = 'SELECT * FROM '
    completions = get_result(completer, text)

    # `users` should be higher priority than `orders` (used more often)
    users = table('users')
    orders = table('orders')

    assert completions.index(users) < completions.index(orders)
def test_table_casing(completer_with_casing, complete_event, text):
    result = completer_with_casing.get_completions(Document(text=text),
                                                   complete_event)
    assert set(result) == set([
        schema('public'),
        schema('CUSTOM'),
        schema('"Custom"'),
        table('users'),
        table('Orders'),
        table('"select"'),
        function('Func1()'),
        function('func2()')
    ])
def test_learn_table_names(completer, complete_event):
    history = 'SELECT * FROM users; SELECT * FROM orders; SELECT * FROM users'
    completer.extend_query_history(history)

    sql = 'SELECT * FROM '
    completions = completer.get_completions(
        Document(text=sql, cursor_position=len(sql)), complete_event)

    # `users` should be higher priority than `orders` (used more often)
    users = table('users')
    orders = table('orders')

    assert completions.index(users) < completions.index(orders)
def test_learn_table_names(completer, complete_event):
    history = 'SELECT * FROM users; SELECT * FROM orders; SELECT * FROM users'
    completer.extend_query_history(history)

    sql = 'SELECT * FROM '
    completions = completer.get_completions(
        Document(text=sql, cursor_position=len(sql)), complete_event)

    # `users` should be higher priority than `orders` (used more often)
    users = table('users')
    orders = table('orders')

    assert completions.index(users) < completions.index(orders)
def test_duplicate_table_aliases(completer, text):
    result = result_set(completer, text)
    assert result == set(testdata.schemas() + [
        table('orders o2'),
        table('users u'),
        table('"Users" U'),
        table('"select" s'),
        view('user_emails ue'),
        function('_custom_fun() cf'),
        function('custom_fun() cf'),
        function('custom_func1() cf'),
        function('custom_func2() cf'),
        function('set_returning_func() srf')])
def test_duplicate_table_aliases(aliased_completer, complete_event, text):
    result = aliased_completer.get_completions(
        Document(text=text), complete_event)
    assert set(result) == set(testdata.schemas() + [
        table('orders o2'),
        table('users u'),
        table('"Users" U'),
        table('"select" s'),
        view('user_emails ue'),
        function('_custom_fun() cf'),
        function('custom_fun() cf'),
        function('custom_func1() cf'),
        function('custom_func2() cf'),
        function('set_returning_func() srf')])
def test_duplicate_aliases_with_casing(completer, text):
    result = result_set(completer, text)
    assert result == set([
        schema('PUBLIC'),
        table('Orders O2'),
        table('Users U'),
        table('"Users" U'),
        table('"select" s'),
        view('User_Emails UE'),
        function('_custom_fun() cf'),
        function('Custom_Fun() CF'),
        function('Custom_Func1() CF'),
        function('custom_func2() cf'),
        function('set_returning_func() srf')])
def test_all_schema_objects_with_casing(completer):
    text = "SELECT * FROM "
    result = get_result(completer, text)
    assert completions_to_set(result) >= completions_to_set(
        [table(x) for x in ("Orders", '"select"', "CUSTOM.shipments")]
        + [function(x + "()") for x in ("func2",)]
    )
def test_all_schema_objects_with_aliases(completer):
    text = "SELECT * FROM "
    result = get_result(completer, text)
    assert completions_to_set(result) >= completions_to_set(
        [table(x) for x in ("orders o", '"select" s', "custom.shipments s")]
        + [function(x) for x in ("func2() f",)]
    )
예제 #26
0
def test_all_schema_objects_with_casing(completer):
    text = 'SELECT * FROM '
    result = result_set(completer, text)
    assert result >= set(
        [table(x) for x in ('Orders', '"select"', 'CUSTOM.shipments')]
        + [function(x+'()') for x in ('func2', 'CUSTOM.func3')]
    )
예제 #27
0
def test_all_schema_objects(completer):
    text = ('SELECT * FROM ')
    result = result_set(completer, text)
    assert result >= set(
        [table(x) for x in ('orders', '"select"', 'custom.shipments')]
        + [function(x+'()') for x in ('func2', 'custom.func3')]
    )
def test_join_alias_search_without_aliases1(completer):
    text = 'SELECT * FROM blog.Entries JOIN blog.e'
    result = get_result(completer, text)
    assert result[:2] == [
        table('Entries', -1),
        join('EntAccLog ON EntAccLog.EntryID = Entries.EntryID', -1)
    ]
def test_duplicate_aliases_with_casing(cased_aliased_completer,
                                        complete_event, text):
    result = cased_aliased_completer.get_completions(
        Document(text=text), complete_event)
    assert set(result) == set([
        schema('PUBLIC'),
        table('Orders O2'),
        table('Users U'),
        table('"Users" U'),
        table('"select" s'),
        view('User_Emails UE'),
        function('_custom_fun() cf'),
        function('Custom_Fun() CF'),
        function('Custom_Func1() CF'),
        function('custom_func2() cf'),
        function('set_returning_func() srf')])
def test_all_schema_objects_with_casing(completer):
    text = 'SELECT * FROM '
    result = get_result(completer, text)
    assert completions_to_set(result) >= completions_to_set(
        [table(x) for x in ('Orders', '"select"', 'CUSTOM.shipments')]
        + [function(x + '()') for x in ('func2',)]
    )
def test_all_schema_objects_with_aliases(completer):
    text = ('SELECT * FROM ')
    result = get_result(completer, text)
    assert completions_to_set(result) >= completions_to_set(
        [table(x) for x in ('orders o', '"select" s', 'custom.shipments s')]
        + [function(x) for x in ('func2() f',)]
    )
예제 #32
0
def test_join_alias_search_with_aliases1(completer):
    text = "SELECT * FROM blog.Entries E JOIN blog.e"
    result = get_result(completer, text)
    assert result[:2] == [
        table("Entries E2", -1),
        join("EntAccLog EAL ON EAL.EntryID = E.EntryID", -1),
    ]
def test_join_alias_search_without_aliases1(completer_with_casing,
                                            complete_event):
    text = 'SELECT * FROM blog.Entries JOIN blog.e'
    result = completer_with_casing.get_completions(
        Document(text=text), complete_event)
    assert result[:2] == [table('Entries', -1), join(
        'EntAccLog ON EntAccLog.EntryID = Entries.EntryID', -1)]
예제 #34
0
def test_all_schema_objects_with_aliases(completer):
    text = ('SELECT * FROM ')
    result = result_set(completer, text)
    assert result >= set(
        [table(x) for x in ('orders o', '"select" s', 'custom.shipments s')]
        + [function(x) for x in ('func2() f', 'custom.func3() f')]
    )
def test_duplicate_table_aliases(completer, text):
    result = get_result(completer, text)
    assert completions_to_set(result) == completions_to_set(testdata.schemas() + [
        table('orders o2'),
        table('users u'),
        table('"Users" U'),
        table('"select" s'),
        view('user_emails ue'),
        view('functions f'),
        function('_custom_fun() cf'),
        function('custom_fun() cf'),
        function('custom_func1() cf'),
        function('custom_func2() cf'),
        function(
            'set_returning_func(x := , y := ) srf',
            display='set_returning_func(x, y) srf'
        ),
    ])
def test_allow_leading_double_quote_in_last_word(completer, complete_event):
    text = 'SELECT * from "sele'
    position = len(text)
    result = completer.get_completions(
        Document(text=text, cursor_position=position), complete_event)

    expected = table('"select"', -5)

    assert expected in set(result)
def test_allow_leading_double_quote_in_last_word(completer, complete_event):
    text = 'SELECT * from "sele'
    position = len(text)
    result = completer.get_completions(
        Document(text=text, cursor_position=position), complete_event)

    expected = table('"select"', -5)

    assert expected in set(result)
def test_duplicate_aliases_with_casing(completer, text):
    result = get_result(completer, text)
    assert completions_to_set(result) == completions_to_set([
        schema('PUBLIC'),
        table('Orders O2'),
        table('Users U'),
        table('"Users" U'),
        table('"select" s'),
        view('User_Emails UE'),
        view('Functions F'),
        function('_custom_fun() cf'),
        function('Custom_Fun() CF'),
        function('Custom_Func1() CF'),
        function('custom_func2() cf'),
        function(
            'set_returning_func(x := , y := ) srf',
            display='set_returning_func(x, y) srf'
        ),
    ])
예제 #39
0
def test_duplicate_table_aliases(completer, text):
    result = get_result(completer, text)
    assert completions_to_set(result) == completions_to_set(
        testdata.schemas() + [
            table("orders o2"),
            table("users u"),
            table('"Users" U'),
            table('"select" s'),
            view("user_emails ue"),
            view("functions f"),
            function("_custom_fun() cf"),
            function("custom_fun() cf"),
            function("custom_func1() cf"),
            function("custom_func2() cf"),
            function(
                "set_returning_func(x := , y := ) srf",
                display="set_returning_func(x, y) srf",
            ),
        ])
예제 #40
0
def test_duplicate_aliases_with_casing(completer, text):
    result = get_result(completer, text)
    assert completions_to_set(result) == completions_to_set([
        schema("PUBLIC"),
        table("Orders O2"),
        table("Users U"),
        table('"Users" U'),
        table('"select" s'),
        view("User_Emails UE"),
        view("Functions F"),
        function("_custom_fun() cf"),
        function("Custom_Fun() CF"),
        function("Custom_Func1() CF"),
        function("custom_func2() cf"),
        function(
            "set_returning_func(x := , y := ) srf",
            display="set_returning_func(x, y) srf",
        ),
    ])
def test_alias_search_with_aliases2(completer):
    text = 'SELECT * FROM blog.et'
    result = get_result(completer, text)
    assert result[0] == table('EntryTags ET', -2)
def test_alias_search_with_aliases1(completer):
    text = 'SELECT * FROM blog.e'
    result = get_result(completer, text)
    assert result[0] == table('Entries E', -1)
def test_join_alias_search_without_aliases1(completer):
    text = 'SELECT * FROM blog.Entries JOIN blog.e'
    result = get_result(completer, text)
    assert result[:2] == [table('Entries', -1), join(
        'EntAccLog ON EntAccLog.EntryID = Entries.EntryID', -1)]
def test_schema_object_order(completer):
    result = get_result(completer, 'SELECT * FROM u')
    assert result[:3] == [
        table(t, pos=-1) for t in ('users', 'custom."Users"', 'custom.users')
    ]
def test_allow_leading_double_quote_in_last_word(completer):
    result = get_result(completer, 'SELECT * from "sele')

    expected = table('"select"', -5)

    assert expected in result
cased_users_col_names = ['ID', 'PARENTID', 'Email', 'First_Name', 'last_name']
cased_users2_col_names = ['UserID', 'UserName']
cased_func_names = [
    'Custom_Fun', '_custom_fun', 'Custom_Func1', 'custom_func2', 'set_returning_func'
]
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')