Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions tests/tests37/test_httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import httpx
import pytest

from mocket import async_mocketize
from mocket import Mocketizer, async_mocketize
from mocket.mockhttp import Entry


@pytest.mark.asyncio
@async_mocketize
async def test_httpx():
url = "https://example.org/"
async def test_httpx_decorator():
url = "https://bar.foo/"
data = {"message": "Hello"}

Entry.single_register(
Expand All @@ -24,3 +24,27 @@ async def test_httpx():
response = await client.get(url)

assert response.json() == data


@pytest.fixture
def httpx_client() -> httpx.AsyncClient:
with Mocketizer():
yield httpx.AsyncClient()


@pytest.mark.asyncio
async def test_httpx_fixture(httpx_client):
url = "https://foo.bar/"
data = {"message": "Hello"}

Entry.single_register(
Entry.GET,
url,
body=json.dumps(data),
headers={"content-type": "application/json"},
)

async with httpx_client as client:
response = await client.get(url)

assert response.json() == data