Skip to content

Commit c7f6667

Browse files
committed
refactor(tests): move InteractionDefinition in own module
The `__init__` was getting a bit too cluttered, so I have refactored the entire `InteractionDefinition` class into its own module. I have also refacted the nested classes to stand alone now. A minor refactor was also made to avoid assigning custom attributes to the `Flask` app, and some changes were made to the provider initialisation to avoid passing a redundant `self.app` in a method call. Signed-off-by: JP-Ellis <[email protected]>
1 parent 5381b6a commit c7f6667

11 files changed

+822
-785
lines changed

tests/v3/compatibility_suite/test_v1_consumer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
from pytest_bdd import given, parsers, scenario
88

9-
from tests.v3.compatibility_suite.util import (
10-
InteractionDefinition,
11-
parse_markdown_table,
12-
)
9+
from tests.v3.compatibility_suite.util import parse_markdown_table
1310
from tests.v3.compatibility_suite.util.consumer import (
1411
a_response_is_returned,
1512
request_n_is_made_to_the_mock_server,
@@ -34,6 +31,9 @@
3431
the_pact_test_is_done,
3532
the_payload_will_contain_the_json_document,
3633
)
34+
from tests.v3.compatibility_suite.util.interaction_definition import (
35+
InteractionDefinition,
36+
)
3737

3838
logger = logging.getLogger(__name__)
3939

