示例#1
0
def test_multiple_pacts_dont_break_during_teardown():
    # ensure teardown is only done on when all pacts __exit__
    pact = Pact(Consumer('Consumer'), Provider('Provider'))
    p1 = pact.given('given').upon_receiving('when').with_request('GET', '/path').will_respond_with(201)
    p2 = pact.given('given2').upon_receiving('when2').with_request('GET', '/path2').will_respond_with(201)
    with p1, p2:
        requests.get(p1.uri + '/path')
示例#2
0
 def test_definition_v3_requires_new_providerStates(self):
     target = Pact(self.consumer, self.provider, version='3.0.0')
     target.given('I am creating a new pact using the Pact class')
     self.assertEqual(target._interactions[0]['providerStates'], [{
         'name': 'I am creating a new pact using the Pact class',
         'params': {}
     }])
示例#3
0
def test_multiple_pacts_dont_break_during_teardown():
    # ensure teardown is only done on when all pacts __exit__
    pact = Pact(Consumer("Consumer"), Provider("Provider"))
    p1 = (pact.given("given").upon_receiving("when").with_request(
        "GET", "/path").will_respond_with(201))
    p2 = (pact.given("given2").upon_receiving("when2").with_request(
        "GET", "/path2").will_respond_with(201))
    with p1, p2:
        requests.get(p1.uri + "/path")
示例#4
0
 def test_definition_v3_requires_new_providerStates(self):
     target = Pact(self.consumer, self.provider, version="3.0.0")
     target.given("I am creating a new pact using the Pact class")
     self.assertEqual(
         target._interactions[0]["providerStates"],
         [{
             "name": "I am creating a new pact using the Pact class",
             "params": {}
         }],
     )
示例#5
0
class PactSetupTestCase(PactTestCase):
    def setUp(self):
        super(PactSetupTestCase, self).setUp()
        self.addCleanup(patch.stopall)
        self.target = Pact(self.consumer, self.provider)
        (self.target.given("I am creating a new pact using the Pact class").
         upon_receiving("a specific request to the server").with_request(
             "GET", "/path").will_respond_with(200, body="success"))

        self.delete_call = call("delete",
                                "http://localhost:1234/interactions",
                                headers={"X-Pact-Mock-Service": "true"})

        self.put_interactions_call = call(
            "put",
            "http://localhost:1234/interactions",
            data=None,
            headers={"X-Pact-Mock-Service": "true"},
            json={
                "interactions": [{
                    "response": {
                        "status": 200,
                        "body": "success"
                    },
                    "request": {
                        "path": "/path",
                        "method": "GET"
                    },
                    "description":
                    "a specific request to the server",
                    "providerState":
                    "I am creating a new pact using the Pact class",
                }]
            },
        )
示例#6
0
class PactSetupTestCase(PactTestCase):
    def setUp(self):
        super(PactSetupTestCase, self).setUp()
        self.addCleanup(patch.stopall)
        self.target = Pact(self.consumer, self.provider)
        (self.target.given('I am creating a new pact using the Pact class').
         upon_receiving('a specific request to the server').with_request(
             'GET', '/path').will_respond_with(200, body='success'))

        self.delete_call = call('delete',
                                'http://localhost:1234/interactions',
                                headers={'X-Pact-Mock-Service': 'true'})

        self.put_interactions_call = call(
            'put',
            'http://localhost:1234/interactions',
            data=None,
            headers={'X-Pact-Mock-Service': 'true'},
            json={
                'interactions': [{
                    'response': {
                        'status': 200,
                        'body': 'success'
                    },
                    'request': {
                        'path': '/path',
                        'method': 'GET'
                    },
                    'description':
                    'a specific request to the server',
                    'providerState':
                    'I am creating a new pact using the Pact class'
                }]
            })
