示例#1
0
def test_order_of_headers():
    data = load_acceptance_test(__file__)

    response = PactResponse(headers=[('Accept', 'hippos, alligators')])
    interaction = {'response': {'headers': data['expected']['headers']}}
    test_result = match(interaction, response)

    assert type(test_result) is Left
def test_different_value_at_key():
    data = load_acceptance_test(__file__)

    response = PactResponse(body={'alligator': {'name': 'Fred'}})
    interaction = {'response': {'body': data['expected']['body']}}
    test_result = match(interaction, response)

    assert type(test_result) is Left
def test_unexpected_number():
    data = load_acceptance_test(__file__)

    response = PactResponse(body={'alligator': {'feet': 4}})
    interaction = {'response': {'body': data['expected']['body']}}
    test_result = match(interaction, response)

    assert type(test_result) is Left
示例#4
0
def test_missing_index():
    data = load_acceptance_test(__file__)

    response = PactResponse(body={'alligator': {'favouriteColours': ['red']}})
    interaction = {'response': {'body': data['expected']['body']}}
    test_result = match(interaction, response)

    assert type(test_result) is Left
示例#5
0
def test_empty_headers():
    data = load_acceptance_test(__file__)

    response = PactResponse(headers=[])
    interaction = {'response': {'headers': data['expected']['headers']}}
    test_result = match(interaction, response)

    assert type(test_result) is Right
示例#6
0
def test_different_case():
    data = load_acceptance_test(__file__)

    response = PactResponse(body={'alligator': {'favouritecolour': 'red'}})
    interaction = {'response': {'body': data['expected']['body']}}
    test_result = match(interaction, response)

    assert type(test_result) is Left
def test_not_null():
    data = load_acceptance_test(__file__)

    response = PactResponse(body={'alligator': {'name': None}})
    interaction = {'response': {'body': data['expected']['body']}}
    test_result = match(interaction, response)

    assert type(test_result) is Left
def test_different_value_case():
    data = load_acceptance_test(__file__)

    response = PactResponse(headers=[('Accept', 'Alligators')])
    interaction = {'response': {'headers': data['expected']['headers']}}
    test_result = match(interaction, response)

    assert type(test_result) is Left
def test_matching_plain_text():
    data = load_acceptance_test(__file__)

    response = PactResponse(body='alligator named mary')
    interaction = {'response': {'body': data['expected']['body']}}
    test_result = match(interaction, response)

    assert type(test_result) is Right
示例#10
0
def test_whitespaces_after_comma():
    data = load_acceptance_test(__file__)

    response = PactResponse(headers=[('Accept', 'alligators, hippos')])
    interaction = {'response': {'headers': data['expected']['headers']}}
    test_result = match(interaction, response)

    assert type(test_result) is Right
示例#11
0
def test_headers_match():
    data = load_acceptance_test(__file__)

    response = PactResponse(headers=[('Accept',
                                      'alligators'), ('Content-Type',
                                                      'hippos')])
    interaction = {'response': {'headers': data['expected']['headers']}}
    test_result = match(interaction, response)

    assert type(test_result) is Right
示例#12
0
def test_array_in_different_order():
    data = load_acceptance_test(__file__)

    response = PactResponse(
        body={'alligator': {
            'favouriteColours': ['blue', 'red']
        }})
    interaction = {'response': {'body': data['expected']['body']}}
    test_result = match(interaction, response)

    assert type(test_result) is Left
示例#13
0
def test_different_values():
    data = load_acceptance_test(__file__)

    response = PactResponse(
        body={'alligator': {
            'favouriteNumbers': ['1', 2, '3']
        }})
    interaction = {'response': {'body': data['expected']['body']}}
    test_result = match(interaction, response)

    assert type(test_result) is Left
示例#14
0
def test_different_values():
    data = load_acceptance_test(__file__)

    response = PactResponse(body={
        'favouriteColours': ['red', 'blue'],
        'favouriteNumber': 7
    })
    interaction = {'response': {'body': data['expected']['body']}}
    test_result = match(interaction, response)

    assert type(test_result) is Right
def test_different_case():
    data = load_acceptance_test(__file__)

    response = PactResponse(
        body={'alligator': {
            'name': 'Mary',
            'phoneNumber': None
        }})
    interaction = {'response': {'body': data['expected']['body']}}
    test_result = match(interaction, response)

    assert type(test_result) is Right
示例#16
0
def test_different_status():
    data = load_acceptance_test(__file__)

    response = PactResponse(status=400)
    interaction = {'response': {'status': data['expected']['status']}}
    test_result = match(interaction, response).value

    assert test_result == {
        'status': FAILED,
        'message': data['comment'],
        'expected': data['expected']['status'],
        'actual': 400
    }
示例#17
0
def verify_state(interaction, pact_helper, test_instance):
    state = find_state(interaction, interaction['description'], test_instance)
    if type(state) is Right:
        state.value()
        output = _execute_request(pact_helper, interaction)
        if type(output) is Right:
            response_verification = match(interaction, output.value)
            output = _build_state_response(state, interaction['description'],
                                           response_verification)
            return output
        error(output.value)
        return output
    error(state.value)
    return state
示例#18
0
def test_matches():
    data = load_acceptance_test(__file__)

    response = PactResponse(body={
        'alligator': {
            'feet': 4,
            'name': 'Mary',
            'favouriteColours': [
                'red',
                'blue'
            ]
        }
    })
    interaction = {'response': {'body': data['expected']['body']}}
    test_result = match(interaction, response)

    assert type(test_result) is Right
示例#19
0
def test_nested_objects():
    data = load_acceptance_test(__file__)

    response = PactResponse(body={
        'object1': {
            'object2': {
                'object4': {
                    'object5': {
                        'name': 'Mary',
                        'friends': ['Fred', 'John'],
                        'gender': 'F'
                    },
                    'object6': {
                        'phoneNumber': 1234567890
                    }
                }
            },
            'color': 'red'
        }
    })
    interaction = {'response': {'body': data['expected']['body']}}
    test_result = match(interaction, response)

    assert type(test_result) is Right