1
0
Fork 0

Behave remove boiler plate code

This commit is contained in:
Dick Marinus 2017-05-02 20:20:13 +02:00
parent 81fb73f4b0
commit f39dda5773
12 changed files with 34 additions and 47 deletions

View File

@ -24,6 +24,7 @@ Internal changes:
* Behave test source command (Thanks: `Dick Marinus`_).
* Behave fix clean up. (Thanks: `Dick Marinus`_).
* Test using behave the tee command (Thanks: `Dick Marinus`_).
* Behave remove boiler plate code (Thanks: `Dick Marinus`_).
1.5.1
=====

View File

View File

@ -2,24 +2,14 @@ Feature: run the cli,
call the help command,
exit the cli
Scenario: run the cli
When we run dbcli
then we see dbcli prompt
Scenario: run "\?" command
When we run dbcli
and we wait for prompt
and we send "\?" command
When we send "\?" command
then we see help output
Scenario: run source command
When we run dbcli
and we wait for prompt
and we send source command
When we send source command
then we see help output
Scenario: run the cli and exit
When we run dbcli
and we wait for prompt
and we send "ctrl + d"
When we send "ctrl + d"
then dbcli exits

View File

@ -2,9 +2,7 @@ Feature: manipulate databases:
create, drop, connect, disconnect
Scenario: create and drop temporary database
When we run dbcli
and we wait for prompt
and we create database
When we create database
then we see database created
when we drop database
then we see database dropped
@ -12,9 +10,7 @@ Feature: manipulate databases:
then we see database connected
Scenario: connect and disconnect from test database
When we run dbcli
and we wait for prompt
and we connect to test database
When we connect to test database
then we see database connected
when we connect to dbserver
then we see database connected

View File

@ -2,9 +2,7 @@ Feature: manipulate tables:
create, insert, update, select, delete from, drop
Scenario: create, insert, select from, update, drop table
When we run dbcli
and we wait for prompt
and we connect to test database
When we connect to test database
then we see database connected
when we create table
then we see table created

View File

@ -8,6 +8,8 @@ import db_utils as dbutils
import fixture_utils as fixutils
import pexpect
from steps.wrappers import run_cli, wait_prompt
def before_all(context):
"""
@ -91,6 +93,11 @@ def before_step(context, _):
context.atprompt = False
def before_scenario(context, _):
run_cli(context)
wait_prompt(context)
def after_scenario(context, _):
"""Cleans up after each test complete."""

View File

@ -1,18 +1,14 @@
Feature: I/O commands
Scenario: edit sql in file with external editor
When we run dbcli
and we wait for prompt
and we start external editor providing a file name
When we start external editor providing a file name
and we type sql in the editor
and we exit the editor
then we see dbcli prompt
and we see the sql in prompt
Scenario: tee output from query
When we run dbcli
and we wait for prompt
and we tee output
When we tee output
and we wait for prompt
and we query "select 123456"
and we wait for prompt

View File

@ -2,9 +2,7 @@ Feature: named queries:
save, use and delete named queries
Scenario: save, use and delete named queries
When we run dbcli
and we wait for prompt
and we connect to test database
When we connect to test database
then we see database connected
when we save a named query
then we see the named query saved

View File

@ -2,8 +2,6 @@ Feature: Special commands
@wip
Scenario: run refresh command
When we run dbcli
and we wait for prompt
and we refresh completions
When we refresh completions
and we wait for prompt
then we see completions refresh started

View File

View File

@ -6,7 +6,6 @@ This string is used to call the step in "*.feature" file.
"""
from __future__ import unicode_literals
import pexpect
import tempfile
from behave import when
@ -15,22 +14,12 @@ import wrappers
@when('we run dbcli')
def step_run_cli(context):
"""
Run the process using pexpect.
"""
cli_cmd = context.conf.get('cli_command')
context.cli = pexpect.spawnu(cli_cmd, cwd='..')
context.exit_sent = False
context.currentdb = context.conf['dbname']
wrappers.run_cli(context)
@when('we wait for prompt')
def step_wait_prompt(context):
"""
Make sure prompt is displayed.
"""
wrappers.expect_exact(context, '{0}> '.format(context.conf['dbname']), timeout=5)
wrappers.wait_prompt(context)
@when('we send "ctrl + d"')
def step_ctrl_d(context):

View File

@ -2,6 +2,7 @@
from __future__ import unicode_literals
import re
import pexpect
def expect_exact(context, expected, timeout):
@ -18,3 +19,16 @@ def expect_exact(context, expected, timeout):
def expect_pager(context, expected, timeout):
expect_exact(context, "{0}\r\n{1}{0}\r\n".format(
context.conf['pager_boundary'], expected), timeout=timeout)
def run_cli(context):
"""Run the process using pexpect."""
cli_cmd = context.conf.get('cli_command')
context.cli = pexpect.spawnu(cli_cmd, cwd='..')
context.exit_sent = False
context.currentdb = context.conf['dbname']
def wait_prompt(context):
"""Make sure prompt is displayed."""
expect_exact(context, '{0}> '.format(context.conf['dbname']), timeout=5)