-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathtest_v2_consumer.py
235 lines (186 loc) · 7.94 KB
/
test_v2_consumer.py
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
"""Basic HTTP consumer feature tests."""
from __future__ import annotations
import logging
from pytest_bdd import given, parsers, scenario
from tests.v3.compatibility_suite.util import (
InteractionDefinition,
parse_markdown_table,
)
from tests.v3.compatibility_suite.util.consumer import (
a_response_is_returned,
request_n_is_made_to_the_mock_server,
request_n_is_made_to_the_mock_server_with_the_following_changes,
the_content_type_will_be_set_as,
the_mismatches_will_contain_a_mismatch_with_path_with_the_error,
the_mismatches_will_contain_a_mismatch_with_the_error,
the_mock_server_is_started_with_interaction_n_but_with_the_following_changes,
the_mock_server_is_started_with_interactions,
the_mock_server_status_will_be,
the_mock_server_status_will_be_an_expected_but_not_received_error_for_interaction_n,
the_mock_server_status_will_be_an_unexpected_request_received_for_interaction_n,
the_mock_server_status_will_be_an_unexpected_request_received_for_path,
the_mock_server_status_will_be_mismatches,
the_mock_server_will_write_out_a_pact_file_for_the_interaction_when_done,
the_nth_interaction_request_content_type_will_be,
the_nth_interaction_request_query_parameters_will_be,
the_nth_interaction_request_will_be_for_method,
the_nth_interaction_request_will_contain_the_document,
the_nth_interaction_request_will_contain_the_header,
the_nth_interaction_will_contain_the_document,
the_pact_file_will_contain_n_interactions,
the_pact_test_is_done,
the_payload_will_contain_the_json_document,
)
logger = logging.getLogger(__name__)
################################################################################
## Scenario
################################################################################
@scenario(
"definition/features/V2/http_consumer.feature",
"Supports a regex matcher (negative case)",
)
def test_supports_a_regex_matcher_negative_case() -> None:
"""Supports a regex matcher (negative case)."""
@scenario(
"definition/features/V2/http_consumer.feature",
"Supports a regex matcher (positive case)",
)
def test_supports_a_regex_matcher_positive_case() -> None:
"""Supports a regex matcher (positive case)."""
@scenario(
"definition/features/V2/http_consumer.feature",
"Supports a type matcher (negative case)",
)
def test_supports_a_type_matcher_negative_case() -> None:
"""Supports a type matcher (negative case)."""
@scenario(
"definition/features/V2/http_consumer.feature",
"Supports a type matcher (positive case)",
)
def test_supports_a_type_matcher_positive_case() -> None:
"""Supports a type matcher (positive case)."""
@scenario(
"definition/features/V2/http_consumer.feature",
"Supports matchers for repeated request headers (negative case)",
)
def test_supports_matchers_for_repeated_request_headers_negative_case() -> None:
"""Supports matchers for repeated request headers (negative case)."""
@scenario(
"definition/features/V2/http_consumer.feature",
"Supports matchers for repeated request headers (positive case)",
)
def test_supports_matchers_for_repeated_request_headers_positive_case() -> None:
"""Supports matchers for repeated request headers (positive case)."""
@scenario(
"definition/features/V2/http_consumer.feature",
"Supports matchers for repeated request query parameters (negative case)",
)
def test_supports_matchers_for_repeated_request_query_parameters_negative_case() -> (
None
):
"""Supports matchers for repeated request query parameters (negative case)."""
@scenario(
"definition/features/V2/http_consumer.feature",
"Supports matchers for repeated request query parameters (positive case)",
)
def test_supports_matchers_for_repeated_request_query_parameters_positive_case() -> (
None
):
"""Supports matchers for repeated request query parameters (positive case)."""
@scenario(
"definition/features/V2/http_consumer.feature",
"Supports matchers for request bodies",
)
def test_supports_matchers_for_request_bodies() -> None:
"""Supports matchers for request bodies."""
@scenario(
"definition/features/V2/http_consumer.feature",
"Supports matchers for request headers",
)
def test_supports_matchers_for_request_headers() -> None:
"""Supports matchers for request headers."""
@scenario(
"definition/features/V2/http_consumer.feature",
"Supports matchers for request query parameters",
)
def test_supports_matchers_for_request_query_parameters() -> None:
"""Supports matchers for request query parameters."""
@scenario(
"definition/features/V2/http_consumer.feature",
"Type matchers cascade to children (negative case)",
)
def test_type_matchers_cascade_to_children_negative_case() -> None:
"""Type matchers cascade to children (negative case)."""
@scenario(
"definition/features/V2/http_consumer.feature",
"Type matchers cascade to children (positive case)",
)
def test_type_matchers_cascade_to_children_positive_case() -> None:
"""Type matchers cascade to children (positive case)."""
@scenario(
"definition/features/V2/http_consumer.feature",
"Supports a matcher for request paths",
)
def test_supports_a_matcher_for_request_paths() -> None:
"""Supports a matcher for request paths."""
################################################################################
## Given
################################################################################
@given(
parsers.parse("the following HTTP interactions have been defined:\n{content}"),
target_fixture="interaction_definitions",
)
def the_following_http_interactions_have_been_defined(
content: str,
) -> dict[int, InteractionDefinition]:
"""
Parse the HTTP interactions table into a dictionary.
The table columns are expected to be:
- No
- method
- path
- query
- headers
- body
- matching rules
The first row is ignored, as it is assumed to be the column headers. The
order of the columns is similarly ignored.
"""
table = parse_markdown_table(content)
# Check that the table is well-formed
assert len(table[0]) == 7, f"Expected 7 columns, got {len(table[0])}"
assert "No" in table[0], "'No' column not found"
# Parse the table into a more useful format
interactions: dict[int, InteractionDefinition] = {}
for row in table:
interactions[int(row["No"])] = InteractionDefinition(**row)
return interactions
################################################################################
## When
################################################################################
request_n_is_made_to_the_mock_server()
request_n_is_made_to_the_mock_server_with_the_following_changes()
the_mock_server_is_started_with_interactions("V2")
the_mock_server_is_started_with_interaction_n_but_with_the_following_changes("V2")
the_pact_test_is_done()
################################################################################
## Then
################################################################################
a_response_is_returned()
the_content_type_will_be_set_as()
the_mismatches_will_contain_a_mismatch_with_path_with_the_error()
the_mismatches_will_contain_a_mismatch_with_the_error()
the_mock_server_status_will_be()
the_mock_server_status_will_be_an_expected_but_not_received_error_for_interaction_n()
the_mock_server_status_will_be_an_unexpected_request_received_for_interaction_n()
the_mock_server_status_will_be_an_unexpected_request_received_for_path()
the_mock_server_status_will_be_mismatches()
the_mock_server_will_write_out_a_pact_file_for_the_interaction_when_done()
the_nth_interaction_request_content_type_will_be()
the_nth_interaction_request_query_parameters_will_be()
the_nth_interaction_request_will_be_for_method()
the_nth_interaction_request_will_contain_the_document()
the_nth_interaction_request_will_contain_the_header()
the_nth_interaction_will_contain_the_document()
the_pact_file_will_contain_n_interactions()
the_payload_will_contain_the_json_document()