コード例 #1
0
def test_server_default_options():
    # Given
    with patch("subprocess.Popen") as popen, patch("requests.get"):

        # When
        ExecutingMountebankServer(port=1234)

        # Then
        assert_that(
            popen,
            has_call(
                with_args(
                    contains_exactly(
                        contains_string("mb"),
                        "start",
                        "--port",
                        "1234",
                        "--debug",
                        "--allowInjection",
                        "--localOnly",
                        "--datadir",
                        ".mbdb",
                    )
                )
            ),
        )
コード例 #2
0
ファイル: test_server.py プロジェクト: ozonru/mbtest
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
コード例 #3
0
def test_server_non_default_options():
    # Given
    with patch("subprocess.Popen") as popen, patch("requests.get"):

        # When
        ExecutingMountebankServer(
            executable="somepath/mb",
            port=3456,
            debug=False,
            allow_injection=False,
            local_only=False,
            data_dir=None,
        )

        # Then
        popen.assert_called_with(["somepath/mb", "start", "--port", "3456"])
コード例 #4
0
ファイル: test_server.py プロジェクト: ozonru/mbtest
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()
コード例 #5
0
def test_server_non_default_options():
    # Given
    with patch("subprocess.Popen") as popen, patch("requests.get"):

        # When
        ExecutingMountebankServer(
            executable=Path("somepath/mb"),
            port=3456,
            debug=False,
            allow_injection=False,
            local_only=False,
            data_dir=None,
        )

        # Then
        assert_that(
            popen,
            has_call(with_args(contains_exactly(contains_string("mb"), "start", "--port", "3456"))),
        )
コード例 #6
0
def test_server_default_options():
    # Given
    with patch("subprocess.Popen") as popen, patch("requests.get"):

        # When
        ExecutingMountebankServer(port=1234)

        # Then
        popen.assert_called_with([
            DEFAULT_MB_EXECUTABLE,
            "start",
            "--port",
            "1234",
            "--debug",
            "--allowInjection",
            "--localOnly",
            "--datadir",
            ".mbdb",
        ])
コード例 #7
0
ファイル: test_server.py プロジェクト: ozonru/mbtest
def test_server_can_be_restarted_on_same_port():
    server = ExecutingMountebankServer(port=2526)
    server.close()

    server = ExecutingMountebankServer(port=2526)
    server.close()
コード例 #8
0
ファイル: test_server.py プロジェクト: ozonru/mbtest
def test_executable_not_mb():
    with pytest.raises(MountebankTimeoutError):
        ExecutingMountebankServer(executable="ls", port=2526, timeout=1)
コード例 #9
0
ファイル: test_server.py プロジェクト: ozonru/mbtest
def test_non_executable():
    with pytest.raises(OSError):
        ExecutingMountebankServer(executable=str(Path(".") / "README.md"), port=2526)
コード例 #10
0
ファイル: test_server.py プロジェクト: ozonru/mbtest
def test_nonexistent_executable():
    with pytest.raises(OSError):
        ExecutingMountebankServer(executable=str(Path(".") / "no" / "such" / "path"), port=2526)