summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDarik Gamble <darik.gamble@gmail.com>2015-03-03 08:31:30 -0500
committerDarik Gamble <darik.gamble@gmail.com>2015-04-05 16:38:04 -0400
commit05dac16040c3c4eb32e7e81b683b16395c9b491a (patch)
tree7aa76b622e7e3c636866ccc6311f3d9d7c73d9e0 /tests
parentd2c67c1671dcdef540a674b493e1873490cf689c (diff)
suggest view names
Diffstat (limited to 'tests')
-rw-r--r--tests/test_pgspecial.py18
-rw-r--r--tests/test_smart_completion_multiple_schemata.py4
-rw-r--r--tests/test_smart_completion_public_schema_only.py28
-rw-r--r--tests/test_sqlcompletion.py30
4 files changed, 61 insertions, 19 deletions
diff --git a/tests/test_pgspecial.py b/tests/test_pgspecial.py
index 66d9a5ad..7b76d5e0 100644
--- a/tests/test_pgspecial.py
+++ b/tests/test_pgspecial.py
@@ -18,21 +18,27 @@ def test_dn_suggests_schemata():
suggestions = suggest_type('\\dn xxx', '\\dn xxx')
assert suggestions == [{'type': 'schema'}]
-def test_d_suggests_tables_and_schemas():
+def test_d_suggests_tables_views_and_schemas():
suggestions = suggest_type('\d ', '\d ')
assert sorted_dicts(suggestions) == sorted_dicts([
- {'type': 'schema'}, {'type': 'table', 'schema': []}])
+ {'type': 'schema'},
+ {'type': 'table', 'schema': []},
+ {'type': 'view', 'schema': []}])
suggestions = suggest_type('\d xxx', '\d xxx')
assert sorted_dicts(suggestions) == sorted_dicts([
- {'type': 'schema'}, {'type': 'table', 'schema': []}])
+ {'type': 'schema'},
+ {'type': 'table', 'schema': []},
+ {'type': 'view', 'schema': []}])
-def test_d_dot_suggests_schema_qualified_tables():
+def test_d_dot_suggests_schema_qualified_tables_or_views():
suggestions = suggest_type('\d myschema.', '\d myschema.')
- assert suggestions == [{'type': 'table', 'schema': 'myschema'}]
+ assert suggestions == [{'type': 'table', 'schema': 'myschema'},
+ {'type': 'view', 'schema': 'myschema'}]
suggestions = suggest_type('\d myschema.xxx', '\d myschema.xxx')
- assert suggestions == [{'type': 'table', 'schema': 'myschema'}]
+ assert suggestions == [{'type': 'table', 'schema': 'myschema'},
+ {'type': 'view', 'schema': 'myschema'}]
def test_df_suggests_schema_or_function():
suggestions = suggest_type('\\df xxx', '\\df xxx')
diff --git a/tests/test_smart_completion_multiple_schemata.py b/tests/test_smart_completion_multiple_schemata.py
index 6190d774..773d89ca 100644
--- a/tests/test_smart_completion_multiple_schemata.py
+++ b/tests/test_smart_completion_multiple_schemata.py
@@ -39,8 +39,8 @@ def completer():
for func in funcs]
comp.extend_schemata(schemata)
- comp.extend_tables(tables)
- comp.extend_columns(columns)
+ comp.extend_relations(tables, kind='tables')
+ comp.extend_columns(columns, kind='tables')
comp.extend_functions(functions)
comp.set_search_path(['public'])
diff --git a/tests/test_smart_completion_public_schema_only.py b/tests/test_smart_completion_public_schema_only.py
index 3f5d4fcc..13fa5c12 100644
--- a/tests/test_smart_completion_public_schema_only.py
+++ b/tests/test_smart_completion_public_schema_only.py
@@ -7,6 +7,8 @@ metadata = {
'users': ['id', 'email', 'first_name', 'last_name'],
'orders': ['id', 'ordered_date', 'status'],
'select': ['id', 'insert', 'ABC']},
+ 'views': {
+ 'user_emails': ['id', 'email']},
'functions': ['custom_func1', 'custom_func2']
}
@@ -17,18 +19,30 @@ def completer():
comp = pgcompleter.PGCompleter(smart_completion=True)
schemata = ['public']
- tables, columns = [], []
+ comp.extend_schemata(schemata)
+ # tables
+ tables, columns = [], []
for table, cols in metadata['tables'].items():
tables.append(('public', table))
columns.extend([('public', table, col) for col in cols])
- functions = [('public', func) for func in metadata['functions']]
+ comp.extend_relations(tables, kind='tables')
+ comp.extend_columns(columns, kind='tables')
- comp.extend_schemata(schemata)
- comp.extend_tables(tables)
- comp.extend_columns(columns)
+ # views
+ views, columns = [], []
+ for view, cols in metadata['views'].items():
+ views.append(('public', view))
+ columns.extend([('public', view, col) for col in cols])
+
+ comp.extend_relations(views, kind='views')
+ comp.extend_columns(columns, kind='views')
+
+ # functions
+ functions = [('public', func) for func in metadata['functions']]
comp.extend_functions(functions)
+
comp.set_search_path(['public'])
return comp
@@ -64,7 +78,8 @@ def test_schema_or_visible_table_completion(completer, complete_event):
assert set(result) == set([Completion(text='public', start_position=0),
Completion(text='users', start_position=0),
Completion(text='"select"', start_position=0),
- Completion(text='orders', start_position=0)])
+ Completion(text='orders', start_position=0),
+ Completion(text='user_emails', start_position=0)])
def test_builtin_function_name_completion(completer, complete_event):
@@ -277,6 +292,7 @@ def test_table_names_after_from(completer, complete_event):
Completion(text='users', start_position=0),
Completion(text='orders', start_position=0),
Completion(text='"select"', start_position=0),
+ Completion(text='user_emails', start_position=0),
])
def test_auto_escaped_col_names(completer, complete_event):
diff --git a/tests/test_sqlcompletion.py b/tests/test_sqlcompletion.py
index 063bf28c..5bd12daf 100644
--- a/tests/test_sqlcompletion.py
+++ b/tests/test_sqlcompletion.py
@@ -39,6 +39,7 @@ def test_from_suggests_tables_and_schemas():
suggestions = suggest_type('SELECT * FROM ', 'SELECT * FROM ')
assert sorted_dicts(suggestions) == sorted_dicts([
{'type': 'table', 'schema': []},
+ {'type': 'view', 'schema': []},
{'type': 'schema'}])
def test_distinct_suggests_cols():
@@ -56,12 +57,14 @@ def test_table_comma_suggests_tables_and_schemas():
'SELECT a, b FROM tbl1, ')
assert sorted_dicts(suggestions) == sorted_dicts([
{'type': 'table', 'schema': []},
+ {'type': 'view', 'schema': []},
{'type': 'schema'}])
def test_into_suggests_tables_and_schemas():
suggestion = suggest_type('INSERT INTO ', 'INSERT INTO ')
assert sorted_dicts(suggestion) == sorted_dicts([
{'type': 'table', 'schema': []},
+ {'type': 'view', 'schema': []},
{'type': 'schema'}])
def test_insert_into_lparen_suggests_cols():
@@ -88,6 +91,7 @@ def test_dot_suggests_cols_of_a_table_or_schema_qualified_table():
assert sorted_dicts(suggestions) == sorted_dicts([
{'type': 'column', 'tables': [(None, 'tabl', None)]},
{'type': 'table', 'schema': 'tabl'},
+ {'type': 'view', 'schema': 'tabl'},
{'type': 'function', 'schema': 'tabl'}])
def test_dot_suggests_cols_of_an_alias():
@@ -95,6 +99,7 @@ def test_dot_suggests_cols_of_an_alias():
'SELECT t1.')
assert sorted_dicts(suggestions) == sorted_dicts([
{'type': 'table', 'schema': 't1'},
+ {'type': 'view', 'schema': 't1'},
{'type': 'column', 'tables': [(None, 'tabl1', 't1')]},
{'type': 'function', 'schema': 't1'}])
@@ -104,6 +109,7 @@ def test_dot_col_comma_suggests_cols_or_schema_qualified_table():
assert sorted_dicts(suggestions) == sorted_dicts([
{'type': 'column', 'tables': [(None, 'tabl2', 't2')]},
{'type': 'table', 'schema': 't2'},
+ {'type': 'view', 'schema': 't2'},
{'type': 'function', 'schema': 't2'}])
def test_sub_select_suggests_keyword():
@@ -118,7 +124,9 @@ def test_sub_select_table_name_completion():
suggestion = suggest_type('SELECT * FROM (SELECT * FROM ',
'SELECT * FROM (SELECT * FROM ')
assert sorted_dicts(suggestion) == sorted_dicts([
- {'type': 'table', 'schema': []}, {'type': 'schema'}])
+ {'type': 'table', 'schema': []},
+ {'type': 'view', 'schema': []},
+ {'type': 'schema'}])
def test_sub_select_col_name_completion():
suggestions = suggest_type('SELECT * FROM (SELECT FROM abc',
@@ -141,6 +149,7 @@ def test_sub_select_dot_col_name_completion():
assert sorted_dicts(suggestions) == sorted_dicts([
{'type': 'column', 'tables': [(None, 'tabl', 't')]},
{'type': 'table', 'schema': 't'},
+ {'type': 'view', 'schema': 't'},
{'type': 'function', 'schema': 't'}])
def test_join_suggests_tables_and_schemas():
@@ -148,6 +157,7 @@ def test_join_suggests_tables_and_schemas():
'SELECT * FROM abc a JOIN ')
assert sorted_dicts(suggestion) == sorted_dicts([
{'type': 'table', 'schema': []},
+ {'type': 'view', 'schema': []},
{'type': 'schema'}])
def test_join_alias_dot_suggests_cols1():
@@ -156,6 +166,7 @@ def test_join_alias_dot_suggests_cols1():
assert sorted_dicts(suggestions) == sorted_dicts([
{'type': 'column', 'tables': [(None, 'abc', 'a')]},
{'type': 'table', 'schema': 'a'},
+ {'type': 'view', 'schema': 'a'},
{'type': 'function', 'schema': 'a'}])
def test_join_alias_dot_suggests_cols2():
@@ -164,6 +175,7 @@ def test_join_alias_dot_suggests_cols2():
assert sorted_dicts(suggestion) == sorted_dicts([
{'type': 'column', 'tables': [(None, 'def', 'd')]},
{'type': 'table', 'schema': 'd'},
+ {'type': 'view', 'schema': 'd'},
{'type': 'function', 'schema': 'd'}])
def test_on_suggests_aliases():
@@ -194,7 +206,9 @@ def test_2_statements_2nd_current():
suggestions = suggest_type('select * from a; select * from ',
'select * from a; select * from ')
assert sorted_dicts(suggestions) == sorted_dicts([
- {'type': 'table', 'schema': []}, {'type': 'schema'}])
+ {'type': 'table', 'schema': []},
+ {'type': 'view', 'schema': []},
+ {'type': 'schema'}])
suggestions = suggest_type('select * from a; select from b',
'select * from a; select ')
@@ -206,13 +220,17 @@ def test_2_statements_2nd_current():
suggestions = suggest_type('select * from; select * from ',
'select * from; select * from ')
assert sorted_dicts(suggestions) == sorted_dicts([
- {'type': 'table', 'schema': []}, {'type': 'schema'}])
+ {'type': 'table', 'schema': []},
+ {'type': 'view', 'schema': []},
+ {'type': 'schema'}])
def test_2_statements_1st_current():
suggestions = suggest_type('select * from ; select * from b',
'select * from ')
assert sorted_dicts(suggestions) == sorted_dicts([
- {'type': 'table', 'schema': []}, {'type': 'schema'}])
+ {'type': 'table', 'schema': []},
+ {'type': 'view', 'schema': []},
+ {'type': 'schema'}])
suggestions = suggest_type('select from a; select * from b',
'select ')
@@ -224,7 +242,9 @@ def test_3_statements_2nd_current():
suggestions = suggest_type('select * from a; select * from ; select * from c',
'select * from a; select * from ')
assert sorted_dicts(suggestions) == sorted_dicts([
- {'type': 'table', 'schema': []}, {'type': 'schema'}])
+ {'type': 'table', 'schema': []},
+ {'type': 'view', 'schema': []},
+ {'type': 'schema'}])
suggestions = suggest_type('select * from a; select from b; select * from c',
'select * from a; select ')