Skip to content

Commit 3bcd4b4

Browse files
feanilclaude
andcommitted
fix: migrate pact Verifier to pact-python 3.x API
pact-python 3.x (released after the 1.x series) ships a new Rust FFI-based verifier that breaks backward compatibility with the old Ruby-based verifier. The constructor and verification call both changed: Old API (pact-python 1.x): verifier = Verifier(provider='lms', provider_base_url=url) output, _ = verifier.verify_pacts(pact_file, headers=[...], provider_states_setup_url=...) assert output == 0 New API (pact-python 3.x): Verifier(name='lms') .add_transport(url=url) .add_source(pact_file) .add_custom_header('Pact-Authentication', 'Allow') .state_handler(provider_states_setup_url, body=True) .verify() Key differences: - `provider` → `name`, `provider_base_url` → `.add_transport(url=...)` - `verify_pacts()` is gone; replaced by fluent `.add_source()` + `.verify()` - Headers are set individually via `.add_custom_header(name, value)` rather than as a list of `Key: Value` strings - `provider_states_setup_url` becomes `.state_handler(url, body=True)`; `body=True` is required for URL-based handlers and matches what the provider state views already expect (they read from request.body) - `verify()` raises RuntimeError on failure instead of returning a non-zero exit code, so the `assert output == 0` is no longer needed - The verifier is now created fresh inside the test method rather than in setUpClass, because `add_source` and `add_custom_header` accumulate state on the underlying FFI handle — sharing a verifier across multiple test invocations would cause duplicate sources/headers on the second run Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent bbc3c64 commit 3bcd4b4

3 files changed

Lines changed: 30 additions & 59 deletions

File tree

lms/djangoapps/course_api/blocks/tests/pacts/verify_pact.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,15 @@
1717
class ProviderVerificationServer(LiveServerTestCase):
1818
""" Django Test Live Server for Pact Verification """
1919

20-
@classmethod
21-
def setUpClass(cls):
22-
super().setUpClass()
23-
24-
cls.verifier = Verifier(
25-
provider='lms',
26-
provider_base_url=cls.live_server_url,
27-
)
28-
29-
@classmethod
30-
def tearDownClass(cls):
31-
super().tearDownClass()
32-
3320
def test_verify_pact(self):
34-
output, _ = self.verifier.verify_pacts(
35-
os.path.join(PACT_DIR, PACT_FILE),
36-
headers=['Pact-Authentication: Allow', ],
37-
provider_states_setup_url=f"{self.live_server_url}{reverse('provider-state-view')}",
21+
(
22+
Verifier(name='lms')
23+
.add_transport(url=self.live_server_url)
24+
.add_source(os.path.join(PACT_DIR, PACT_FILE))
25+
.add_custom_header('Pact-Authentication', 'Allow')
26+
.state_handler(
27+
f"{self.live_server_url}{reverse('provider-state-view')}",
28+
body=True,
29+
)
30+
.verify()
3831
)
39-
40-
assert output == 0

lms/djangoapps/courseware/tests/pacts/verify_pact.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,15 @@
1717
class ProviderVerificationServer(LiveServerTestCase):
1818
""" Django Test Live Server for Pact Verification """
1919

20-
@classmethod
21-
def setUpClass(cls):
22-
super().setUpClass()
23-
24-
cls.verifier = Verifier(
25-
provider='lms',
26-
provider_base_url=cls.live_server_url,
27-
)
28-
29-
@classmethod
30-
def tearDownClass(cls):
31-
super().tearDownClass()
32-
3320
def test_verify_pact(self):
34-
output, _ = self.verifier.verify_pacts(
35-
os.path.join(PACT_DIR, PACT_FILE),
36-
headers=['Pact-Authentication: Allow', ],
37-
provider_states_setup_url=f"{self.live_server_url}{reverse('courseware_xblock_handler_provider_state')}",
21+
(
22+
Verifier(name='lms')
23+
.add_transport(url=self.live_server_url)
24+
.add_source(os.path.join(PACT_DIR, PACT_FILE))
25+
.add_custom_header('Pact-Authentication', 'Allow')
26+
.state_handler(
27+
f"{self.live_server_url}{reverse('courseware_xblock_handler_provider_state')}",
28+
body=True,
29+
)
30+
.verify()
3831
)
39-
40-
assert output == 0

openedx/core/djangoapps/courseware_api/tests/pacts/verify_pact.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,16 @@
2020
class ProviderVerificationServer(LiveServerTestCase):
2121
""" Live Server for Pact Verification"""
2222

23-
@classmethod
24-
def setUpClass(cls):
25-
super().setUpClass()
26-
27-
cls.PACT_URL = cls.live_server_url
28-
29-
cls.verifier = Verifier(
30-
provider='lms',
31-
provider_base_url=cls.PACT_URL,
32-
)
33-
34-
@classmethod
35-
def tearDownClass(cls):
36-
super().tearDownClass()
37-
3823
@override_waffle_flag(DISCOUNT_APPLICABILITY_FLAG, active=True)
3924
def test_verify_pact(self):
40-
output, _ = self.verifier.verify_pacts(
41-
os.path.join(PACT_DIR, PACT_FILE),
42-
headers=['Pact-Authentication: Allow', ],
43-
provider_states_setup_url=f"{self.PACT_URL}{reverse('courseware_api:provider-state-view')}",
25+
(
26+
Verifier(name='lms')
27+
.add_transport(url=self.live_server_url)
28+
.add_source(os.path.join(PACT_DIR, PACT_FILE))
29+
.add_custom_header('Pact-Authentication', 'Allow')
30+
.state_handler(
31+
f"{self.live_server_url}{reverse('courseware_api:provider-state-view')}",
32+
body=True,
33+
)
34+
.verify()
4435
)
45-
46-
assert output == 0

0 commit comments

Comments
 (0)