예제 #1
0
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'")
예제 #2
0
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'])
예제 #3
0
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'))))
예제 #4
0
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")),
        ))
예제 #5
0
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"])