@@ -1489,25 +1489,33 @@ def test_unknown_flag(self, _):
1489
1489
self .assertEqual (stdout .getvalue (), '' )
1490
1490
self .assertIn ('error' , stderr .getvalue ())
1491
1491
1492
- def test_response_headers_arg (self ):
1493
- with mock .patch .object (HTTPServer , 'serve_forever' ):
1494
- httpd = server ._main (
1495
- ['-H' , 'Set-Cookie' , 'k=v' , '-H' , 'Set-Cookie' , 'k2=v2' , '8080' ]
1492
+ @mock .patch ('http.server._make_server' , wraps = server ._make_server )
1493
+ @mock .patch .object (HTTPServer , 'serve_forever' )
1494
+ def test_response_headers_arg (self , _ , mock_make_server ):
1495
+ server ._main (
1496
+ ['-H' , 'Set-Cookie' , 'k=v' , '-H' , 'Set-Cookie' , 'k2=v2' , '8080' ]
1497
+ )
1498
+ # Get an instance of the server / RequestHandler by using
1499
+ # the spied call args, then calling _make_server with them.
1500
+ args , kwargs = mock_make_server .call_args
1501
+ httpd = server ._make_server (* args , ** kwargs )
1502
+
1503
+ # Ensure the RequestHandler class is passed the correct response
1504
+ # headers
1505
+ request_handler_class = httpd .RequestHandlerClass
1506
+ with mock .patch .object (
1507
+ request_handler_class , '__init__'
1508
+ ) as mock_handler_init :
1509
+ mock_handler_init .return_value = None
1510
+ # finish_request instantiates a request handler class,
1511
+ # ensure response_headers are passed to it
1512
+ httpd .finish_request (mock .Mock (), '127.0.0.1' )
1513
+ mock_handler_init .assert_called_once_with (
1514
+ mock .ANY , mock .ANY , mock .ANY , directory = mock .ANY ,
1515
+ response_headers = [
1516
+ ['Set-Cookie' , 'k=v' ], ['Set-Cookie' , 'k2=v2' ]
1517
+ ]
1496
1518
)
1497
- request_handler_class = httpd .RequestHandlerClass
1498
- with mock .patch .object (
1499
- request_handler_class , '__init__'
1500
- ) as mock_handler_init :
1501
- mock_handler_init .return_value = None
1502
- # finish_request instantiates a request handler class,
1503
- # ensure response_headers are passed to it
1504
- httpd .finish_request (mock .Mock (), '127.0.0.1' )
1505
- mock_handler_init .assert_called_once_with (
1506
- mock .ANY , mock .ANY , mock .ANY , directory = mock .ANY ,
1507
- response_headers = [
1508
- ['Set-Cookie' , 'k=v' ], ['Set-Cookie' , 'k2=v2' ]
1509
- ]
1510
- )
1511
1519
1512
1520
1513
1521
class CommandLineRunTimeTestCase (unittest .TestCase ):
0 commit comments