33"""
44
55import pytest
6- from unittest .mock import patch , MagicMock
6+ from pathlib import Path
7+ from unittest .mock import patch , MagicMock , ANY
78from webtask .server import webtaskServer , WebTaskHandler
89from 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"""
0 commit comments