diff options
author | koljonen <koljonen@outlook.com> | 2016-06-11 15:40:51 +0200 |
---|---|---|
committer | koljonen <koljonen@outlook.com> | 2016-06-14 22:34:10 +0200 |
commit | 6cb8c38628791e18dc5bf1a2a25c13497058c3eb (patch) | |
tree | 4197256424e0b3c2c933bebe70984eb7a3881f4d /tests/test_smart_completion_multiple_schemata.py | |
parent | 351a58554b4d30e1db42a13e3cd9d533b97100b5 (diff) |
Join conditions: alias tables already included in query
If we have the input `SELECT * FROM Foo JOIN `, we now suggest `Foo Foo2 ON Foo2.ParentID = Foo.ID` (given the appropriate casing file and FK).
There were also some problems with quoted tables and with the casing of table aliases, which are now fixed.
I also made a few cosmetic changes to get_join_matches (pgcompleter.py) just to make it a bit easier to work with.
Diffstat (limited to 'tests/test_smart_completion_multiple_schemata.py')
-rw-r--r-- | tests/test_smart_completion_multiple_schemata.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/tests/test_smart_completion_multiple_schemata.py b/tests/test_smart_completion_multiple_schemata.py index 381657de..9f74a7d4 100644 --- a/tests/test_smart_completion_multiple_schemata.py +++ b/tests/test_smart_completion_multiple_schemata.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals import pytest +import itertools from prompt_toolkit.completion import Completion from prompt_toolkit.document import Document from pgcli.packages.function_metadata import FunctionMetadata, ForeignKey @@ -158,19 +159,21 @@ def test_suggested_join_conditions(completer, complete_event, text): Completion(text='shipments.id = users.id', start_position=0, display_meta='name join'), Completion(text='shipments.user_id = users.id', start_position=0, display_meta='fk join')]) -@pytest.mark.parametrize('text', [ - 'SELECT * FROM public.users RIGHT OUTER JOIN ', +@pytest.mark.parametrize(('query', 'tbl'), itertools.product(( + 'SELECT * FROM public.{0} RIGHT OUTER JOIN ', '''SELECT * - FROM users + FROM {0} JOIN ''' -]) -def test_suggested_joins(completer, complete_event, text): +), ('users', '"users"', 'Users'))) +def test_suggested_joins(completer, complete_event, query, tbl): + text = query.format(tbl) position = len(text) result = set(completer.get_completions( Document(text=text, cursor_position=position), complete_event)) + join = 'custom.shipments ON shipments.user_id = {0}.id'.format(tbl) assert set(result) == set([ - Completion(text='custom.shipments ON shipments.user_id = users.id', start_position=0, display_meta='join'), + Completion(text=join, start_position=0, display_meta='join'), Completion(text='public', start_position=0, display_meta='schema'), Completion(text='custom', start_position=0, display_meta='schema'), Completion(text='"Custom"', start_position=0, display_meta='schema'), |