summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Koljonen <koljonen@outlook.com>2016-08-23 12:11:23 +0200
committerJoakim Koljonen <koljonen@outlook.com>2016-08-23 13:47:04 +0200
commit6d41a8a6bd147a9d74845792408efd80b60511c5 (patch)
tree83a06582795e5c2280f49bb1d880152f32647f11
parentbeb9ceae946c3db9cff6d21d0f35485e853411d6 (diff)
Fix crash bug with named queries
And add behave tests.
-rw-r--r--pgcli/pgcompleter.py5
-rw-r--r--tests/features/named_queries.feature13
-rw-r--r--tests/features/steps/step_definitions.py45
3 files changed, 61 insertions, 2 deletions
diff --git a/pgcli/pgcompleter.py b/pgcli/pgcompleter.py
index 3c876aba..580bbc9d 100644
--- a/pgcli/pgcompleter.py
+++ b/pgcli/pgcompleter.py
@@ -250,10 +250,11 @@ class PGCompleter(Completer):
"""
- type_priority = [
+ prio_order = [
'keyword', 'function', 'view', 'table', 'datatype', 'database',
'schema', 'column', 'table alias', 'join', 'name join', 'fk join'
- ].index(meta) if meta else -1
+ ]
+ type_priority = prio_order.index(meta) if meta in prio_order else -1
text = last_word(text, include='most_punctuations').lower()
text_len = len(text)
diff --git a/tests/features/named_queries.feature b/tests/features/named_queries.feature
new file mode 100644
index 00000000..89f21dc8
--- /dev/null
+++ b/tests/features/named_queries.feature
@@ -0,0 +1,13 @@
+Feature: named queries:
+ save, use and delete named queries
+
+ Scenario: save, use and delete named queries
+ Given we have pgcli installed
+ when we run pgcli
+ and we wait for prompt
+ and we connect to test database
+ then we see database connected
+ when we save a named query
+ then we see the named query saved
+ when we delete a named query
+ then we see the named query deleted
diff --git a/tests/features/steps/step_definitions.py b/tests/features/steps/step_definitions.py
index afeb6af9..13d14ffb 100644
--- a/tests/features/steps/step_definitions.py
+++ b/tests/features/steps/step_definitions.py
@@ -56,6 +56,26 @@ def step_send_help(context):
"""
context.cli.sendline('\?')
+@when('we save a named query')
+def step_save_named_query(context):
+ """
+ Send \ns command
+ """
+ context.cli.sendline('\\ns foo SELECT 12345')
+
+@when('we use a named query')
+def step_use_named_query(context):
+ """
+ Send \n command
+ """
+ context.cli.sendline('\\n foo')
+
+@when('we delete a named query')
+def step_delete_named_query(context):
+ """
+ Send \nd command
+ """
+ context.cli.sendline('\\nd foo')
@when('we create database')
def step_db_create(context):
@@ -283,6 +303,31 @@ def step_see_table_dropped(context):
_expect_exact(context, 'DROP TABLE', timeout=2)
+@then('we see the named query saved')
+def step_see_named_query_saved(context):
+ """
+ Wait to see query saved.
+ """
+ _expect_exact(context, 'Saved.', timeout=1)
+
+
+@then('we see the named query executed')
+def step_see_named_query_executed(context):
+ """
+ Wait to see select output.
+ """
+ _expect_exact(context, '12345', timeout=1)
+ _expect_exact(context, 'SELECT 1', timeout=1)
+
+
+@then('we see the named query deleted')
+def step_see_named_query_deleted(context):
+ """
+ Wait to see query deleted.
+ """
+ _expect_exact(context, 'foo: Deleted', timeout=1)
+
+
@then('we see completions refresh started')
def step_see_refresh_started(context):
"""