Skip to content

Commit 3c909f1

Browse files
docs: example uses date matcher (#231)
1 parent 6390144 commit 3c909f1

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

examples/e2e/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55

6+
67
def pytest_addoption(parser):
78
parser.addoption(
89
"--publish-pact", type=str, action="store",
@@ -19,6 +20,7 @@ def pytest_addoption(parser):
1920
help="Whether to run broker in this test or not."
2021
)
2122

23+
2224
# This fixture is to simulate a managed Pact Broker or Pactflow account
2325
# Do not do this yourself but setup one of the above
2426
# https://github.com/pact-foundation/pact_broker

examples/e2e/src/consumer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import requests
2+
from datetime import datetime
23

34

45
class UserConsumer(object):
@@ -13,9 +14,12 @@ def get_user(self, user_name):
1314
return None
1415

1516
name = response.json()['name']
16-
return User(name)
17+
created_on = datetime.strptime(response.json()['created_on'], '%Y-%m-%dT%H:%M:%S')
18+
19+
return User(name, created_on)
1720

1821

1922
class User(object):
20-
def __init__(self, name):
23+
def __init__(self, name, created_on):
2124
self.name = name
25+
self.created_on = created_on

examples/e2e/tests/consumer/test_user_consumer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import logging
44
import os
5+
from datetime import datetime
56

67
import pytest
7-
from pact import Consumer, Like, Provider, Term, Format
8+
from pact import Consumer, Like, Provider, Format
89

910
from src.consumer import UserConsumer
1011

@@ -47,14 +48,12 @@ def pact(request):
4748
print('stop service')
4849
pact.stop_service()
4950

51+
5052
def test_get_user_non_admin(broker, pact, consumer):
5153
expected = {
5254
'name': 'UserA',
5355
'id': Format().uuid,
54-
'created_on': Term(
55-
r'\d+-\d+-\d+T\d+:\d+:\d+',
56-
'2016-12-15T20:16:01'
57-
),
56+
'created_on': Format().timestamp,
5857
'ip_address': Format().ip_address,
5958
'admin': False
6059
}
@@ -68,6 +67,7 @@ def test_get_user_non_admin(broker, pact, consumer):
6867
with pact:
6968
user = consumer.get_user('UserA')
7069
assert user.name == 'UserA'
70+
assert user.created_on == datetime.strptime('2000-2-1T12:30:00', '%Y-%m-%dT%H:%M:%S')
7171

7272

7373
def test_get_non_existing_user(broker, pact, consumer):

examples/e2e/tests/provider/test_provider.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
PACT_URL = "http://{}:{}".format(PACT_MOCK_HOST, PACT_MOCK_PORT)
2525
PACT_DIR = os.path.dirname(os.path.realpath(__file__))
2626

27+
2728
@pytest.fixture
2829
def default_opts():
2930
return {

0 commit comments

Comments
 (0)