Skip to content

Commit 7ceb00a

Browse files
author
Tom Softreck
committed
update
1 parent 4ce45b2 commit 7ceb00a

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

tests/test_webtask.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"""
44

55
import pytest
6-
from unittest.mock import patch, MagicMock
6+
from pathlib import Path
7+
from unittest.mock import patch, MagicMock, ANY
78
from webtask.server import webtaskServer, WebTaskHandler
89
from webtask.main import main
910

@@ -18,11 +19,30 @@ def test_server_initialization(self):
1819
assert server.port == 8000
1920
assert server.open_browser is True
2021

21-
def test_webtask_handler_initialization(self):
22+
@patch('http.server.SimpleHTTPRequestHandler.__init__')
23+
def test_webtask_handler_initialization(self, mock_init):
2224
"""Test WebTaskHandler initialization"""
23-
handler = WebTaskHandler(None, ('127.0.0.1', 12345), None)
24-
assert hasattr(handler, 'directory')
25-
assert 'static' in str(handler.directory)
25+
# Setup mocks
26+
mock_init.return_value = None
27+
28+
# Create a mock for the static directory path
29+
mock_static_dir = MagicMock()
30+
mock_static_dir.__str__.return_value = '/mock/static'
31+
32+
# Patch the Path class to return our mock
33+
with patch('pathlib.Path') as mock_path:
34+
# Configure the Path mock to return our mock_static_dir when divided by 'static'
35+
mock_path.return_value.parent = mock_path.return_value
36+
mock_path.return_value.__truediv__.return_value = mock_static_dir
37+
38+
# Create handler with mocked components
39+
handler = WebTaskHandler(None, None, None)
40+
41+
# Verify the handler was initialized with the correct directory
42+
mock_init.assert_called_once()
43+
call_args = mock_init.call_args[1]
44+
assert 'directory' in call_args
45+
assert 'static' in str(call_args['directory'])
2646

2747
def test_server_initialization_with_params(self):
2848
"""Test server initialization with custom parameters"""

webtask/server.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
import threading
77
from http.server import HTTPServer, SimpleHTTPRequestHandler
88
from pathlib import Path
9-
from typing import Any, Tuple, Optional, Type, TypeVar
10-
11-
12-
_RequestHandlerT = TypeVar('_RequestHandlerT', bound=SimpleHTTPRequestHandler)
9+
from typing import Any
1310

1411

1512
class WebTaskHandler(SimpleHTTPRequestHandler):
@@ -33,7 +30,12 @@ def log_message(self, format: str, *args: Any) -> None:
3330

3431
class webtaskServer:
3532
"""webtask server wrapper"""
36-
def __init__(self, host: str = "localhost", port: int = 8000, open_browser: bool = True) -> None:
33+
def __init__(
34+
self,
35+
host: str = "localhost",
36+
port: int = 8000,
37+
open_browser: bool = True
38+
) -> None:
3739
self.host = host
3840
self.port = port
3941
self.open_browser = open_browser

0 commit comments

Comments
 (0)