Skip to content

Commit

Permalink
feat: Enhance provider states for pact-message
Browse files Browse the repository at this point in the history
* feat: allow multiple provider states to be defined in a pact

* feat: allow additional parameters to be passed in the provider state

Signed-off-by: Nuno Frias <nsfrias@gmail.com>
  • Loading branch information
Nuno Frias committed Jan 13, 2023
1 parent 0971c24 commit edd73bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pact/message_pact.py
Expand Up @@ -108,15 +108,15 @@ def given(self, name, params=None):
:param name: The short sentence that is unique to describe the provider
state for this contract.
:type name: basestring
:param params: Additional arguments necessary to set the porovider state
:param params: Additional arguments necessary to set the provider state
:type params: dict
:rtype: Pact
"""
self._insert_message_if_complete()

provider_state = {'name': "{}".format(name)}
if params:
provider_state['params'] = from_term(params)
provider_state['params'] = params

if 'providerStates' not in self._messages[0]:
self._messages[0]['providerStates'] = [provider_state]
Expand Down
14 changes: 6 additions & 8 deletions tests/test_message_pact.py
Expand Up @@ -87,11 +87,9 @@ def test_definition_multiple_provider_states(self):
(
target
.given('there is an alligator named John',
params={'color':'green', 'weight_kg': 130, 'lenght_m': 1.95}
)
params={'color': 'green', 'weight_kg': 130, 'length_m': 1.95})
.given('there is an spider named Jack',
params={'color':'mostly black', 'weight_kg': 0.009, 'lenght_m': 0.05}
)
params={'color': 'mostly black', 'weight_kg': 0.009, 'length_m': 0.05})
.expects_to_receive('an alligator message')
.with_content({'name': 'John', 'document_name': 'sample_document.doc'})
.with_metadata({'contentType': 'application/json',
Expand All @@ -107,17 +105,17 @@ def test_definition_multiple_provider_states(self):
{
'name': 'there is an alligator named John',
'params': {
'color':'green',
'color': 'green',
'weight_kg': 130,
'lenght_m': 1.95
'length_m': 1.95
}
},
{
'name': 'there is an spider named Jack',
'params': {
'color':'mostly black',
'color': 'mostly black',
'weight_kg': 0.009,
'lenght_m': 0.05
'length_m': 0.05
}
}
]
Expand Down

0 comments on commit edd73bb

Please sign in to comment.