Skip to content

Commit ac5fca0

Browse files
chore: update unit tests
1 parent 24a6230 commit ac5fca0

File tree

6 files changed

+28
-39
lines changed

6 files changed

+28
-39
lines changed

google/cloud/sql/connector/pg8000.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import ssl
1818
from typing import Any, TYPE_CHECKING
1919

20-
SERVER_PROXY_PORT = 3307
21-
2220
if TYPE_CHECKING:
2321
import pg8000
2422

google/cloud/sql/connector/pymysql.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import ssl
1818
from typing import Any, TYPE_CHECKING
1919

20-
SERVER_PROXY_PORT = 3307
21-
2220
if TYPE_CHECKING:
2321
import pymysql
2422

google/cloud/sql/connector/pytds.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
from google.cloud.sql.connector.exceptions import PlatformNotSupportedError
2222

23-
SERVER_PROXY_PORT = 3307
24-
2523
if TYPE_CHECKING:
2624
import pytds
2725

tests/unit/test_pg8000.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
"""
1616

17-
from functools import partial
17+
import socket
1818
from typing import Any
1919

2020
from mock import patch
@@ -31,15 +31,14 @@ async def test_pg8000(kwargs: Any) -> None:
3131
ip_addr = "127.0.0.1"
3232
# build ssl.SSLContext
3333
context = await create_ssl_context()
34-
# force all wrap_socket calls to have do_handshake_on_connect=False
35-
setattr(
36-
context,
37-
"wrap_socket",
38-
partial(context.wrap_socket, do_handshake_on_connect=False),
34+
sock = context.wrap_socket(
35+
socket.create_connection((ip_addr, 3307)),
36+
server_hostname=ip_addr,
37+
do_handshake_on_connect=False,
3938
)
4039
with patch("pg8000.dbapi.connect") as mock_connect:
4140
mock_connect.return_value = True
42-
connection = connect(ip_addr, context, **kwargs)
41+
connection = connect(ip_addr, sock, **kwargs)
4342
assert connection is True
4443
# verify that driver connection call would be made
4544
assert mock_connect.assert_called_once

tests/unit/test_pymysql.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
"""
1616

17-
from functools import partial
17+
import socket
1818
import ssl
1919
from typing import Any
2020

@@ -40,15 +40,14 @@ async def test_pymysql(kwargs: Any) -> None:
4040
ip_addr = "127.0.0.1"
4141
# build ssl.SSLContext
4242
context = await create_ssl_context()
43-
# force all wrap_socket calls to have do_handshake_on_connect=False
44-
setattr(
45-
context,
46-
"wrap_socket",
47-
partial(context.wrap_socket, do_handshake_on_connect=False),
43+
sock = context.wrap_socket(
44+
socket.create_connection((ip_addr, 3307)),
45+
server_hostname=ip_addr,
46+
do_handshake_on_connect=False,
4847
)
4948
kwargs["timeout"] = 30
5049
with patch("pymysql.Connection") as mock_connect:
5150
mock_connect.return_value = MockConnection
52-
pymysql_connect(ip_addr, context, **kwargs)
51+
pymysql_connect(ip_addr, sock, **kwargs)
5352
# verify that driver connection call would be made
5453
assert mock_connect.assert_called_once

tests/unit/test_pytds.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
limitations under the License.
1515
"""
1616

17-
from functools import partial
1817
import platform
18+
import socket
1919
from typing import Any
2020

2121
from 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

Comments
 (0)