lotr-sut/tests/backend/services/test_pact_contracts.py
Fellowship Scholar f6a5823439 init commit
2026-03-29 20:07:56 +00:00

25 lines
697 B
Python

import pytest
from pact import Consumer, Provider
import requests
# Example PACT test for a service-to-service contract
def test_pact_with_inventory_provider():
# Arrange
pact = Consumer('ShopService').has_pact_with(Provider('InventoryProvider'), port=1234)
expected = {
'id': 1,
'name': 'Sword',
'quantity': 10
}
(pact
.given('Inventory item exists')
.upon_receiving('a request for inventory item')
.with_request('get', '/inventory/1')
.will_respond_with(200, body=expected))
with pact:
# Act
result = requests.get('http://localhost:1234/inventory/1')
# Assert
assert result.json() == expected