Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions tests/consumer/test_products_consumer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
"""pact test for product service client"""
"""pact test for product service client via ruby core"""

import json
import logging
import os
import requests
from requests.auth import HTTPBasicAuth

import pytest
from pact import Consumer, Like, Provider, Term, Format
Expand Down
37 changes: 37 additions & 0 deletions tests/consumer/test_products_consumer_v3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""pact test for product service client via rust core"""

import logging
from typing import Generator

import pytest
from pact.v3.pact import Pact
from pact.v3.match import like
from src.consumer import ProductConsumer

log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

@pytest.fixture(scope='session')
def pact() -> Generator[Pact, None, None]:
pact = Pact("pactflow-example-consumer-python-v3", "pactflow-example-provider-python-v3")
yield pact.with_specification("V4")
pact.write_file("./pacts")

def test_get_product(pact) -> None:
expected = {
'id': "27",
'name': 'Margharita',
'type': 'Pizza'
}

(pact
.upon_receiving('a request to get a product')
.given('a product with ID 10 exists')
.with_request(method='GET', path='/product/10')
.will_respond_with(200)
.with_body(like(expected)))

with pact.serve() as srv:
consumer = ProductConsumer(str(srv.url))
user = consumer.get_product('10')
assert user.name == 'Margharita'
Loading