Skip to content

Commit c256717

Browse files
committed
test: add ruby/rust impl based DELETE reqs with body
1 parent 4a898b6 commit c256717

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/consumer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ def get_product(self, id):
1414
json = response.json()
1515
return Product(json['id'], json['type'], json['name'])
1616

17+
def delete_product(self, id):
18+
"""Delete product by ID"""
19+
uri = self.base_uri + '/product/' + id
20+
response = requests.delete(uri, json={'id': id})
21+
if response.status_code == 404:
22+
return None
23+
24+
status_code = response.status_code
25+
return status_code
26+
1727

1828
class Product(object):
1929
def __init__(self, id, type, name ):

tests/consumer/test_products_consumer.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,18 @@ def test_get_product(pact, consumer):
5454
with pact:
5555
user = consumer.get_product('10')
5656
assert user.name == 'Margharita'
57+
58+
def test_delete_product_with_body(pact, consumer):
59+
expected = {
60+
'id': "27"
61+
}
62+
63+
(pact
64+
.given('a product with ID 10 exists')
65+
.upon_receiving('a request to delete a product')
66+
.with_request('DELETE', '/product/10', headers={'Content-Type': 'application/json'}, body=Like(expected))
67+
.will_respond_with(204))
68+
69+
with pact:
70+
response = consumer.delete_product('10')
71+
assert response == 204

tests/consumer/test_products_consumer_v3.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
log = logging.getLogger(__name__)
1212
logging.basicConfig(level=logging.INFO)
1313

14-
@pytest.fixture(scope='session')
14+
@pytest.fixture
1515
def pact() -> Generator[Pact, None, None]:
1616
pact = Pact("pactflow-example-consumer-python-v3", "pactflow-example-provider-python-v3")
1717
yield pact.with_specification("V4")
@@ -35,3 +35,20 @@ def test_get_product(pact) -> None:
3535
consumer = ProductConsumer(str(srv.url))
3636
user = consumer.get_product('10')
3737
assert user.name == 'Margharita'
38+
39+
def test_delete_product_with_body(pact) -> None:
40+
expected = {
41+
'id': "27"
42+
}
43+
44+
(pact
45+
.upon_receiving('a request to delete a product')
46+
.given('a product with ID 10 exists')
47+
.with_request(method='DELETE', path='/product/10')
48+
.with_body(like(expected))
49+
.will_respond_with(204))
50+
51+
with pact.serve() as srv:
52+
consumer = ProductConsumer(str(srv.url))
53+
response = consumer.delete_product('10')
54+
assert response == 204

0 commit comments

Comments
 (0)