def test_ResponseVerifier_checks_for_missing_headers(mock_pact): interaction = {"headers": {"X-Custom-Header": "value1"}} mock_result = Mock() r = ResponseVerifier(mock_pact("2.0.0"), interaction, mock_result) assert r.verify(FakeResponse({"headers": {}})) is False mock_result.fail.assert_called_with( "Response missing header 'X-Custom-Header'")
def test_ResponseVerifier_reports_correct_message_when_key_missing( mock_pact, interaction): mock_result = Mock() r = ResponseVerifier(mock_pact('2.0.0'), interaction, mock_result) r.verify(FakeResponse({"body": {}})) mock_result.fail.assert_called_with("Response element 'key1' is missing", ['body'])
def test_response_verifier(fake_interaction, mock_pact): fake_interaction['response']['body'] = dict(a='b', c=1) # note: no rule for matching of c fake_interaction['response']['matchingRules'] = { '$.body.a': dict(match='type'), } fake_interaction['response']['headers'] = {'Content-Type': 'json-yeah'} r = ResponseVerifier(mock_pact('2.0.0'), fake_interaction['response'], Mock()) r.verify(Mock(status_code=200, headers={'Content-Type': 'json-yeah'}, json=Mock(return_value=dict(a='b', c='c'))))
def test_response_verifier(fake_interaction, mock_pact): fake_interaction["response"]["body"] = dict( a="b", c=1) # note: no rule for matching of c fake_interaction["response"]["matchingRules"] = { "$.body.a": dict(match="type") } fake_interaction["response"]["headers"] = {"Content-Type": "json-yeah"} r = ResponseVerifier(mock_pact("2.0.0"), fake_interaction["response"], Mock()) r.verify( Mock( status_code=200, headers={"Content-Type": "json-yeah"}, json=Mock(return_value=dict(a="b", c="c")), ))
def test_bug85_exact_alongside_type_match_fails(mock_pact): # odd bug where an exact match inside a container with a typed match rule # would not invoke fail() mock_result = Mock() r = ResponseVerifier( mock_pact("2.0.0"), { "body": { "id": "spam" }, "matchingRules": { "$.body.token": { "match": "type" } } }, mock_result, ) r.verify(FakeResponse({"body": {"id": "ham"}})) mock_result.fail.assert_called_with( "Element mismatch 'ham' is not expected 'spam'", ["body", "id"])