4
4
from unittest .mock import AsyncMock , MagicMock , patch , ANY
5
5
from pathlib import Path
6
6
7
- from pydoll .constants import By , RequestStage , ResourceType
7
+ from pydoll .constants import By , RequestStage , ResourceType , RequestMethod
8
8
from pydoll .browser .tab import Tab
9
9
from pydoll .exceptions import (
10
10
NoDialogPresent ,
@@ -1214,7 +1214,7 @@ class TestTabRequestManagement:
1214
1214
1215
1215
@pytest .mark .asyncio
1216
1216
async def test_continue_request (self , tab ):
1217
- """Test continue_request method."""
1217
+ """Test continue_request method with minimal parameters ."""
1218
1218
request_id = 'test_request_123'
1219
1219
1220
1220
await tab .continue_request (request_id )
@@ -1229,6 +1229,13 @@ async def test_continue_request(self, tab):
1229
1229
# Verify it's a FetchCommands.continue_request command
1230
1230
assert command ['method' ] == 'Fetch.continueRequest'
1231
1231
assert command ['params' ]['requestId' ] == request_id
1232
+ # Verify optional parameters are None/not set
1233
+ params = command ['params' ]
1234
+ assert params .get ('url' ) is None
1235
+ assert params .get ('method' ) is None
1236
+ assert params .get ('postData' ) is None
1237
+ assert params .get ('headers' ) is None
1238
+ assert params .get ('interceptResponse' ) is None
1232
1239
1233
1240
@pytest .mark .asyncio
1234
1241
async def test_fail_request (self , tab ):
@@ -1254,15 +1261,11 @@ async def test_fail_request(self, tab):
1254
1261
1255
1262
@pytest .mark .asyncio
1256
1263
async def test_fulfill_request (self , tab ):
1257
- """Test fulfill_request method."""
1264
+ """Test fulfill_request method with minimal parameters ."""
1258
1265
request_id = 'test_request_789'
1259
1266
response_code = 200
1260
- response_headers = [{'name' : 'Content-Type' , 'value' : 'application/json' }]
1261
- response_body = {'status' : 'success' , 'data' : 'test' }
1262
1267
1263
- await tab .fulfill_request (
1264
- request_id , response_code , response_headers , response_body
1265
- )
1268
+ await tab .fulfill_request (request_id , response_code )
1266
1269
1267
1270
# Verify the command was executed with correct parameters
1268
1271
assert_mock_called_at_least_once (tab ._connection_handler )
@@ -1275,8 +1278,48 @@ async def test_fulfill_request(self, tab):
1275
1278
assert command ['method' ] == 'Fetch.fulfillRequest'
1276
1279
assert command ['params' ]['requestId' ] == request_id
1277
1280
assert command ['params' ]['responseCode' ] == response_code
1278
- assert command ['params' ]['responseHeaders' ] == response_headers
1279
- assert command ['params' ]['body' ] == response_body
1281
+ # Verify optional parameters are None/not set
1282
+ params = command ['params' ]
1283
+ assert params .get ('responseHeaders' ) is None
1284
+ assert params .get ('body' ) is None
1285
+ assert params .get ('responsePhrase' ) is None
1286
+
1287
+ @pytest .mark .asyncio
1288
+ async def test_continue_request_with_all_params (self , tab ):
1289
+ """Test continue_request with all parameters."""
1290
+ from pydoll .constants import RequestMethod
1291
+
1292
+ request_id = 'test_request_456'
1293
+ url = 'https://modified-example.com'
1294
+ method = RequestMethod .POST
1295
+ post_data = 'modified_data=test'
1296
+ headers = [{'name' : 'Authorization' , 'value' : 'Bearer token123' }]
1297
+ intercept_response = True
1298
+
1299
+ await tab .continue_request (
1300
+ request_id = request_id ,
1301
+ url = url ,
1302
+ method = method ,
1303
+ post_data = post_data ,
1304
+ headers = headers ,
1305
+ intercept_response = intercept_response ,
1306
+ )
1307
+
1308
+ # Verify the command was executed with correct parameters
1309
+ assert_mock_called_at_least_once (tab ._connection_handler )
1310
+
1311
+ # Get the call arguments to verify the command
1312
+ call_args = tab ._connection_handler .execute_command .call_args_list [- 1 ]
1313
+ command = call_args [0 ][0 ] # First argument is the command
1314
+
1315
+ # Verify all parameters
1316
+ params = command ['params' ]
1317
+ assert params ['requestId' ] == request_id
1318
+ assert params ['url' ] == url
1319
+ assert params ['method' ] == method
1320
+ assert params ['postData' ] == post_data
1321
+ assert params ['headers' ] == headers
1322
+ assert params ['interceptResponse' ] == intercept_response
1280
1323
1281
1324
@pytest .mark .asyncio
1282
1325
async def test_continue_request_with_different_id (self , tab ):
@@ -1309,6 +1352,38 @@ async def test_fail_request_with_different_error(self, tab):
1309
1352
command = call_args [0 ][0 ]
1310
1353
assert command ['params' ]['errorReason' ] == error_reason
1311
1354
1355
+ @pytest .mark .asyncio
1356
+ async def test_fulfill_request_with_all_params (self , tab ):
1357
+ """Test fulfill_request with all parameters."""
1358
+ request_id = 'test_request_complete'
1359
+ response_code = 200
1360
+ response_headers = [{'name' : 'Content-Type' , 'value' : 'application/json' }]
1361
+ body = '{"status": "success", "data": "test"}'
1362
+ response_phrase = 'OK'
1363
+
1364
+ await tab .fulfill_request (
1365
+ request_id = request_id ,
1366
+ response_code = response_code ,
1367
+ response_headers = response_headers ,
1368
+ body = body ,
1369
+ response_phrase = response_phrase ,
1370
+ )
1371
+
1372
+ # Verify the command was executed with correct parameters
1373
+ assert_mock_called_at_least_once (tab ._connection_handler )
1374
+
1375
+ # Get the call arguments to verify the command
1376
+ call_args = tab ._connection_handler .execute_command .call_args_list [- 1 ]
1377
+ command = call_args [0 ][0 ] # First argument is the command
1378
+
1379
+ # Verify all parameters
1380
+ params = command ['params' ]
1381
+ assert params ['requestId' ] == request_id
1382
+ assert params ['responseCode' ] == response_code
1383
+ assert params ['responseHeaders' ] == response_headers
1384
+ assert params ['body' ] == body
1385
+ assert params ['responsePhrase' ] == response_phrase
1386
+
1312
1387
@pytest .mark .asyncio
1313
1388
async def test_fulfill_request_with_different_status_code (self , tab ):
1314
1389
"""Test fulfill_request with different status code."""
0 commit comments