2727
2828@pytest .fixture
2929def remote_connection ():
30+ """Fixture to create a RemoteConnection instance."""
3031 return RemoteConnection ("http://localhost:4444" )
3132
3233
33- def test_add_command ():
34- RemoteConnection .add_command ("CUSTOM_COMMAND" , "PUT" , "/session/$sessionId/custom" )
35- assert RemoteConnection .extra_commands ["CUSTOM_COMMAND" ] == ("PUT" , "/session/$sessionId/custom" )
34+ def test_add_command (remote_connection ):
35+ """Test adding a custom command to the connection."""
36+ remote_connection .add_command ("CUSTOM_COMMAND" , "PUT" , "/session/$sessionId/custom" )
37+ assert remote_connection .get_command ("CUSTOM_COMMAND" ) == ("PUT" , "/session/$sessionId/custom" )
3638
3739
3840@patch ("selenium.webdriver.remote.remote_connection.RemoteConnection._request" )
3941def test_execute_custom_command (mock_request , remote_connection ):
40- RemoteConnection .add_command ("CUSTOM_COMMAND" , "PUT" , "/session/$sessionId/custom" )
41- mock_request .return_value = {"status" : 0 , "value" : "OK" }
42+ """Test executing a custom command through the connection."""
43+ remote_connection .add_command ("CUSTOM_COMMAND" , "PUT" , "/session/$sessionId/custom" )
44+ mock_request .return_value = {"status" : 200 , "value" : "OK" }
4245
4346 params = {"sessionId" : "12345" }
4447 response = remote_connection .execute ("CUSTOM_COMMAND" , params )
4548
4649 mock_request .assert_called_once_with ("PUT" , "http://localhost:4444/session/12345/custom" , body = "{}" )
47- assert response == {"status" : 0 , "value" : "OK" }
50+ assert response == {"status" : 200 , "value" : "OK" }
4851
4952
5053def test_get_remote_connection_headers_defaults ():
@@ -266,17 +269,17 @@ def mock_no_proxy_settings(monkeypatch):
266269
267270@patch ("selenium.webdriver.remote.remote_connection.RemoteConnection.get_remote_connection_headers" )
268271def test_override_user_agent_in_headers (mock_get_remote_connection_headers , remote_connection ):
269- RemoteConnection .user_agent = "rspec /1.0 (python 3.8)"
272+ RemoteConnection .user_agent = "custom-agent /1.0 (python 3.8)"
270273
271274 mock_get_remote_connection_headers .return_value = {
272275 "Accept" : "application/json" ,
273276 "Content-Type" : "application/json;charset=UTF-8" ,
274- "User-Agent" : "rspec /1.0 (python 3.8)" ,
277+ "User-Agent" : "custom-agent /1.0 (python 3.8)" ,
275278 }
276279
277280 headers = RemoteConnection .get_remote_connection_headers (parse .urlparse ("http://remote" ))
278281
279- assert headers .get ("User-Agent" ) == "rspec /1.0 (python 3.8)"
282+ assert headers .get ("User-Agent" ) == "custom-agent /1.0 (python 3.8)"
280283 assert headers .get ("Accept" ) == "application/json"
281284 assert headers .get ("Content-Type" ) == "application/json;charset=UTF-8"
282285
@@ -285,7 +288,7 @@ def test_override_user_agent_in_headers(mock_get_remote_connection_headers, remo
285288def test_register_extra_headers (mock_request , remote_connection ):
286289 RemoteConnection .extra_headers = {"Foo" : "bar" }
287290
288- mock_request .return_value = {"status" : 0 , "value" : "OK" }
291+ mock_request .return_value = {"status" : 200 , "value" : "OK" }
289292 remote_connection .execute ("newSession" , {})
290293
291294 mock_request .assert_called_once_with ("POST" , "http://localhost:4444/session" , body = "{}" )
0 commit comments