示例#7
0
    def test_definition_all_options_v3(self):
        target = Pact(self.consumer, self.provider, version="3.0.0")
        (target.given([{
            "name": "I am creating a new pact using the Pact class",
            "params": {}
        }]).upon_receiving("a specific request to the server").with_request(
            "GET",
            "/path",
            body={
                "key": "value"
            },
            headers={
                "Accept": "application/json"
            },
            query={
                "search": ["test"]
            },
        ).will_respond_with(200,
                            body="success",
                            headers={"Content-Type": "application/json"}))

        self.assertEqual(
            target._interactions[0]["providerStates"],
            [{
                "name": "I am creating a new pact using the Pact class",
                "params": {}
            }],
        )

        self.assertEqual(target._interactions[0]["description"],
                         "a specific request to the server")

        self.assertEqual(
            target._interactions[0]["request"],
            {
                "path": "/path",
                "method": "GET",
                "body": {
                    "key": "value"
                },
                "headers": {
                    "Accept": "application/json"
                },
                "query": {
                    "search": ["test"]
                },
            },
        )
        self.assertEqual(
            target._interactions[0]["response"],
            {
                "status": 200,
                "body": "success",
                "headers": {
                    "Content-Type": "application/json"
                }
            },
        )
示例#8
0
    def test_definition_all_options_v3(self):
        target = Pact(self.consumer, self.provider, version='3.0.0')
        (target.given([{
            'name': 'I am creating a new pact using the Pact class',
            'params': {}
        }]).upon_receiving('a specific request to the server').with_request(
            'GET',
            '/path',
            body={
                'key': 'value'
            },
            headers={
                'Accept': 'application/json'
            },
            query={
                'search': ['test']
            }).will_respond_with(200,
                                 body='success',
                                 headers={'Content-Type': 'application/json'}))

        self.assertEqual(target._interactions[0]['providerStates'], [{
            'name': 'I am creating a new pact using the Pact class',
            'params': {}
        }])

        self.assertEqual(target._interactions[0]['description'],
                         'a specific request to the server')

        self.assertEqual(
            target._interactions[0]['request'], {
                'path': '/path',
                'method': 'GET',
                'body': {
                    'key': 'value'
                },
                'headers': {
                    'Accept': 'application/json'
                },
                'query': {
                    'search': ['test']
                }
            })
        self.assertEqual(
            target._interactions[0]['response'], {
                'status': 200,
                'body': 'success',
                'headers': {
                    'Content-Type': 'application/json'
                }
            })
示例#9
0
    def test_definition_multiple_interactions(self):
        target = Pact(self.consumer, self.provider)
        (target.given("I am creating a new pact using the Pact class").
         upon_receiving("a specific request to the server").with_request(
             "GET", "/foo").will_respond_with(200, body="success").given(
                 "I am creating another new pact using the Pact class").
         upon_receiving("a different request to the server").with_request(
             "GET", "/bar").will_respond_with(200, body="success"))

        self.assertEqual(len(target._interactions), 2)

        self.assertEqual(
            target._interactions[1]["providerState"],
            "I am creating a new pact using the Pact class",
        )
        self.assertEqual(
            target._interactions[0]["providerState"],
            "I am creating another new pact using the Pact class",
        )

        self.assertEqual(target._interactions[1]["description"],
                         "a specific request to the server")
        self.assertEqual(target._interactions[0]["description"],
                         "a different request to the server")

        self.assertEqual(target._interactions[1]["request"], {
            "path": "/foo",
            "method": "GET"
        })
        self.assertEqual(target._interactions[0]["request"], {
            "path": "/bar",
            "method": "GET"
        })

        self.assertEqual(target._interactions[1]["response"], {
            "status": 200,
            "body": "success"
        })
        self.assertEqual(target._interactions[0]["response"], {
            "status": 200,
            "body": "success"
        })
示例#10
0
    def test_definition_sparse(self):
        target = Pact(self.consumer, self.provider)
        (target.given('I am creating a new pact using the Pact class').
         upon_receiving('a specific request to the server').with_request(
             'GET', '/path').will_respond_with(200, body='success'))

        self.assertEqual(len(target._interactions), 1)

        self.assertEqual(target._interactions[0]['providerState'],
                         'I am creating a new pact using the Pact class')

        self.assertEqual(target._interactions[0]['description'],
                         'a specific request to the server')

        self.assertEqual(target._interactions[0]['request'], {
            'path': '/path',
            'method': 'GET'
        })
        self.assertEqual(target._interactions[0]['response'], {
            'status': 200,
            'body': 'success'
        })