File: crud_database.py

package info (click to toggle)
mycli 1.44.1-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,048 kB
  • sloc: python: 9,087; makefile: 10
file content (113 lines) | stat: -rw-r--r-- 3,314 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# type: ignore

"""Steps for behavioral style tests are defined in this module.

Each step is defined by the string decorating it. This string is used
to call the step in "*.feature" file.

"""

from behave import then, when
import pexpect
import wrappers


@when("we create database")
def step_db_create(context):
    """Send create database."""
    context.cli.sendline(f"create database {context.conf['dbname_tmp']};")

    context.response = {"database_name": context.conf["dbname_tmp"]}


@when("we drop database")
def step_db_drop(context):
    """Send drop database."""
    context.cli.sendline(f"drop database {context.conf['dbname_tmp']};")


@when("we connect to test database")
def step_db_connect_test(context):
    """Send connect to database."""
    db_name = context.conf["dbname"]
    context.currentdb = db_name
    context.cli.sendline(f"use {db_name};")


@when("we connect to quoted test database")
def step_db_connect_quoted_tmp(context):
    """Send connect to database."""
    db_name = context.conf["dbname"]
    context.currentdb = db_name
    context.cli.sendline(f"use `{db_name}`;")


@when("we connect to tmp database")
def step_db_connect_tmp(context):
    """Send connect to database."""
    db_name = context.conf["dbname_tmp"]
    context.currentdb = db_name
    context.cli.sendline(f"use {db_name}")


@when("we connect to dbserver")
def step_db_connect_dbserver(context):
    """Send connect to database."""
    context.currentdb = "mysql"
    context.cli.sendline("use mysql")


@then("dbcli exits")
def step_wait_exit(context):
    """Make sure the cli exits."""
    wrappers.expect_exact(context, pexpect.EOF, timeout=5)


@then("we see dbcli prompt")
def step_see_prompt(context):
    """Wait to see the prompt."""
    user = context.conf["user"]
    host = context.conf["host"]
    dbname = context.currentdb
    wrappers.wait_prompt(context, f"{user}@{host}:{dbname}> ")


@then("we see help output")
def step_see_help(context):
    for expected_line in context.fixture_data["help_commands.txt"]:
        # in case tests are run without extras
        if 'LLM' in expected_line:
            continue
        wrappers.expect_exact(context, expected_line, timeout=1)


@then("we see database created")
def step_see_db_created(context):
    """Wait to see create database output."""
    wrappers.expect_exact(context, "Query OK, 1 row affected", timeout=2)


@then("we see database dropped")
def step_see_db_dropped(context):
    """Wait to see drop database output."""
    wrappers.expect_exact(context, "Query OK, 0 rows affected", timeout=2)


@then("we see database dropped and no default database")
def step_see_db_dropped_no_default(context):
    """Wait to see drop database output."""
    user = context.conf["user"]
    host = context.conf["host"]
    database = "(none)"
    context.currentdb = None

    wrappers.expect_exact(context, "Query OK, 0 rows affected", timeout=2)
    wrappers.wait_prompt(context, f"{user}@{host}:{database}>")


@then("we see database connected")
def step_see_db_connected(context):
    """Wait to see drop database output."""
    wrappers.expect_exact(context, 'connected to database "', timeout=2)
    wrappers.expect_exact(context, '"', timeout=2)
    wrappers.expect_exact(context, f' as user "{context.conf["user"]}"', timeout=2)