summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/metadata.py4
-rw-r--r--tests/test_smart_completion_multiple_schemata.py35
-rw-r--r--tests/test_smart_completion_public_schema_only.py32
3 files changed, 19 insertions, 52 deletions
diff --git a/tests/metadata.py b/tests/metadata.py
index 7e9115e9..e6176251 100644
--- a/tests/metadata.py
+++ b/tests/metadata.py
@@ -40,6 +40,10 @@ class MetaData(object):
return [datatype(escape(x), pos)
for x in self.metadata.get('datatypes', {}).get(schema, [])]
+ def tables(self, schema='public', pos=0):
+ return [table(escape(x), pos)
+ for x in self.metadata.get('tables', {}).get(schema, [])]
+
def schemas(self, pos=0):
schemas = set(sch for schs in self.metadata.values() for sch in schs)
return [schema(escape(s), pos=pos) for s in schemas]
diff --git a/tests/test_smart_completion_multiple_schemata.py b/tests/test_smart_completion_multiple_schemata.py
index f7000bfa..ff176305 100644
--- a/tests/test_smart_completion_multiple_schemata.py
+++ b/tests/test_smart_completion_multiple_schemata.py
@@ -2,7 +2,6 @@ from __future__ import unicode_literals
import pytest
import itertools
from metadata import (MetaData, alias, name_join, fk_join, join,
- table,
function,
column,
wildcard_expansion)
@@ -67,9 +66,7 @@ def test_schema_or_visible_table_completion(completer, complete_event):
assert set(result) == set(testdata.schemas() + [
function('func1'),
function('func2'),
- table('users'),
- table('"select"'),
- table('orders')])
+ ] + testdata.tables())
@pytest.mark.parametrize('table', [
@@ -144,11 +141,8 @@ def test_suggested_joins(completer, complete_event, query, tbl):
result = set(completer.get_completions(
Document(text=text, cursor_position=position),
complete_event))
- assert set(result) == set(testdata.schemas() + [
+ assert set(result) == set(testdata.schemas() + testdata.tables() + [
join('custom.shipments ON shipments.user_id = {0}.id'.format(tbl)),
- table('orders'),
- table('users'),
- table('"select"'),
function('func1'),
function('func2')])
@@ -209,12 +203,8 @@ def test_suggested_table_names_with_schema_dot(completer, complete_event,
position = len(text)
result = completer.get_completions(
Document(text=text, cursor_position=position), complete_event)
- assert set(result) == set([
+ assert set(result) == set(testdata.tables('custom', start_pos) + [
function('func3', start_pos),
- table('users', start_pos),
- table('"Users"', start_pos),
- table('products', start_pos),
- table('shipments', start_pos),
function('set_returning_func', start_pos),
])
@@ -234,9 +224,9 @@ def test_suggested_table_names_with_schema_dot2(completer, complete_event,
result = completer.get_completions(
Document(text=text, cursor_position=position), complete_event)
assert set(result) == set([
- function('func4', start_pos),
- table('projects', start_pos)
- ])
+ function('func4', start_pos)]
+ + testdata.tables('Custom', start_pos)
+ )
def test_suggested_column_names_with_qualified_alias(completer, complete_event):
"""
@@ -328,12 +318,9 @@ def test_table_names_after_from(completer, complete_event):
result = set(completer.get_completions(
Document(text=text, cursor_position=position),
complete_event))
- assert set(result) == set(testdata.schemas() + [
+ assert set(result) == set(testdata.schemas() + testdata.tables() + [
function('func1'),
function('func2'),
- table('users'),
- table('orders'),
- table('"select"'),
])
def test_schema_qualified_function_name(completer, complete_event):
@@ -356,12 +343,8 @@ def test_schema_qualified_type_name(text, completer, complete_event):
pos = len(text)
result = completer.get_completions(
Document(text=text, cursor_position=pos), complete_event)
- assert set(result) == set(testdata.datatypes('custom') + [
- table('users'),
- table('"Users"'),
- table('products'),
- table('shipments'),
- ])
+ assert set(result) == set(testdata.datatypes('custom')
+ + testdata.tables('custom'))
def test_suggest_columns_from_aliased_set_returning_function(completer, complete_event):
diff --git a/tests/test_smart_completion_public_schema_only.py b/tests/test_smart_completion_public_schema_only.py
index 57f138dd..c8bba0d8 100644
--- a/tests/test_smart_completion_public_schema_only.py
+++ b/tests/test_smart_completion_public_schema_only.py
@@ -67,11 +67,7 @@ def test_schema_or_visible_table_completion(completer, complete_event):
position = len(text)
result = completer.get_completions(
Document(text=text, cursor_position=position), complete_event)
- assert set(result) == set(testdata.schemas() + [
- table('users'),
- table('"Users"'),
- table('"select"'),
- table('orders'),
+ assert set(result) == set(testdata.schemas() + testdata.tables() + [
view('user_emails'),
function('custom_func1'),
function('custom_func2'),
@@ -377,14 +373,10 @@ def test_suggested_joins(completer, complete_event, text):
result = set(completer.get_completions(
Document(text=text, cursor_position=position),
complete_event))
- assert set(result) == set(testdata.schemas() + [
+ assert set(result) == set(testdata.schemas() + testdata.tables() + [
join('"Users" ON "Users".userid = users.id'),
join('users users2 ON users2.id = users.parentid'),
join('users users2 ON users2.parentid = users.id'),
- table('"Users"'),
- table('"select"'),
- table('orders'),
- table('users'),
view('user_emails'),
function('custom_func2'),
function('set_returning_func'),
@@ -402,12 +394,8 @@ def test_suggested_joins_quoted_schema_qualified_table(completer, complete_event
result = set(completer.get_completions(
Document(text=text, cursor_position=position),
complete_event))
- assert set(result) == set(testdata.schemas() + [
+ assert set(result) == set(testdata.schemas() + testdata.tables() + [
join('public.users ON users.id = "Users".userid'),
- table('"Users"'),
- table('"select"'),
- table('orders'),
- table('users'),
view('user_emails'),
function('custom_func2'),
function('set_returning_func'),
@@ -520,11 +508,7 @@ def test_table_names_after_from(completer, complete_event, text):
result = completer.get_completions(
Document(text=text, cursor_position=position),
complete_event)
- assert set(result) == set(testdata.schemas() + [
- table('users'),
- table('"Users"'),
- table('orders'),
- table('"select"'),
+ assert set(result) == set(testdata.schemas() + testdata.tables() + [
view('user_emails'),
function('custom_func1'),
function('custom_func2'),
@@ -581,12 +565,8 @@ def test_suggest_datatype(text, completer, complete_event):
pos = len(text)
result = completer.get_completions(
Document(text=text, cursor_position=pos), complete_event)
- assert set(result) == set(testdata.schemas() + testdata.datatypes() + [
- table('users'),
- table('"Users"'),
- table('orders'),
- table('"select"')] +
- list(testdata.builtin_datatypes()))
+ assert set(result) == set(testdata.schemas() + testdata.datatypes() +
+ testdata.tables() + list(testdata.builtin_datatypes()))
def test_suggest_columns_from_escaped_table_alias(completer, complete_event):