Skip to content

Commit e645b24

Browse files
sunsathish88Sathish SundararajanSathish Sundararajan
authored
feat: message_pact -> with_metadata() updated to accept term (#289)
* feat: Included term matcher to meta data for message_pact * feat: Included term matcher to meta data for message_pact * feat: fixed flake issues Co-authored-by: Sathish Sundararajan <[email protected]> Co-authored-by: Sathish Sundararajan <[email protected]>
1 parent b981865 commit e645b24

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

pact/message_pact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def with_metadata(self, metadata):
125125
:rtype: Pact
126126
"""
127127
self._insert_message_if_complete()
128-
self._messages[0]['metaData'] = metadata
128+
self._messages[0]['metaData'] = from_term(metadata)
129129
return self
130130

131131
def with_content(self, contents):

tests/test_message_pact.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pact.message_pact import MessagePact
99
from pact.constants import MESSAGE_PATH
1010
from pact import message_pact as message_pact
11+
from pact import Term
1112

1213
class MessagePactTestCase(TestCase):
1314
def setUp(self):
@@ -57,7 +58,9 @@ def test_definition_sparse(self):
5758
.given('there is an alligator named John')
5859
.expects_to_receive('an alligator message')
5960
.with_content({'name': 'John', 'document_name': 'sample_document.doc'})
60-
.with_metadata({'contentType': 'application/json', 'source': 'legacy_api'})
61+
.with_metadata({'contentType': 'application/json',
62+
'source': 'legacy_api',
63+
'some-header': Term('\\d+-\\d+-\\d+T\\d+:\\d+:\\d+', '2022-02-15T20:16:01')})
6164
)
6265

6366
self.assertEqual(len(target._messages), 1)
@@ -74,9 +77,10 @@ def test_definition_sparse(self):
7477
target._messages[0]['contents'],
7578
{'name': 'John', 'document_name': 'sample_document.doc'})
7679

77-
self.assertEqual(
78-
target._messages[0]['metaData'],
79-
{'contentType': 'application/json', 'source': 'legacy_api'})
80+
self.assertTrue({'contentType': 'application/json', 'source': 'legacy_api'}.items()
81+
<= target._messages[0]['metaData'].items())
82+
83+
self.assertTrue(target._messages[0]['metaData']['some-header'], 'Pact::Term')
8084

8185
def test_insert_new_message_once_required_attributes_provided(self):
8286
target = MessagePact(self.consumer, self.provider)

0 commit comments

Comments
 (0)