1414limitations under the License.
1515"""
1616
17- from functools import partial
1817import platform
18+ import socket
1919from typing import Any
2020
2121from mock import patch
@@ -43,16 +43,15 @@ async def test_pytds(kwargs: Any) -> None:
4343 ip_addr = "127.0.0.1"
4444 # build ssl.SSLContext
4545 context = await create_ssl_context ()
46- # force all wrap_socket calls to have do_handshake_on_connect=False
47- setattr (
48- context ,
49- "wrap_socket" ,
50- partial (context .wrap_socket , do_handshake_on_connect = False ),
46+ sock = context .wrap_socket (
47+ socket .create_connection ((ip_addr , 3307 )),
48+ server_hostname = ip_addr ,
49+ do_handshake_on_connect = False ,
5150 )
5251
5352 with patch ("pytds.connect" ) as mock_connect :
5453 mock_connect .return_value = True
55- connection = connect (ip_addr , context , ** kwargs )
54+ connection = connect (ip_addr , sock , ** kwargs )
5655 # verify that driver connection call would be made
5756 assert connection is True
5857 assert mock_connect .assert_called_once
@@ -68,17 +67,16 @@ async def test_pytds_platform_error(kwargs: Any) -> None:
6867 assert platform .system () == "Linux"
6968 # build ssl.SSLContext
7069 context = await create_ssl_context ()
71- # force all wrap_socket calls to have do_handshake_on_connect=False
72- setattr (
73- context ,
74- "wrap_socket" ,
75- partial (context .wrap_socket , do_handshake_on_connect = False ),
70+ sock = context .wrap_socket (
71+ socket .create_connection ((ip_addr , 3307 )),
72+ server_hostname = ip_addr ,
73+ do_handshake_on_connect = False ,
7674 )
7775 # add active_directory_auth to kwargs
7876 kwargs ["active_directory_auth" ] = True
7977 # verify that error is thrown with Linux and active_directory_auth
8078 with pytest .raises (PlatformNotSupportedError ):
81- connect (ip_addr , context , ** kwargs )
79+ connect (ip_addr , sock , ** kwargs )
8280
8381
8482@pytest .mark .usefixtures ("server" )
@@ -94,11 +92,10 @@ async def test_pytds_windows_active_directory_auth(kwargs: Any) -> None:
9492 assert platform .system () == "Windows"
9593 # build ssl.SSLContext
9694 context = await create_ssl_context ()
97- # force all wrap_socket calls to have do_handshake_on_connect=False
98- setattr (
99- context ,
100- "wrap_socket" ,
101- partial (context .wrap_socket , do_handshake_on_connect = False ),
95+ sock = context .wrap_socket (
96+ socket .create_connection ((ip_addr , 3307 )),
97+ server_hostname = ip_addr ,
98+ do_handshake_on_connect = False ,
10299 )
103100 # add active_directory_auth and server_name to kwargs
104101 kwargs ["active_directory_auth" ] = True
@@ -107,7 +104,7 @@ async def test_pytds_windows_active_directory_auth(kwargs: Any) -> None:
107104 mock_connect .return_value = True
108105 with patch ("pytds.login.SspiAuth" ) as mock_login :
109106 mock_login .return_value = True
110- connection = connect (ip_addr , context , ** kwargs )
107+ connection = connect (ip_addr , sock , ** kwargs )
111108 # verify that driver connection call would be made
112109 assert mock_login .assert_called_once
113110 assert connection is True
0 commit comments