Ejemplo n.º 1
0
def test_detect_mismatch_request_manual_mode():
    with tempfile.TemporaryDirectory() as d:
        pact = (
            Consumer("C")
            .has_pact_with(Provider("P"), pact_dir=d, file_write_mode="merge")
            .given("g")
            .upon_receiving("r")
            .with_request("get", "/foo")
            .will_respond_with(200)
        )
        with pact:
            requests.get(pact.uri + "/foo")

        # force a failure by specifying the same given/providerState but different request
        pact = (
            Consumer("C")
            .has_pact_with(Provider("P"), pact_dir=d, file_write_mode="merge")
            .given("g")
            .upon_receiving("r")
            .with_request("get", "/bar")
            .will_respond_with(200)
        )
        with pytest.raises(PactInteractionMismatch):
            with pact:
                requests.get(pact.uri + "/bar")
Ejemplo n.º 2
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')
Ejemplo n.º 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")
Ejemplo n.º 4
0
 def f(file_write_mode=None, version='2.0.0'):
     monkeypatch.setattr(Pact, "allocate_port", Mock())
     monkeypatch.setattr(os, "remove", Mock())
     monkeypatch.setattr(os.path, "exists", Mock(return_value=True))
     log_dir = "/tmp/a"
     pact_dir = "/tmp/pact"
     return Pact(Consumer("CONSUMER"),
                 Provider("PROVIDER"),
                 log_dir=log_dir,
                 pact_dir=pact_dir,
                 version=version,
                 file_write_mode=file_write_mode)
Ejemplo n.º 5
0
def test_detect_mismatch_request_retained_relationship():
    with tempfile.TemporaryDirectory() as d:
        pact = Consumer('C').has_pact_with(Provider('P'), pact_dir=d)
        with pact.given("g").upon_receiving("r").with_request(
                "get", "/foo").will_respond_with(200):
            requests.get(pact.uri + '/foo')

        # force a failure by specifying the same given/providerState but different request
        with pytest.raises(PactInteractionMismatch):
            with pact.given("g").upon_receiving("r").with_request(
                    "get", "/bar").will_respond_with(200):
                requests.get(pact.uri + '/bar')
Ejemplo n.º 6
0
def test_pacts_written():
    with tempfile.TemporaryDirectory() as d:
        pact = Consumer('C').has_pact_with(Provider('P'), pact_dir=d)
        with pact.given("g").upon_receiving("r").with_request(
                "get", "/foo").will_respond_with(200):
            requests.get(pact.uri + '/foo')

        # force a failure
        with pytest.raises(AssertionError):
            with pact.given("g").upon_receiving("r2").with_request(
                    "get", "/bar").will_respond_with(200):
                requests.get(pact.uri + '/foo')

        # make sure mocking still works
        with pact.given("g").upon_receiving("r2").with_request(
                "get", "/bar").will_respond_with(200):
            requests.get(pact.uri + '/bar')

        # ensure two pacts written
        with open(pact.pact_json_filename) as f:
            content = json.load(f)
            assert len(content['interactions']) == 2
Ejemplo n.º 7
0
 def setUp(self):
     self.consumer = Consumer('TestConsumer')
     self.provider = Provider('TestProvider')
Ejemplo n.º 8
0
 def setUp(self):
     self.consumer = Consumer("TestConsumer")
     self.provider = Provider("TestProvider")
Ejemplo n.º 9
0
 def test_init(self):
     result = Provider('TestProvider')
     self.assertIsInstance(result, Provider)
     self.assertEqual(result.name, 'TestProvider')