@@ -25,7 +25,7 @@ async def wrapper(*args, **kwargs):
25
25
26
26
@pytest .mark .asyncio
27
27
@async_retry ()
28
- async def test_client_init_params ():
28
+ async def test_asyncclient_init ():
29
29
auth = ("user" , "password" )
30
30
headers = {"X-Test" : "test" }
31
31
cookies = {"ccc" : "ddd" , "cccc" : "dddd" }
@@ -43,227 +43,4 @@ async def test_client_init_params():
43
43
assert json_data ["headers" ]["X-Test" ] == "test"
44
44
assert json_data ["headers" ]["Cookie" ] == "ccc=ddd; cccc=dddd"
45
45
assert json_data ["headers" ]["Authorization" ] == "Basic dXNlcjpwYXNzd29yZA=="
46
- assert json_data ["args" ] == {"x" : "aaa" , "y" : "bbb" }
47
-
48
-
49
- @pytest .mark .asyncio
50
- @async_retry ()
51
- async def test_client_setters ():
52
- client = primp .AsyncClient ()
53
- client .auth = ("user" , "password" )
54
- client .headers = {"X-Test" : "TesT" }
55
- client .cookies = {"ccc" : "ddd" , "cccc" : "dddd" }
56
- client .params = {"x" : "aaa" , "y" : "bbb" }
57
- client .timeout = 20
58
-
59
- response = await client .get ("https://httpbin.org/anything" )
60
- assert response .status_code == 200
61
- assert client .auth == ("user" , "password" )
62
- assert client .headers == {"x-test" : "TesT" }
63
- assert client .cookies == {"ccc" : "ddd" , "cccc" : "dddd" }
64
- assert client .params == {"x" : "aaa" , "y" : "bbb" }
65
- assert client .timeout == 20.0
66
- json_data = response .json ()
67
- assert json_data ["method" ] == "GET"
68
- assert json_data ["headers" ]["X-Test" ] == "TesT"
69
- assert json_data ["headers" ]["Cookie" ] == "ccc=ddd; cccc=dddd"
70
- assert json_data ["headers" ]["Authorization" ] == "Basic dXNlcjpwYXNzd29yZA=="
71
- assert json_data ["args" ] == {"x" : "aaa" , "y" : "bbb" }
72
- assert "Basic dXNlcjpwYXNzd29yZA==" in response .text
73
- assert b"Basic dXNlcjpwYXNzd29yZA==" in response .content
74
-
75
-
76
- @pytest .mark .asyncio
77
- @async_retry ()
78
- async def test_client_request_get ():
79
- client = primp .AsyncClient ()
80
- auth_bearer = "bearerXXXXXXXXXXXXXXXXXXXX"
81
- headers = {"X-Test" : "test" }
82
- cookies = {"ccc" : "ddd" , "cccc" : "dddd" }
83
- params = {"x" : "aaa" , "y" : "bbb" }
84
- response = await client .request (
85
- "GET" ,
86
- "https://httpbin.org/anything" ,
87
- auth_bearer = auth_bearer ,
88
- headers = headers ,
89
- cookies = cookies ,
90
- params = params ,
91
- )
92
- assert response .status_code == 200
93
- json_data = response .json ()
94
- assert json_data ["method" ] == "GET"
95
- assert json_data ["headers" ]["X-Test" ] == "test"
96
- assert json_data ["headers" ]["Cookie" ] == "ccc=ddd; cccc=dddd"
97
- assert json_data ["headers" ]["Authorization" ] == "Bearer bearerXXXXXXXXXXXXXXXXXXXX"
98
- assert json_data ["args" ] == {"x" : "aaa" , "y" : "bbb" }
99
- assert "Bearer bearerXXXXXXXXXXXXXXXXXXXX" in response .text
100
- assert b"Bearer bearerXXXXXXXXXXXXXXXXXXXX" in response .content
101
-
102
-
103
- @pytest .mark .asyncio
104
- @async_retry ()
105
- async def test_client_get ():
106
- client = primp .AsyncClient ()
107
- auth_bearer = "bearerXXXXXXXXXXXXXXXXXXXX"
108
- headers = {"X-Test" : "test" }
109
- cookies = {"ccc" : "ddd" , "cccc" : "dddd" }
110
- params = {"x" : "aaa" , "y" : "bbb" }
111
- response = await client .get (
112
- "https://httpbin.org/anything" ,
113
- auth_bearer = auth_bearer ,
114
- headers = headers ,
115
- cookies = cookies ,
116
- params = params ,
117
- )
118
- assert response .status_code == 200
119
- json_data = response .json ()
120
- assert json_data ["method" ] == "GET"
121
- assert json_data ["headers" ]["X-Test" ] == "test"
122
- assert json_data ["headers" ]["Cookie" ] == "ccc=ddd; cccc=dddd"
123
- assert json_data ["headers" ]["Authorization" ] == "Bearer bearerXXXXXXXXXXXXXXXXXXXX"
124
- assert json_data ["args" ] == {"x" : "aaa" , "y" : "bbb" }
125
- assert "Bearer bearerXXXXXXXXXXXXXXXXXXXX" in response .text
126
- assert b"Bearer bearerXXXXXXXXXXXXXXXXXXXX" in response .content
127
-
128
-
129
- @pytest .mark .asyncio
130
- @async_retry ()
131
- async def test_client_post_content ():
132
- client = primp .AsyncClient ()
133
- auth = ("user" , "password" )
134
- headers = {"X-Test" : "test" }
135
- cookies = {"ccc" : "ddd" , "cccc" : "dddd" }
136
- params = {"x" : "aaa" , "y" : "bbb" }
137
- content = b"test content"
138
- response = await client .post (
139
- "https://httpbin.org/anything" ,
140
- auth = auth ,
141
- headers = headers ,
142
- cookies = cookies ,
143
- params = params ,
144
- content = content ,
145
- )
146
- assert response .status_code == 200
147
- json_data = response .json ()
148
- assert json_data ["method" ] == "POST"
149
- assert json_data ["headers" ]["X-Test" ] == "test"
150
- assert json_data ["headers" ]["Cookie" ] == "ccc=ddd; cccc=dddd"
151
- assert json_data ["headers" ]["Authorization" ] == "Basic dXNlcjpwYXNzd29yZA=="
152
- assert json_data ["args" ] == {"x" : "aaa" , "y" : "bbb" }
153
- assert json_data ["data" ] == "test content"
154
-
155
-
156
- @pytest .mark .asyncio
157
- @async_retry ()
158
- async def test_client_post_data ():
159
- client = primp .AsyncClient ()
160
- auth_bearer = "bearerXXXXXXXXXXXXXXXXXXXX"
161
- headers = {"X-Test" : "test" }
162
- cookies = {"ccc" : "ddd" , "cccc" : "dddd" }
163
- params = {"x" : "aaa" , "y" : "bbb" }
164
- data = {"key1" : "value1" , "key2" : "value2" }
165
- response = await client .post (
166
- "https://httpbin.org/anything" ,
167
- auth_bearer = auth_bearer ,
168
- headers = headers ,
169
- cookies = cookies ,
170
- params = params ,
171
- data = data ,
172
- )
173
- assert response .status_code == 200
174
- json_data = response .json ()
175
- assert json_data ["method" ] == "POST"
176
- assert json_data ["headers" ]["X-Test" ] == "test"
177
- assert json_data ["headers" ]["Cookie" ] == "ccc=ddd; cccc=dddd"
178
- assert json_data ["headers" ]["Authorization" ] == "Bearer bearerXXXXXXXXXXXXXXXXXXXX"
179
- assert json_data ["args" ] == {"x" : "aaa" , "y" : "bbb" }
180
- assert json_data ["form" ] == {"key1" : "value1" , "key2" : "value2" }
181
-
182
-
183
- @pytest .mark .asyncio
184
- @async_retry ()
185
- async def test_client_post_json ():
186
- client = primp .AsyncClient ()
187
- auth_bearer = "bearerXXXXXXXXXXXXXXXXXXXX"
188
- headers = {"X-Test" : "test" }
189
- cookies = {"ccc" : "ddd" , "cccc" : "dddd" }
190
- params = {"x" : "aaa" , "y" : "bbb" }
191
- data = {"key1" : "value1" , "key2" : "value2" }
192
- response = await client .post (
193
- "https://httpbin.org/anything" ,
194
- auth_bearer = auth_bearer ,
195
- headers = headers ,
196
- cookies = cookies ,
197
- params = params ,
198
- json = data ,
199
- )
200
- assert response .status_code == 200
201
- json_data = response .json ()
202
- assert json_data ["method" ] == "POST"
203
- assert json_data ["headers" ]["X-Test" ] == "test"
204
- assert json_data ["headers" ]["Cookie" ] == "ccc=ddd; cccc=dddd"
205
- assert json_data ["headers" ]["Authorization" ] == "Bearer bearerXXXXXXXXXXXXXXXXXXXX"
206
- assert json_data ["args" ] == {"x" : "aaa" , "y" : "bbb" }
207
- assert json_data ["json" ] == data
208
-
209
-
210
- @pytest .fixture (scope = "session" )
211
- def test_files (tmp_path_factory ):
212
- tmp_path_factory .mktemp ("data" )
213
- temp_file1 = tmp_path_factory .mktemp ("data" ) / "img1.png"
214
- with open (temp_file1 , "w" ) as f :
215
- f .write ("aaa111" )
216
- temp_file2 = tmp_path_factory .mktemp ("data" ) / "img2.png"
217
- with open (temp_file2 , "w" ) as f :
218
- f .write ("bbb222" )
219
- return str (temp_file1 ), str (temp_file2 )
220
-
221
-
222
- @pytest .mark .asyncio
223
- async def test_client_post_files (test_files ):
224
- temp_file1 , temp_file2 = test_files
225
- client = primp .AsyncClient ()
226
- auth_bearer = "bearerXXXXXXXXXXXXXXXXXXXX"
227
- headers = {"X-Test" : "test" }
228
- cookies = {"ccc" : "ddd" , "cccc" : "dddd" }
229
- params = {"x" : "aaa" , "y" : "bbb" }
230
- files = {"file1" : temp_file1 , "file2" : temp_file2 }
231
- response = await client .post (
232
- "https://httpbin.org/anything" ,
233
- auth_bearer = auth_bearer ,
234
- headers = headers ,
235
- cookies = cookies ,
236
- params = params ,
237
- files = files ,
238
- )
239
- assert response .status_code == 200
240
- json_data = response .json ()
241
- assert json_data ["method" ] == "POST"
242
- assert json_data ["headers" ]["X-Test" ] == "test"
243
- assert json_data ["headers" ]["Cookie" ] == "ccc=ddd; cccc=dddd"
244
- assert json_data ["headers" ]["Authorization" ] == "Bearer bearerXXXXXXXXXXXXXXXXXXXX"
245
- assert json_data ["args" ] == {"x" : "aaa" , "y" : "bbb" }
246
- assert json_data ["files" ] == {"file1" : "aaa111" , "file2" : "bbb222" }
247
-
248
-
249
- @pytest .mark .asyncio
250
- @async_retry ()
251
- async def test_client_impersonate_chrome131 ():
252
- client = primp .AsyncClient (
253
- impersonate = "chrome_131" ,
254
- impersonate_os = "windows" ,
255
- )
256
- # response = client.get("https://tls.peet.ws/api/all")
257
- response = await client .get ("https://tls.http.rw/api/all" )
258
- assert response .status_code == 200
259
- json_data = response .json ()
260
- assert (
261
- json_data ["user_agent" ]
262
- == "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
263
- )
264
- assert json_data ["tls" ]["ja4" ] == "t13d1516h2_8daaf6152771_b1ff8ab2d16f"
265
- assert (
266
- json_data ["http2" ]["akamai_fingerprint_hash" ]
267
- == "90224459f8bf70b7d0a8797eb916dbc9"
268
- )
269
- assert json_data ["tls" ]["peetprint_hash" ] == "7466733991096b3f4e6c0e79b0083559"
46
+ assert json_data ["args" ] == {"x" : "aaa" , "y" : "bbb" }
0 commit comments