@@ -320,7 +320,7 @@ def the_following_http_interactions_have_been_defined(
320320
# Parse the table into a more useful format
321321
interactions: dict[int, InteractionDefinition] = {}
322322
for row in content:
323-
interactions[int(row["No"])] = InteractionDefinition(**row)
323+
interactions[int(row["No"])] = InteractionDefinition(**row) # type: ignore[arg-type]
324324
return interactions
325325

326326

tests/v3/compatibility_suite/test_v1_provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import pytest
1111
from pytest_bdd import given, parsers, scenario
1212

13-
from tests.v3.compatibility_suite.util import (
13+
from tests.v3.compatibility_suite.util import parse_markdown_table
14+
from tests.v3.compatibility_suite.util.interaction_definition import (
1415
InteractionDefinition,
15-
parse_markdown_table,
1616
)
1717
from tests.v3.compatibility_suite.util.provider import (
1818
a_failed_verification_result_will_be_published_back,
@@ -407,7 +407,7 @@ def the_following_http_interactions_have_been_defined(
407407
# Parse the table into a more useful format
408408
interactions: dict[int, InteractionDefinition] = {}
409409
for row in content:
410-
interactions[int(row["No"])] = InteractionDefinition(**row)
410+
interactions[int(row["No"])] = InteractionDefinition(**row) # type: ignore[arg-type]
411411
return interactions
412412

413413

tests/v3/compatibility_suite/test_v2_consumer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
from pytest_bdd import given, parsers, scenario
88

9-
from tests.v3.compatibility_suite.util import (
10-
InteractionDefinition,
11-
parse_markdown_table,
12-
)
9+
from tests.v3.compatibility_suite.util import parse_markdown_table
1310
from tests.v3.compatibility_suite.util.consumer import (
1411
a_response_is_returned,
1512
request_n_is_made_to_the_mock_server,
@@ -35,6 +32,9 @@
3532
the_pact_test_is_done,
3633
the_payload_will_contain_the_json_document,
3734
)
35+
from tests.v3.compatibility_suite.util.interaction_definition import (
36+
InteractionDefinition,
37+
)
3838

3939
logger = logging.getLogger(__name__)
4040

@@ -196,7 +196,7 @@ def the_following_http_interactions_have_been_defined(
196196
# Parse the table into a more useful format
197197
interactions: dict[int, InteractionDefinition] = {}
198198
for row in table:
199-
interactions[int(row["No"])] = InteractionDefinition(**row)
199+
interactions[int(row["No"])] = InteractionDefinition(**row) # type: ignore[arg-type]
200200

201201
return interactions
202202

tests/v3/compatibility_suite/test_v2_provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import pytest
1111
from pytest_bdd import given, parsers, scenario
1212

13-
from tests.v3.compatibility_suite.util import (
13+
from tests.v3.compatibility_suite.util import parse_markdown_table
14+
from tests.v3.compatibility_suite.util.interaction_definition import (
1415
InteractionDefinition,
15-
parse_markdown_table,
1616
)
1717
from tests.v3.compatibility_suite.util.provider import (
1818
a_pact_file_for_interaction_is_to_be_verified,
@@ -125,7 +125,7 @@ def the_following_http_interactions_have_been_defined(
125125
# Parse the table into a more useful format
126126
interactions: dict[int, InteractionDefinition] = {}
127127
for row in content:
128-
interactions[int(row["No"])] = InteractionDefinition(**row)
128+
interactions[int(row["No"])] = InteractionDefinition(**row) # type: ignore[arg-type]
129129
return interactions
130130

131131

tests/v3/compatibility_suite/test_v3_message_producer.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818

1919
from pact.v3.pact import Pact
2020
from tests.v3.compatibility_suite.util import (
21-
InteractionDefinition,
2221
parse_horizontal_markdown_table,
2322
parse_markdown_table,
2423
)
24+
from tests.v3.compatibility_suite.util.interaction_definition import (
25+
InteractionDefinition,
26+
InteractionState,
27+
)
2528
from tests.v3.compatibility_suite.util.provider import (
2629
a_provider_is_started_that_can_generate_the_message,
2730
a_provider_state_callback_is_configured,
@@ -229,7 +232,7 @@ def a_pact_file_for_is_to_be_verified_with_the_following(
229232
interaction_definition = InteractionDefinition(
230233
type="Async",
231234
description=name,
232-
**table,
235+
**table, # type: ignore[arg-type]
233236
)
234237
interaction_definition.add_to_pact(pact, name)
235238
(temp_dir / "pacts").mkdir(exist_ok=True, parents=True)
@@ -284,16 +287,14 @@ def a_pact_file_for_is_to_be_verified_with_provider_state(
284287
description=name,
285288
body=fixture,
286289
)
287-
interaction_definition.states = [InteractionDefinition.State(provider_state)]
290+
interaction_definition.states = [InteractionState(provider_state)]
288291
interaction_definition.add_to_pact(pact, name)
289292
(temp_dir / "pacts").mkdir(exist_ok=True, parents=True)
290293
pact.write_file(temp_dir / "pacts")
291294
verifier.add_source(temp_dir / "pacts")
292295
with (temp_dir / "provider_states").open("w") as f:
293296
logger.debug("Writing provider state to %s", temp_dir / "provider_states")
294-
json.dump(
295-
[s.as_dict() for s in [InteractionDefinition.State(provider_state)]], f
296-
)
297+
json.dump([s.as_dict() for s in [InteractionState(provider_state)]], f)
297298

298299

299300
@given(

tests/v3/compatibility_suite/test_v3_provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import pytest
1111
from pytest_bdd import given, parsers, scenario
1212

13-
from tests.v3.compatibility_suite.util import (
13+
from tests.v3.compatibility_suite.util import parse_markdown_table
14+
from tests.v3.compatibility_suite.util.interaction_definition import (
1415
InteractionDefinition,
15-
parse_markdown_table,
1616
)
1717
from tests.v3.compatibility_suite.util.provider import (
1818
a_pact_file_for_interaction_is_to_be_verified_with_a_provider_states_defined,
@@ -100,7 +100,7 @@ def the_following_http_interactions_have_been_defined(
100100
# Parse the table into a more useful format
101101
interactions: dict[int, InteractionDefinition] = {}
102102
for row in content:
103-
interactions[int(row["No"])] = InteractionDefinition(**row)
103+
interactions[int(row["No"])] = InteractionDefinition(**row) # type: ignore[arg-type]
104104
return interactions
105105

106106

tests/v3/compatibility_suite/test_v4_provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import pytest
1111
from pytest_bdd import given, parsers, scenario
1212

13-
from tests.v3.compatibility_suite.util import (
13+
from tests.v3.compatibility_suite.util import parse_markdown_table
14+
from tests.v3.compatibility_suite.util.interaction_definition import (
1415
InteractionDefinition,
15-
parse_markdown_table,
1616
)
1717
from tests.v3.compatibility_suite.util.provider import (
1818
a_pact_file_for_interaction_is_to_be_verified,
@@ -104,7 +104,7 @@ def the_following_http_interactions_have_been_defined(
104104
# Parse the table into a more useful format
105105
interactions: dict[int, InteractionDefinition] = {}
106106
for row in content:
107-
interactions[int(row["No"])] = InteractionDefinition(**row)
107+
interactions[int(row["No"])] = InteractionDefinition(**row) # type: ignore[arg-type]
108108
return interactions
109109

110110

0 commit comments

Comments
 (0)