Skip to content

Commit 2240ebf

Browse files
committed
feat: support Decimal data type in MessageProvider
1 parent 0d5b921 commit 2240ebf

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

examples/message/tests/consumer/test_message_consumer.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""pact test for a message consumer"""
22

3+
from decimal import Decimal
34
import logging
45
import pytest
56
import time
@@ -8,6 +9,8 @@
89
from os.path import isfile
910

1011
from pact import MessageConsumer, Provider
12+
from pact import matchers
13+
from pact.matchers import Like, Term
1114
from src.message_handler import MessageHandler, CustomError
1215

1316
log = logging.getLogger(__name__)
@@ -104,9 +107,10 @@ def test_put_file(pact_no_publish):
104107

105108
expected_event = {
106109
"event": "ObjectCreated:Put",
107-
"documentName": "document.doc",
108-
"creator": "TP",
109-
"documentType": "microsoft-word"
110+
"documentName": Term("^.*\\.(doc|docx)$", 'document.doc'),
111+
"creator": Like("TP"),
112+
"decimal-data": Decimal(0.1),
113+
"documentType": "microsoft-word",
110114
}
111115

112116
(pact_no_publish
@@ -118,7 +122,7 @@ def test_put_file(pact_no_publish):
118122
}))
119123

120124
with pact_no_publish:
121-
MessageHandler(expected_event)
125+
MessageHandler(matchers.get_generated_values(expected_event))
122126

123127
progressive_delay(f"{PACT_FILE}")
124128
assert isfile(f"{PACT_FILE}") == 1

examples/message/tests/provider/test_message_provider.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from decimal import Decimal
12
import pytest
23
from pact import MessageProvider
34

@@ -22,7 +23,8 @@ def document_created_handler():
2223
return {
2324
"event": "ObjectCreated:Put",
2425
"documentName": "document.doc",
25-
"creator": "TP",
26+
"creator": "PF",
27+
"decimal-data": Decimal(0.1),
2628
"documentType": "microsoft-word"
2729
}
2830

pact/matchers.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""Classes for defining request and response data that is variable."""
2+
from decimal import Decimal
23
import six
34
import datetime
45

56
from enum import Enum
6-
from decimal import Decimal
7-
87

98
class Matcher(object):
109
"""Base class for defining complex contract expectations."""
@@ -214,7 +213,7 @@ def get_generated_values(input):
214213
"""
215214
if input is None:
216215
return input
217-
if isinstance(input, (six.string_types, int, float, bool)):
216+
if isinstance(input, (six.string_types, int, float, bool, Decimal)):
218217
return input
219218
if isinstance(input, dict):
220219
return {k: get_generated_values(v) for k, v in input.items()}

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def read(filename):
228228
'six>=1.16.0',
229229
'fastapi>=0.67.0',
230230
'urllib3>=1.26.12',
231+
'simplejson==3.18.4'
231232
]
232233

233234
if sys.version_info < (3, 7):

0 commit comments

Comments
 (0)