Ejemplo n.º 1
0
def test_exception_running_multiple_servers_on_same_port():
    # Given
    with pytest.raises(MountebankPortInUseException):
        try:
            server1 = ExecutingMountebankServer(port=2526)
            server2 = ExecutingMountebankServer(port=2526)
        finally:
            try:
                server1.close()
                server2.close()
            except UnboundLocalError:
                pass
Ejemplo n.º 2
0
def test_allow_multiple_servers_on_different_ports():
    # Given
    try:
        server1 = ExecutingMountebankServer(port=2526)
        server2 = ExecutingMountebankServer(port=2527)
        imposter1 = Imposter(Stub(Predicate(path="/test"), Response(body="sausages")))
        imposter2 = Imposter(Stub(Predicate(path="/test"), Response(body="bacon")))

        with server1(imposter1), server2(imposter2):

            response1 = requests.get(f"{imposter1.url}/test")
            response2 = requests.get(f"{imposter2.url}/test")

            assert_that(response1, is_response().with_status_code(200).and_body("sausages"))
            assert_that(response2, is_response().with_status_code(200).and_body("bacon"))

    finally:
        server1.close()
        server2.close()
Ejemplo n.º 3
0
def test_server_can_be_restarted_on_same_port():
    server = ExecutingMountebankServer(port=2526)
    server.close()

    server = ExecutingMountebankServer(port=2526)
    server.close()