示例#1
0
    def test_nested(self):
        (pact
         .given('a list of users exists')
         .upon_receiving('a query of all users')
         .with_request('get', '/users/', query={'limit': Term('\d+', '5')})
         .will_respond_with(200, body={'results': EachLike({
            'username': Term('\w+', 'bob'),
            'id': SomethingLike(123),
            'groups': EachLike(123),
            'meta': SomethingLike({
                'name': Term('.+', 'sample'),
                'value': Term('.+', 'data')
            })
         }, minimum=2)}))

        with pact:
            results = requests.get(
                'http://localhost:1234/users/?limit=4')

        self.assertEqual(results.json(), {
            'results': [
                {'username': '******', 'id': 123, 'groups': [123],
                 'meta': {'name': 'sample', 'value': 'data'}},
                {'username': '******', 'id': 123, 'groups': [123],
                 'meta': {'name': 'sample', 'value': 'data'}}]})
示例#2
0
def test_get_account(pact):
    expected = {
        'name': Like('A'),
        'account_number': 'XQR9MUP',
        'amount': Like(4000)
    }
    # Usage of Like:
    # Like(123)  # Matches if the value is an integer
    # Like('hello world')  # Matches if the value is a string
    # Like(3.14)  # Matches if the value is a float

    (pact.given('Account A exists and has balance and activity fields').
     upon_receiving('a request for Account A').with_request(
         'get', '/accounts/num/XQR9MUP').will_respond_with(200, body=expected))

    (pact.given('Active accounts exists').upon_receiving(
        'Request for Active accounts, return list').with_request(
            'get',
            '/accounts/active').will_respond_with(200,
                                                  body=EachLike(expected)))

    # pact.setup()

    with pact:
        acc = getAccount('XQR9MUP')
        activeAccs = getActiveAccounts()
        # print(acc)
        assert acc['name'] == 'A'
        assert activeAccs[0]['name'] == 'A'
示例#3
0
def test_get_addresses(pact):
    expected = EachLike({
        'ID': Like('py'),
        'ZipCode': Like(''),
        'Street': Like('')
    })
    headers = {'Content-Type': 'application/json'}
    (pact.given('test').upon_receiving('a request for addresses').with_request(
        'get', '/').will_respond_with(200, headers=headers, body=expected))

    with pact:
        result = get_addresses(pact.uri + '/')
        assert result == get_generated_values(expected)

    pact.verify()
示例#4
0
     1111,
     'interactions': [{
         'GIVEN':
         'Provided we have the correct project_id and data to edit',
         'UPON_RECEIVING': 'the correct paper URL should be provided',
         'REQUEST': {
             'method': 'get',
             'path': '/'
         },
         'RESPONSE': {
             'status':
             200,
             'body':
             EachLike({
                 "id": Like(1),
                 "name": Like("Pants"),
                 "quantity": Like(15)
             })
         }
     }]
 },
 'Shipping': {
     'port':
     2222,
     'interactions': [{
         'GIVEN':
         'Provided we have the correct project_id and data to edit',
         'UPON_RECEIVING': 'the correct paper URL should be provided',
         'REQUEST': {
             'method': 'get',
             'path': '/'