summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIryna Cherniavska <i.chernyavska@gmail.com>2015-07-27 16:28:15 -0700
committerIryna Cherniavska <i.chernyavska@gmail.com>2015-07-27 16:28:15 -0700
commit4a5c77d5ca370acc190465a3c5d503a6574d6729 (patch)
tree47fb97ab6d23d96cf12dbd5828a552184d668eff
parentf39eb99eb93b4fea7a4b4f1953bdc86be6994b36 (diff)
Added tests for db create/drop, connect/disconnect. Fix for connecting with no password (trust).
-rw-r--r--tests/features/db_utils.py2
-rw-r--r--tests/features/environment.py10
-rw-r--r--tests/features/simple_cli_commands.feature23
-rw-r--r--tests/features/steps/step_definitions.py60
4 files changed, 91 insertions, 4 deletions
diff --git a/tests/features/db_utils.py b/tests/features/db_utils.py
index 1b514ed5..63c6586b 100644
--- a/tests/features/db_utils.py
+++ b/tests/features/db_utils.py
@@ -45,7 +45,7 @@ def create_cn(hostname, password, username, dbname):
cn = connect(host=hostname, user=username, database=dbname,
password=password)
else:
- cn = connect(host=hostname, user=username, database=dbname)
+ cn = connect(user=username, database=dbname)
print('Created connection: {0}.'.format(cn.dsn))
return cn
diff --git a/tests/features/environment.py b/tests/features/environment.py
index 64ca66de..03b597ea 100644
--- a/tests/features/environment.py
+++ b/tests/features/environment.py
@@ -21,7 +21,7 @@ def before_all(context):
# Store get params from config.
context.conf = {
'host': context.config.userdata.get('pg_test_host', 'localhost'),
- 'user': context.config.userdata.get('pg_test_user', 'root'),
+ 'user': context.config.userdata.get('pg_test_user', 'postgres'),
'pass': context.config.userdata.get('pg_test_pass', None),
'dbname': context.config.userdata.get('pg_test_db', None),
}
@@ -38,10 +38,14 @@ def before_all(context):
os.environ['PGDATABASE'] = context.conf['dbname']
os.environ['PGUSER'] = context.conf['user']
os.environ['PGHOST'] = context.conf['host']
+
if context.conf['pass']:
os.environ['PGPASS'] = context.conf['pass']
- elif 'PGPASS' in os.environ:
- del os.environ['PGPASS']
+ else:
+ if 'PGPASS' in os.environ:
+ del os.environ['PGPASS']
+ if 'PGHOST' in os.environ:
+ del os.environ['PGHOST']
context.cn = dbutils.create_db(context.conf['host'], context.conf['user'],
context.conf['pass'],
diff --git a/tests/features/simple_cli_commands.feature b/tests/features/simple_cli_commands.feature
index 1121651c..5dde8c24 100644
--- a/tests/features/simple_cli_commands.feature
+++ b/tests/features/simple_cli_commands.feature
@@ -20,3 +20,26 @@ Feature: run the cli,
and we wait for prompt
and we send "ctrl + d"
then pgcli exits
+
+ Scenario: run the cli, create and drop database, exit
+ Given we have pgcli installed
+ when we run pgcli
+ and we wait for prompt
+ and we send "create database" command
+ then we see database created
+ when we send "drop database" command
+ then we see database dropped
+ when we send "ctrl + d"
+ then pgcli exits
+
+ @wip
+ Scenario: run the cli, connect and disconnect from test database, exit
+ 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 connect to postgres
+ then we see database connected
+ when we send "ctrl + d"
+ then pgcli exits
diff --git a/tests/features/steps/step_definitions.py b/tests/features/steps/step_definitions.py
index 53b0466c..f111a789 100644
--- a/tests/features/steps/step_definitions.py
+++ b/tests/features/steps/step_definitions.py
@@ -54,6 +54,42 @@ def step_send_help(context):
context.cli.sendline('\?')
+@when('we send "create database" command')
+def step_db_create(context):
+ """
+ Send create database.
+ """
+ context.cli.sendline('create database pgcli_behave_tmp;')
+ context.response = {
+ 'database_name': 'pgcli_behave_tmp'
+ }
+
+
+@when('we send "drop database" command')
+def step_db_drop(context):
+ """
+ Send drop database.
+ """
+ context.cli.sendline('drop database pgcli_behave_tmp;')
+
+
+@when('we connect to test database')
+def step_db_connect_test(context):
+ """
+ Send connect to database.
+ """
+ db_name = context.config.userdata.get('pg_test_db', None)
+ context.cli.sendline('\connect {0}'.format(db_name))
+
+
+@when('we connect to postgres')
+def step_db_connect_postgres(context):
+ """
+ Send connect to database.
+ """
+ context.cli.sendline('\connect postgres')
+
+
@then('pgcli exits')
def step_wait_exit(context):
"""
@@ -77,3 +113,27 @@ def step_see_help(context):
context.cli.expect_exact(expected_line, timeout=1)
except Exception:
raise Exception('Expected: ' + expected_line.strip() + '!')
+
+
+@then('we see database created')
+def step_see_db_created(context):
+ """
+ Wait to see create database output.
+ """
+ context.cli.expect_exact('CREATE DATABASE', timeout=2)
+
+
+@then('we see database dropped')
+def step_see_db_dropped(context):
+ """
+ Wait to see drop database output.
+ """
+ context.cli.expect_exact('DROP DATABASE', timeout=2)
+
+
+@then('we see database connected')
+def step_see_db_connected(context):
+ """
+ Wait to see drop database output.
+ """
+ context.cli.expect_exact('You are now connected to database', timeout=2)