Skip to content

Commit

Permalink
Fix test_pac_file_served_from_disk
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavsingh committed Aug 10, 2024
1 parent 6f0562d commit 148721c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
4 changes: 1 addition & 3 deletions proxy/http/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,7 @@ def _parse_first_request(self, data: memoryview) -> bool:
return True
# Discover which HTTP handler plugin is capable of
# handling the current incoming request
klass = self._discover_plugin_klass(
self.request.http_handler_protocol,
)
klass = self._discover_plugin_klass(self.request.http_handler_protocol)
if klass is None:
# No matching protocol class found.
# Return bad request response and
Expand Down
39 changes: 25 additions & 14 deletions tests/http/web/test_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,6 @@ def test_on_client_connection_called_on_teardown(mocker: MockerFixture) -> None:
assert _conn.closed


def mock_selector_for_client_read(self: Any) -> None:
self.mock_selector.return_value.select.return_value = [
(
selectors.SelectorKey(
fileobj=self._conn.fileno(),
fd=self._conn.fileno(),
events=selectors.EVENT_READ,
data=None,
),
selectors.EVENT_READ,
),
]

# @mock.patch('socket.fromfd')
# def test_on_client_connection_called_on_teardown(
# self, mock_fromfd: mock.Mock,
Expand Down Expand Up @@ -171,10 +158,34 @@ def _setUp(self, request: Any, mocker: MockerFixture) -> None:
b'GET / HTTP/1.1',
CRLF,
])
mock_selector_for_client_read(self)
self.mock_selector.return_value.select.side_effect = [
[
(
selectors.SelectorKey(
fileobj=self._conn.fileno(),
fd=self._conn.fileno(),
events=selectors.EVENT_READ,
data=None,
),
selectors.EVENT_READ,
)
],
[
(
selectors.SelectorKey(
fileobj=self._conn.fileno(),
fd=self._conn.fileno(),
events=selectors.EVENT_WRITE,
data=None,
),
selectors.EVENT_WRITE,
)
],
]

@pytest.mark.asyncio # type: ignore[misc]
async def test_pac_file_served_from_disk(self) -> None:
await self.protocol_handler._run_once()
await self.protocol_handler._run_once()
self.assertEqual(
self.protocol_handler.request.state,
Expand Down

0 comments on commit 148721c

Please sign in to comment.