How to use the respx.post function in respx

To help you get started, we’ve selected a few respx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lundberg / respx / tests / test_mock.py View on Github external
async def test_nested_global_contextmanager(client):
    with respx.mock:
        get_request = respx.get("https://foo/bar/", status_code=202)

        with respx.mock:
            post_request = respx.post("https://foo/bar/", status_code=201)

            response = await client.get("https://foo/bar/")
            assert get_request.called is True
            assert response.status_code == 202
            assert respx.stats.call_count == 1

            response = await client.post("https://foo/bar/")
            assert post_request.called is True
            assert response.status_code == 201
            assert respx.stats.call_count == 2
github lundberg / respx / tests / test_api.py View on Github external
async def test_http_methods(client):
    async with respx.mock:
        url = "https://foo.bar/"
        m = respx.get(url, status_code=404)
        respx.post(url, status_code=201)
        respx.put(url, status_code=202)
        respx.patch(url, status_code=500)
        respx.delete(url, status_code=204)
        respx.head(url, status_code=405)
        respx.options(url, status_code=501)

        response = httpx.get(url)
        assert response.status_code == 404
        response = await client.get(url)
        assert response.status_code == 404

        response = httpx.post(url)
        assert response.status_code == 201
        response = await client.post(url)
        assert response.status_code == 201
github msys2 / msys2-web / tests / test_main.py View on Github external
def test_webhook_push(client, monkeypatch):
    monkeypatch.setenv("GITHUB_WEBHOOK_SECRET", "foobar")
    monkeypatch.setenv("APPVEYOR_ACCOUNT", "account")
    monkeypatch.setenv("APPVEYOR_PROJECT", "project")
    monkeypatch.setenv("APPVEYOR_TOKEN", "token")

    with respx.mock:
        request = respx.post(
            "https://ci.appveyor.com/api/builds",
            status_code=201,
            content={
                "buildId": 1234
            })

        r = client.post("/webhook", headers={
            "X-Hub-Signature": "sha1=241ebb961521e58a8b2d5d1436863df772ffd531",
            "X-GitHub-Event": "push",
        })
        assert request.called
        r.raise_for_status()
        assert "msg" in r.json()
        assert "1234" in r.json()["msg"]