summaryrefslogtreecommitdiffstats
path: root/tests/features/steps/crud_table.py
blob: 27d543e74b49b547250b89dfd3c4055a152a5e73 (plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
"""
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 when, then
from textwrap import dedent
import wrappers


INITIAL_DATA = "xxx"
UPDATED_DATA = "yyy"


@when("we create table")
def step_create_table(context):
    """
    Send create table.
    """
    context.cli.sendline("create table a(x text);")


@when("we insert into table")
def step_insert_into_table(context):
    """
    Send insert into table.
    """
    context.cli.sendline(f"""insert into a(x) values('{INITIAL_DATA}');""")


@when("we update table")
def step_update_table(context):
    """
    Send insert into table.
    """
    context.cli.sendline(
        f"""update a set x = '{UPDATED_DATA}' where x = '{INITIAL_DATA}';"""
    )


@when("we select from table")
def step_select_from_table(context):
    """
    Send select from table.
    """
    context.cli.sendline("select * from a;")


@when("we delete from table")
def step_delete_from_table(context):
    """
    Send deete from table.
    """
    context.cli.sendline(f"""delete from a where x = '{UPDATED_DATA}';""")


@when("we drop table")
def step_drop_table(context):
    """
    Send drop table.
    """
    context.cli.sendline("drop table a;")


@when("we alter the table")
def step_alter_table(context):
    """
    Alter the table by adding a column.
    """
    context.cli.sendline("""alter table a add column y varchar;""")


@when("we begin transaction")
def step_begin_transaction(context):
    """
    Begin transaction
    """
    context.cli.sendline("begin;")


@when("we rollback transaction")
def step_rollback_transaction(context):
    """
    Rollback transaction
    """
    context.cli.sendline("rollback;")


@then("we see table created")
def step_see_table_created(context):
    """
    Wait to see create table output.
    """
    wrappers.expect_pager(context, "CREATE TABLE\r\n", timeout=2)


@then("we see record inserted")
def step_see_record_inserted(context):
    """
    Wait to see insert output.
    """
    wrappers.expect_pager(context, "INSERT 0 1\r\n", timeout=2)


@then("we see record updated")
def step_see_record_updated(context):
    """
    Wait to see update output.
    """
    wrappers.expect_pager(context, "UPDATE 1\r\n", timeout=2)


@then("we see data selected: {data}")
def step_see_data_selected(context, data):
    """
    Wait to see select output with initial or updated data.
    """
    x = UPDATED_DATA if data == "updated" else INITIAL_DATA
    wrappers.expect_pager(
        context,
        dedent(
            f"""\
            +-----+\r
            | x   |\r
            |-----|\r
            | {x} |\r
            +-----+\r
            SELECT 1\r
        """
        ),
        timeout=1,
    )


@then("we see select output without data")
def step_see_no_data_selected(context):
    """
    Wait to see select output without data.
    """
    wrappers.expect_pager(
        context,
        dedent(
            """\
            +---+\r
            | x |\r
            |---|\r
            +---+\r
            SELECT 0\r
        """
        ),
        timeout=1,
    )


@then("we see record deleted")
def step_see_data_deleted(context):
    """
    Wait to see delete output.
    """
    wrappers.expect_pager(context, "DELETE 1\r\n", timeout=2)


@then("we see table dropped")
def step_see_table_dropped(context):
    """
    Wait to see drop output.
    """
    wrappers.expect_pager(context, "DROP TABLE\r\n", timeout=2)


@then("we see transaction began")
def step_see_transaction_began(context):
    """
    Wait to see transaction began.
    """
    wrappers.expect_pager(context, "BEGIN\r\n", timeout=2)


@then("we see transaction rolled back")
def step_see_transaction_rolled_back(context):
    """
    Wait to see transaction rollback.
    """
    wrappers.expect_pager(context, "ROLLBACK\r\n", timeout=2)