File tree Expand file tree Collapse file tree 1 file changed +27
-3
lines changed
Expand file tree Collapse file tree 1 file changed +27
-3
lines changed Original file line number Diff line number Diff line change 33import httpx
44import pytest
55
6- from mocket import async_mocketize
6+ from mocket import Mocketizer , async_mocketize
77from 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
You can’t perform that action at this time.
0 commit comments