Skip to content

Commit 37710f9

Browse files
committed
tests: add tests for new requests functionality
1 parent ac19780 commit 37710f9

14 files changed

+1425
-74
lines changed

tests/test_browser/test_browser_base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
)
2121
from pydoll.protocol.fetch.events import FetchEvent
2222
from pydoll.connection.connection_handler import ConnectionHandler
23-
from pydoll.constants import DownloadBehavior, PermissionType, NetworkErrorReason, RequestMethod
2423

24+
from pydoll.protocol.network.types import RequestMethod, ErrorReason
25+
from pydoll.protocol.browser.types import DownloadBehavior, PermissionType
2526

2627
class ConcreteBrowser(Browser):
2728
def _get_default_binary_location(self) -> str:
@@ -488,7 +489,7 @@ async def test_set_download_behavior(mock_browser):
488489
@pytest.mark.asyncio
489490
async def test_set_download_path(mock_browser):
490491
mock_browser._execute_command = AsyncMock()
491-
await mock_browser.set_download_path('/downloads')
492+
await mock_browser.set_download_path(path='/downloads')
492493

493494
mock_browser._execute_command.assert_called_with(
494495
BrowserCommands.set_download_behavior(
@@ -716,7 +717,7 @@ async def test_continue_request_with_all_params(mock_browser):
716717
async def test_fail_request(mock_browser):
717718
"""Test fail_request."""
718719
request_id = 'test_request_123'
719-
error_reason = NetworkErrorReason.FAILED
720+
error_reason = ErrorReason.FAILED
720721

721722
await mock_browser.fail_request(request_id, error_reason)
722723

tests/test_browser/test_browser_tab.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from unittest.mock import AsyncMock, MagicMock, patch, ANY
66
from pathlib import Path
77

8-
from pydoll.constants import By, RequestStage, ResourceType, RequestMethod
8+
from pydoll.protocol.network.types import ResourceType, RequestMethod
9+
from pydoll.protocol.fetch.types import RequestStage
10+
from pydoll.constants import By
911
from pydoll.browser.tab import Tab
1012
from pydoll.exceptions import (
1113
NoDialogPresent,
@@ -809,14 +811,13 @@ async def test_expect_file_chooser_with_path_objects(self, tab):
809811
@pytest.mark.asyncio
810812
async def test_expect_file_chooser_event_handler_single_file(self, tab):
811813
"""Test the real event_handler function with single file."""
812-
from pydoll.protocol.dom.types import EventFileChooserOpened
813-
from pydoll.protocol.page.events import PageEvent
814+
from pydoll.protocol.page.events import FileChooserOpenedEvent, PageEvent
814815

815816
# Mock execute_command to capture the call
816817
tab._execute_command = AsyncMock()
817818

818819
# Create mock event data
819-
mock_event: EventFileChooserOpened = {
820+
mock_event: FileChooserOpenedEvent = {
820821
'method': 'Page.fileChooserOpened',
821822
'params': {
822823
'frameId': 'test-frame-id',
@@ -855,14 +856,13 @@ async def mock_on(event_name, handler, temporary=False):
855856
@pytest.mark.asyncio
856857
async def test_expect_file_chooser_event_handler_multiple_files(self, tab):
857858
"""Test the real event_handler function with multiple files."""
858-
from pydoll.protocol.dom.types import EventFileChooserOpened
859-
from pydoll.protocol.page.events import PageEvent
859+
from pydoll.protocol.page.events import FileChooserOpenedEvent, PageEvent
860860

861861
# Mock execute_command to capture the call
862862
tab._execute_command = AsyncMock()
863863

864864
# Create mock event data
865-
mock_event: EventFileChooserOpened = {
865+
mock_event: FileChooserOpenedEvent = {
866866
'method': 'Page.fileChooserOpened',
867867
'params': {
868868
'frameId': 'test-frame-id',
@@ -900,14 +900,13 @@ async def mock_on(event_name, handler, temporary=False):
900900

901901
async def _test_event_handler_with_files(self, tab, files, expected_files, backend_node_id):
902902
"""Helper method to test event handler with different file types."""
903-
from pydoll.protocol.dom.types import EventFileChooserOpened
904-
from pydoll.protocol.page.events import PageEvent
903+
from pydoll.protocol.page.events import FileChooserOpenedEvent, PageEvent
905904

906905
# Mock execute_command to capture the call
907906
tab._execute_command = AsyncMock()
908907

909908
# Create mock event data
910-
mock_event: EventFileChooserOpened = {
909+
mock_event: FileChooserOpenedEvent = {
911910
'method': 'Page.fileChooserOpened',
912911
'params': {
913912
'frameId': 'test-frame-id',
@@ -1241,10 +1240,10 @@ async def test_continue_request(self, tab):
12411240
@pytest.mark.asyncio
12421241
async def test_fail_request(self, tab):
12431242
"""Test fail_request method."""
1244-
from pydoll.constants import NetworkErrorReason
1243+
from pydoll.protocol.network.types import ErrorReason
12451244

12461245
request_id = 'test_request_456'
1247-
error_reason = NetworkErrorReason.FAILED
1246+
error_reason = ErrorReason.FAILED
12481247

12491248
await tab.fail_request(request_id, error_reason)
12501249

@@ -1288,7 +1287,7 @@ async def test_fulfill_request(self, tab):
12881287
@pytest.mark.asyncio
12891288
async def test_continue_request_with_all_params(self, tab):
12901289
"""Test continue_request with all parameters."""
1291-
from pydoll.constants import RequestMethod
1290+
from pydoll.protocol.network.types import RequestMethod
12921291

12931292
request_id = 'test_request_456'
12941293
url = 'https://modified-example.com'
@@ -1339,10 +1338,10 @@ async def test_continue_request_with_different_id(self, tab):
13391338
@pytest.mark.asyncio
13401339
async def test_fail_request_with_different_error(self, tab):
13411340
"""Test fail_request with different error reason."""
1342-
from pydoll.constants import NetworkErrorReason
1341+
from pydoll.protocol.network.types import ErrorReason
13431342

13441343
request_id = 'test_request_error'
1345-
error_reason = NetworkErrorReason.ABORTED
1344+
error_reason = ErrorReason.ABORTED
13461345

13471346
await tab.fail_request(request_id, error_reason)
13481347

0 commit comments

Comments
 (0)