diff options
author | Joakim Koljonen <koljonen@outlook.com> | 2016-12-10 05:50:07 +0100 |
---|---|---|
committer | Joakim Koljonen <koljonen@outlook.com> | 2016-12-12 02:45:39 +0100 |
commit | 813afcaf11e1b0ea0d9be0be35d5ef2c3a910c0c (patch) | |
tree | 4e81d301b3d86861d841e3980da5b10a3a2fc4ce /tests/test_smart_completion_multiple_schemata.py | |
parent | 36568270fd7a56ae0c5afe065b1fbdd82e910196 (diff) |
Search table suggestions using initialisms
The idea is that if you have e.g. a table called `FooBar`, where we'd
use the initialism `FB` as an alias (suggesting `FooBar FB`),
inputting e.g. `SELECT * FROM FB` should suggest `FooBar FB` (or
`FooBar` if aliasing is disabled). Ditto for functions, views and joins.
The solution is that we send `FB` as a `synonym` to `find_matches`,
which results in the `FooBar` suggestion rising to the top (above e.g.
`FabulousTable`).
Diffstat (limited to 'tests/test_smart_completion_multiple_schemata.py')
-rw-r--r-- | tests/test_smart_completion_multiple_schemata.py | 95 |
1 files changed, 83 insertions, 12 deletions
diff --git a/tests/test_smart_completion_multiple_schemata.py b/tests/test_smart_completion_multiple_schemata.py index 608f3b84..92e8d0e0 100644 --- a/tests/test_smart_completion_multiple_schemata.py +++ b/tests/test_smart_completion_multiple_schemata.py @@ -20,7 +20,14 @@ metadata = { }, 'Custom': { 'projects': ['projectid', 'name'] - }}, + }, + 'blog': { + 'entries': ['entryid', 'entrytitle', 'entrytext'], + 'tags': ['tagid', 'name'], + 'entrytags': ['entryid', 'tagid'], + 'entacclog': ['entryid', 'username', 'datestamp'], + } + }, 'functions': { 'public': [ ['func1', [], [], [], '', False, False, False], @@ -30,7 +37,13 @@ metadata = { ['set_returning_func', ['x'], ['integer'], ['o'], 'integer', False, False, True]], 'Custom': [ - ['func4', [], [], [], '', False, False, False]] + ['func4', [], [], [], '', False, False, False]], + 'blog': [ + ['extract_entry_symbols', ['_entryid', 'symbol'], + ['integer', 'text'], ['i', 'o'], '', False, False, True], + ['enter_entry', ['_title', '_text', 'entryid'], + ['text', 'text', 'integer'], ['i', 'i', 'o'], + '', False, False, False]], }, 'datatypes': { 'public': ['typ1', 'typ2'], @@ -39,16 +52,25 @@ metadata = { 'foreignkeys': { 'custom': [ ('public', 'users', 'id', 'custom', 'shipments', 'user_id') - ]}, + ], + 'blog': [ + ('blog', 'entries', 'entryid', 'blog', 'entacclog', 'entryid'), + ('blog', 'entries', 'entryid', 'blog', 'entrytags', 'entryid'), + ('blog', 'tags', 'tagid', 'blog', 'entrytags', 'tagid'), + ], + }, } testdata = MetaData(metadata) +cased_schemas = [schema(x) for x in ('public', 'blog', 'CUSTOM', '"Custom"')] @pytest.fixture def completer(): return testdata.completer -casing = ('SELECT', 'Orders', 'User_Emails', 'CUSTOM', 'Func1') +casing = ('SELECT', 'Orders', 'User_Emails', 'CUSTOM', 'Func1', 'Entries', + 'Tags', 'EntryTags', 'EntAccLog', + 'EntryID', 'EntryTitle', 'EntryText') @pytest.fixture def completer_with_casing(): @@ -475,10 +497,7 @@ def test_table_aliases(completer_with_aliases, complete_event, text): 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"'), + assert set(result) == set(cased_schemas + [ table('users u'), table('Orders O' if text == 'SELECT * FROM ' else 'Orders O2'), table('"select" s'), @@ -489,12 +508,64 @@ def test_aliases_with_casing(completer_aliases_casing, complete_event, text): 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"'), + assert set(result) == set(cased_schemas + [ table('users'), table('Orders'), table('"select"'), function('Func1()'), function('func2()')]) + +def test_alias_search_without_aliases2(completer_with_casing, complete_event): + text = 'SELECT * FROM blog.et' + result = completer_with_casing.get_completions( + Document(text=text), complete_event) + assert result[0] == table('EntryTags', -2) + +def test_alias_search_without_aliases1(completer_with_casing, complete_event): + text = 'SELECT * FROM blog.e' + result = completer_with_casing.get_completions( + Document(text=text), complete_event) + assert result[0] == table('Entries', -1) + +def test_alias_search_with_aliases2(completer_aliases_casing, complete_event): + text = 'SELECT * FROM blog.et' + result = completer_aliases_casing.get_completions( + Document(text=text), complete_event) + assert result[0] == table('EntryTags ET', -2) + +def test_alias_search_with_aliases1(completer_aliases_casing, complete_event): + text = 'SELECT * FROM blog.e' + result = completer_aliases_casing.get_completions( + Document(text=text), complete_event) + assert result[0] == table('Entries E', -1) + +def test_join_alias_search_with_aliases1(completer_aliases_casing, + complete_event): + text = 'SELECT * FROM blog.Entries E JOIN blog.e' + result = completer_aliases_casing.get_completions( + Document(text=text), complete_event) + 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)] + +def test_join_alias_search_with_aliases2(completer_aliases_casing, + complete_event): + text = 'SELECT * FROM blog.Entries E JOIN blog.et' + result = completer_aliases_casing.get_completions( + Document(text=text), complete_event) + assert result[0] == join('EntryTags ET ON ET.EntryID = E.EntryID', -2) + +def test_join_alias_search_without_aliases2(completer_with_casing, + complete_event): + text = 'SELECT * FROM blog.Entries JOIN blog.et' + result = completer_with_casing.get_completions( + Document(text=text), complete_event) + assert result[0] == join( + 'EntryTags ON EntryTags.EntryID = Entries.EntryID', -2) |