def test_like_v2():
    pact = Consumer('consumer').has_pact_with(Provider('provider'),
                                              version='2.0.0')

    pact.given("the condition exists").upon_receiving("a request") \
        .with_request("GET", "/path", query=Like("fields=first,second")).will_respond_with(200, body='ok')

    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='GET',
                 path='/path',
                 query='fields=first,second',
                 matchingRules={'$.query': {
                     'match': 'type'
                 }}),
            'response':
            dict(status=200, body='ok'),
        }],
        'metadata':
        dict(pactSpecification=dict(version='2.0.0'))
    }
Beispiel #2
0
def test_like_v2():
    pact = Consumer("consumer").has_pact_with(Provider("provider"), version="2.0.0")

    pact.given("the condition exists").upon_receiving("a request").with_request(
        "GET", "/path", query=Like("fields=first,second")
    ).will_respond_with(200, body="ok")

    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="GET",
                    path="/path",
                    query="fields=first,second",
                    matchingRules={"$.query": {"match": "type"}},
                ),
                "response": dict(status=200, body="ok"),
            }
        ],
        "metadata": dict(pactSpecification=dict(version="2.0.0")),
    }
Beispiel #3
0
def test_v3(query_field):
    pact = Consumer("consumer").has_pact_with(Provider("provider"),
                                              version="3.0.0")
    pact.given([{
        "name": "the condition exists",
        "params": {}
    }]).upon_receiving("a request").with_request(
        "GET", "/path",
        query=dict(fields=query_field)).will_respond_with(200, body="ok")

    result = pact.construct_pact(pact._interactions[0])
    assert result == {
        "consumer": {
            "name": "consumer"
        },
        "provider": {
            "name": "provider"
        },
        "interactions": [{
            "description":
            "a request",
            "providerStates": [{
                "name": "the condition exists",
                "params": {}
            }],
            "request":
            dict(method="GET",
                 path="/path",
                 query=dict(fields=["first,second"])),
            "response":
            dict(status=200, body="ok"),
        }],
        "metadata":
        dict(pactSpecification=dict(version="3.0.0")),
    }
def test_v3(query_field):
    pact = Consumer('consumer').has_pact_with(Provider('provider'),
                                              version='3.0.0')
    pact.given([{'name': "the condition exists", 'params': {}}]).upon_receiving("a request") \
        .with_request("GET", "/path", query=dict(fields=query_field)).will_respond_with(200, body='ok')

    result = pact.construct_pact(pact._interactions[0])
    assert result == {
        'consumer': {
            'name': 'consumer'
        },
        'provider': {
            'name': 'provider'
        },
        'interactions': [{
            'description':
            'a request',
            'providerStates': [{
                'name': 'the condition exists',
                'params': {}
            }],
            'request':
            dict(method='GET',
                 path='/path',
                 query=dict(fields=['first,second'])),
            'response':
            dict(status=200, body='ok'),
        }],
        'metadata':
        dict(pactSpecification=dict(version='3.0.0'))
    }
Beispiel #5
0
def test_full_payload_v2():
    pact = Consumer("consumer").has_pact_with(Provider("provider"), version="2.0.0")
    (
        pact.given("UserA exists and is not an administrator")
        .upon_receiving("a request for UserA")
        .with_request(
            "get", "/users/UserA", headers={"Accept": "application/json"}, query="term=test"
        )
        .will_respond_with(
            200, body={"username": "******"}, headers={"Content-Type": "application/json"}
        )
    )
    result = pact.construct_pact(pact._interactions[0])
    assert result == {
        "consumer": {"name": "consumer"},
        "provider": {"name": "provider"},
        "interactions": [
            {
                "description": "a request for UserA",
                "providerState": "UserA exists and is not an administrator",
                "request": dict(
                    method="get",
                    path="/users/UserA",
                    headers={"Accept": "application/json"},
                    query="term=test",
                ),
                "response": dict(
                    status=200,
                    body={"username": "******"},
                    headers={"Content-Type": "application/json"},
                ),
            }
        ],
        "metadata": dict(pactSpecification=dict(version="2.0.0")),
    }
Beispiel #6
0
def test_v3():
    pact = Consumer("consumer").has_pact_with(Provider("provider"),
                                              version="3.0.0")
    pact.given([
        dict(name="the condition exists", params={}),
        dict(name="the user exists", params=dict(username="******")),
    ]).upon_receiving("a request").with_request(
        "GET", "/path").will_respond_with(200, body="ok")

    result = pact.construct_pact(pact._interactions[0])
    assert result == {
        "consumer": {
            "name": "consumer"
        },
        "provider": {
            "name": "provider"
        },
        "interactions": [{
            "description":
            "a request",
            "providerStates": [
                {
                    "name": "the condition exists",
                    "params": {}
                },
                {
                    "name": "the user exists",
                    "params": {
                        "username": "******"
                    }
                },
            ],
            "request":
            dict(method="GET", path="/path"),
            "response":
            dict(status=200, body="ok"),
        }],
        "metadata":
        dict(pactSpecification=dict(version="3.0.0")),
    }
Beispiel #7
0
def test_null(version):
    pact = Consumer("consumer").has_pact_with(Provider("provider"),
                                              version=version)
    pact.given(None).upon_receiving("a request").with_request(
        "GET", "/path").will_respond_with(200, body="ok")

    result = pact.construct_pact(pact._interactions[0])
    assert result == {
        "consumer": {
            "name": "consumer"
        },
        "provider": {
            "name": "provider"
        },
        "interactions": [{
            "description": "a request",
            "request": dict(method="GET", path="/path"),
            "response": dict(status=200, body="ok"),
        }],
        "metadata":
        dict(pactSpecification=dict(version=version)),
    }
Beispiel #8
0
def test_null(version):
    pact = Consumer('consumer').has_pact_with(Provider('provider'),
                                              version=version)
    pact.given(None).upon_receiving("a request").with_request("GET", "/path") \
        .will_respond_with(200, body='ok')

    result = pact.construct_pact(pact._interactions[0])
    assert result == {
        'consumer': {
            'name': 'consumer'
        },
        'provider': {
            'name': 'provider'
        },
        'interactions': [{
            'description': 'a request',
            'request': dict(method='GET', path='/path'),
            'response': dict(status=200, body='ok'),
        }],
        'metadata':
        dict(pactSpecification=dict(version=version))
    }
Beispiel #9
0
def test_v3():
    pact = Consumer('consumer').has_pact_with(Provider('provider'),
                                              version='3.0.0')
    pact.given([
        dict(name="the condition exists", params={}),
        dict(name="the user exists", params=dict(username='******')),
    ]).upon_receiving("a request").with_request(
        "GET", "/path").will_respond_with(200, body='ok')

    result = pact.construct_pact(pact._interactions[0])
    assert result == {
        'consumer': {
            'name': 'consumer'
        },
        'provider': {
            'name': 'provider'
        },
        'interactions': [{
            'description':
            'a request',
            'providerStates': [{
                'name': 'the condition exists',
                'params': {}
            }, {
                'name': 'the user exists',
                'params': {
                    'username': '******'
                }
            }],
            'request':
            dict(method='GET', path='/path'),
            'response':
            dict(status=200, body='ok'),
        }],
        'metadata':
        dict(pactSpecification=dict(version='3.0.0'))
    }