Skip to content

Commit 2ec367e

Browse files
authored
Improving tests for httpx. (#186)
1 parent 38e94b2 commit 2ec367e

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

tests/tests37/test_httpx.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import httpx
44
import pytest
55

6-
from mocket import async_mocketize
6+
from mocket import Mocketizer, async_mocketize
77
from mocket.mockhttp import Entry
88

99

1010
@pytest.mark.asyncio
1111
@async_mocketize
12-
async def test_httpx():
13-
url = "https://example.org/"
12+
async def test_httpx_decorator():
13+
url = "https://bar.foo/"
1414
data = {"message": "Hello"}
1515

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

2626
assert response.json() == data
27+
28+
29+
@pytest.fixture
30+
def httpx_client() -> httpx.AsyncClient:
31+
with Mocketizer():
32+
yield httpx.AsyncClient()
33+
34+
35+
@pytest.mark.asyncio
36+
async def test_httpx_fixture(httpx_client):
37+
url = "https://foo.bar/"
38+
data = {"message": "Hello"}
39+
40+
Entry.single_register(
41+
Entry.GET,
42+
url,
43+
body=json.dumps(data),
44+
headers={"content-type": "application/json"},
45+
)
46+
47+
async with httpx_client as client:
48+
response = await client.get(url)
49+
50+
assert response.json() == data

0 commit comments

Comments
 (0)