def test_nested_matchers(): matcher = EachLike({"username": Term("[a-z]+", "user"), "id": Like(123)}) assert matcher.ruby_protocol() == { "json_class": "Pact::ArrayLike", "contents": { "username": { "json_class": "Pact::Term", "data": { "matcher": {"json_class": "Regexp", "s": "[a-z]+", "o": 0}, "generate": "user", }, }, "id": {"json_class": "Pact::SomethingLike", "contents": 123}, }, "min": 1, }
def test_nested_matchers(): matcher = EachLike({'username': Term('[a-z]+', 'user'), 'id': Like(123)}) assert matcher.ruby_protocol() == { 'json_class': 'Pact::ArrayLike', 'contents': { 'username': { 'json_class': 'Pact::Term', 'data': { 'matcher': { 'json_class': 'Regexp', 's': '[a-z]+', 'o': 0}, 'generate': 'user'}}, 'id': { 'json_class': 'Pact::SomethingLike', 'contents': 123}}, 'min': 1 }
def test_eachlike(): pact = (Consumer("consumer").has_pact_with( Provider("provider"), version="2.0.0").given("the condition exists").upon_receiving( "a request").with_request("POST", "/path", body=EachLike(1)).will_respond_with( 200, body={"results": EachLike(1)})) result = pact.construct_pact(pact._interactions[0]) assert result == { "consumer": { "name": "consumer" }, "provider": { "name": "provider" }, "interactions": [{ "description": "a request", "providerState": "the condition exists", "request": dict( method="POST", path="/path", body=[1], matchingRules={"$.body": { "match": "type", "min": 1 }}, ), "response": dict( status=200, body={"results": [1]}, matchingRules={"$.body.results": { "match": "type", "min": 1 }}, ), }], "metadata": dict(pactSpecification=dict(version="2.0.0")), }
def test_eachlike(): pact = (Consumer('consumer').has_pact_with( Provider('provider'), version='2.0.0').given("the condition exists").upon_receiving( "a request").with_request("POST", "/path", body=EachLike(1)).will_respond_with( 200, body={"results": EachLike(1)})) result = pact.construct_pact(pact._interactions[0]) assert result == { 'consumer': { 'name': 'consumer' }, 'provider': { 'name': 'provider' }, 'interactions': [{ 'description': 'a request', 'providerState': 'the condition exists', 'request': dict(method='POST', path='/path', body=[1], matchingRules={'$.body': { 'match': 'type', 'min': 1 }}), 'response': dict(status=200, body={'results': [1]}, matchingRules={'$.body.results': { 'match': 'type', 'min': 1 }}), }], 'metadata': dict(pactSpecification=dict(version='2.0.0')) }
def test_minimum(): assert EachLike(1, minimum=2).ruby_protocol() == {'json_class': 'Pact::ArrayLike', 'contents': 1, 'min': 2}
def test_default_options(): assert EachLike(1).ruby_protocol() == {'json_class': 'Pact::ArrayLike', 'contents': 1, 'min': 1}
def test_minimum_assertion_error(): with pytest.raises(AssertionError) as e: EachLike(1, minimum=0) assert str(e.value) == 'Minimum must be greater than or equal to 1'
def test_minimum(): assert EachLike(1, minimum=2).ruby_protocol() == { "json_class": "Pact::ArrayLike", "contents": 1, "min": 2, }
def test_default_options(): assert EachLike(1).ruby_protocol() == {"json_class": "Pact::ArrayLike", "contents": 1, "min": 1}