Skip to content

Commit 4ab57d1

Browse files
authored
Merge pull request #14 from pactflow/test/pact-python-v3
add pact v3 python example
2 parents 3818ddc + 891c8bf commit 4ab57d1

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

tests/consumer/test_products_consumer.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
"""pact test for product service client"""
1+
"""pact test for product service client via ruby core"""
22

3-
import json
43
import logging
54
import os
6-
import requests
7-
from requests.auth import HTTPBasicAuth
85

96
import pytest
107
from pact import Consumer, Like, Provider, Term, Format
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""pact test for product service client via rust core"""
2+
3+
import logging
4+
from typing import Generator
5+
6+
import pytest
7+
from pact.v3.pact import Pact
8+
from pact.v3.match import like
9+
from src.consumer import ProductConsumer
10+
11+
log = logging.getLogger(__name__)
12+
logging.basicConfig(level=logging.INFO)
13+
14+
@pytest.fixture(scope='session')
15+
def pact() -> Generator[Pact, None, None]:
16+
pact = Pact("pactflow-example-consumer-python-v3", "pactflow-example-provider-python-v3")
17+
yield pact.with_specification("V4")
18+
pact.write_file("./pacts")
19+
20+
def test_get_product(pact) -> None:
21+
expected = {
22+
'id': "27",
23+
'name': 'Margharita',
24+
'type': 'Pizza'
25+
}
26+
27+
(pact
28+
.upon_receiving('a request to get a product')
29+
.given('a product with ID 10 exists')
30+
.with_request(method='GET', path='/product/10')
31+
.will_respond_with(200)
32+
.with_body(like(expected)))
33+
34+
with pact.serve() as srv:
35+
consumer = ProductConsumer(str(srv.url))
36+
user = consumer.get_product('10')
37+
assert user.name == 'Margharita'

0 commit comments

Comments
 (0)