コード例 #1
0
def test_access_logs():
    with zebr0.TestServer() as server:
        requests.get("http://127.0.0.1:8000/lorem")
        requests.get("http://127.0.0.1:8000/lorem")
        requests.get("http://127.0.0.1:8000/dolor/sit")

        assert server.access_logs == ["/lorem", "/lorem", "/dolor/sit"]
コード例 #2
0
def test_setting_the_data_afterwards():
    with zebr0.TestServer() as server:
        server.data = {"key": "value"}

        response = requests.get("http://127.0.0.1:8000/key")
        assert response.ok
        assert response.text == "value"
コード例 #3
0
def test_basic_usage():
    server = zebr0.TestServer({"key": "value"})
    server.start()

    response = requests.get("http://127.0.0.1:8000/key")
    assert response.ok
    assert response.text == "value"

    server.stop()
コード例 #4
0
def test_multiple_keys():
    with zebr0.TestServer({
            "lorem": "ipsum",
            "dolor/sit": "amet",
            "consectetur/adipiscing": "elit"
    }):
        assert requests.get("http://127.0.0.1:8000/lorem").text == "ipsum"
        assert requests.get("http://127.0.0.1:8000/dolor/sit").text == "amet"
        assert requests.get(
            "http://127.0.0.1:8000/consectetur/adipiscing").text == "elit"
コード例 #5
0
def test_changing_the_data_while_running():
    with zebr0.TestServer({"key": "value"}) as server:
        response = requests.get("http://127.0.0.1:8000/key")
        assert response.ok
        assert response.text == "value"

        server.data = {"key": "new value"}

        response = requests.get("http://127.0.0.1:8000/key")
        assert response.ok
        assert response.text == "new value"
コード例 #6
0
ファイル: test_cli.py プロジェクト: zebr0/zebr0.py
def server():
    with zebr0.TestServer() as server:
        yield server
コード例 #7
0
def test_missing_key():
    with zebr0.TestServer():
        response = requests.get("http://127.0.0.1:8000/key")
        assert response.status_code == 404
コード例 #8
0
def test_another_address_and_port():
    with zebr0.TestServer({"key": "value"}, address="0.0.0.0", port=8001):
        response = requests.get("http://0.0.0.0:8001/key")
        assert response.ok
        assert response.text == "value"
コード例 #9
0
def test_context_manager_usage():
    with zebr0.TestServer({"key": "value"}):
        response = requests.get("http://127.0.0.1:8000/key")
        assert response.ok
        assert response.text == "value"