@@ -20,97 +20,92 @@ async def amake_request(self, method, url, content=None, headers=None):
20
20
return response .status , response_content , response .headers
21
21
22
22
23
- def _pook_url (URL ):
24
- return pook .head (URL ).reply (200 ).mock
25
-
26
-
27
- @pytest .fixture
28
- def URL (httpbin ):
29
- return f"{ httpbin .url } /status/404"
23
+ def _pook_url (url ):
24
+ return pook .head (url ).reply (200 ).mock
30
25
31
26
32
27
@pytest .mark .asyncio
33
- async def test_async_with_request (URL ):
34
- mock = _pook_url (URL )
28
+ async def test_async_with_request (url_404 ):
29
+ mock = _pook_url (url_404 )
35
30
async with aiohttp .ClientSession () as session :
36
- async with session .head (URL ) as req :
31
+ async with session .head (url_404 ) as req :
37
32
assert req .status == 200
38
33
39
34
assert len (mock .matches ) == 1
40
35
41
36
42
37
@pytest .mark .asyncio
43
- async def test_await_request (URL ):
44
- mock = _pook_url (URL )
38
+ async def test_await_request (url_404 ):
39
+ mock = _pook_url (url_404 )
45
40
async with aiohttp .ClientSession () as session :
46
- req = await session .head (URL )
41
+ req = await session .head (url_404 )
47
42
assert req .status == 200
48
43
49
44
assert len (mock .matches ) == 1
50
45
51
46
52
47
@pytest .mark .asyncio
53
- async def test_binary_body (URL ):
54
- pook .get (URL ).reply (200 ).body (BINARY_FILE )
48
+ async def test_binary_body (url_404 ):
49
+ pook .get (url_404 ).reply (200 ).body (BINARY_FILE )
55
50
async with aiohttp .ClientSession () as session :
56
- req = await session .get (URL )
51
+ req = await session .get (url_404 )
57
52
assert await req .read () == BINARY_FILE
58
53
59
54
60
55
@pytest .mark .asyncio
61
- async def test_json_matcher_json_payload (URL ):
56
+ async def test_json_matcher_json_payload (url_404 ):
62
57
payload = {"foo" : "bar" }
63
- pook .post (URL ).json (payload ).reply (200 ).body (BINARY_FILE )
58
+ pook .post (url_404 ).json (payload ).reply (200 ).body (BINARY_FILE )
64
59
async with aiohttp .ClientSession () as session :
65
- req = await session .post (URL , json = payload )
60
+ req = await session .post (url_404 , json = payload )
66
61
assert await req .read () == BINARY_FILE
67
62
68
63
69
64
@pytest .mark .asyncio
70
- async def test_client_base_url (httpbin ):
65
+ async def test_client_base_url (local_responder ):
71
66
"""Client base url should be matched."""
72
- pook .get (httpbin + "/status/404" ).reply (200 ).body ("hello from pook" )
73
- async with aiohttp .ClientSession (base_url = httpbin .url ) as session :
67
+ pook .get (local_responder + "/status/404" ).reply (200 ).body ("hello from pook" )
68
+ async with aiohttp .ClientSession (base_url = local_responder .url ) as session :
74
69
res = await session .get ("/status/404" )
75
70
assert res .status == 200
76
71
assert await res .read () == b"hello from pook"
77
72
78
73
79
74
@pytest .mark .asyncio
80
- async def test_client_headers (httpbin ):
75
+ async def test_client_headers (local_responder ):
81
76
"""Headers set on the client should be matched."""
82
- pook .get (httpbin + "/status/404" ).header ("x-pook" , "hello" ).reply (200 ).body (
77
+ pook .get (local_responder + "/status/404" ).header ("x-pook" , "hello" ).reply (200 ).body (
83
78
"hello from pook"
84
79
)
85
80
async with aiohttp .ClientSession (headers = {"x-pook" : "hello" }) as session :
86
- res = await session .get (httpbin + "/status/404" )
81
+ res = await session .get (local_responder + "/status/404" )
87
82
assert res .status == 200
88
83
assert await res .read () == b"hello from pook"
89
84
90
85
91
86
@pytest .mark .asyncio
92
- async def test_client_headers_merged (httpbin ):
87
+ async def test_client_headers_merged (local_responder ):
93
88
"""Headers set on the client should be matched even if request-specific headers are sent."""
94
- pook .get (httpbin + "/status/404" ).header ("x-pook" , "hello" ).reply (200 ).body (
89
+ pook .get (local_responder + "/status/404" ).header ("x-pook" , "hello" ).reply (200 ).body (
95
90
"hello from pook"
96
91
)
97
92
async with aiohttp .ClientSession (headers = {"x-pook" : "hello" }) as session :
98
93
res = await session .get (
99
- httpbin + "/status/404" , headers = {"x-pook-secondary" : "xyz" }
94
+ local_responder + "/status/404" , headers = {"x-pook-secondary" : "xyz" }
100
95
)
101
96
assert res .status == 200
102
97
assert await res .read () == b"hello from pook"
103
98
104
99
105
100
@pytest .mark .asyncio
106
- async def test_client_headers_both_session_and_request (httpbin ):
101
+ async def test_client_headers_both_session_and_request (local_responder ):
107
102
"""Headers should be matchable from both the session and request in the same matcher"""
108
- pook .get (httpbin + "/status/404" ).header ("x-pook-session" , "hello" ).header (
103
+ pook .get (local_responder + "/status/404" ).header ("x-pook-session" , "hello" ).header (
109
104
"x-pook-request" , "hey"
110
105
).reply (200 ).body ("hello from pook" )
111
106
async with aiohttp .ClientSession (headers = {"x-pook-session" : "hello" }) as session :
112
107
res = await session .get (
113
- httpbin + "/status/404" , headers = {"x-pook-request" : "hey" }
108
+ local_responder + "/status/404" , headers = {"x-pook-request" : "hey" }
114
109
)
115
110
assert res .status == 200
116
111
assert await res .read () == b"hello from pook"
0 commit comments