Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions pymysql/tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def test_defer_connect(self):

def test_ssl_connect(self):
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
with mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -570,6 +570,7 @@ def test_ssl_connect(self):
"key": "key",
"cipher": "cipher",
},
defer_connect=True,
)
assert create_default_context.called
assert dummy_ssl_context.check_hostname
Expand All @@ -582,7 +583,7 @@ def test_ssl_connect(self):
dummy_ssl_context.set_ciphers.assert_called_with("cipher")

dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
with mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -592,6 +593,7 @@ def test_ssl_connect(self):
"cert": "cert",
"key": "key",
},
defer_connect=True,
)
assert create_default_context.called
assert dummy_ssl_context.check_hostname
Expand All @@ -604,7 +606,7 @@ def test_ssl_connect(self):
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
with mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -615,6 +617,7 @@ def test_ssl_connect(self):
"key": "key",
"password": "password",
},
defer_connect=True,
)
assert create_default_context.called
assert dummy_ssl_context.check_hostname
Expand All @@ -627,12 +630,13 @@ def test_ssl_connect(self):
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
with mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
pymysql.connect(
ssl_ca="ca",
defer_connect=True,
)
assert create_default_context.called
assert not dummy_ssl_context.check_hostname
Expand All @@ -641,14 +645,15 @@ def test_ssl_connect(self):
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
with mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
pymysql.connect(
ssl_ca="ca",
ssl_cert="cert",
ssl_key="key",
defer_connect=True,
)
assert create_default_context.called
assert not dummy_ssl_context.check_hostname
Expand All @@ -662,14 +667,15 @@ def test_ssl_connect(self):

for ssl_verify_cert in (True, "1", "yes", "true"):
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
with mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
pymysql.connect(
ssl_cert="cert",
ssl_key="key",
ssl_verify_cert=ssl_verify_cert,
defer_connect=True,
)
assert create_default_context.called
assert not dummy_ssl_context.check_hostname
Expand All @@ -683,14 +689,15 @@ def test_ssl_connect(self):

for ssl_verify_cert in (None, False, "0", "no", "false"):
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
with mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
pymysql.connect(
ssl_cert="cert",
ssl_key="key",
ssl_verify_cert=ssl_verify_cert,
defer_connect=True,
)
assert create_default_context.called
assert not dummy_ssl_context.check_hostname
Expand All @@ -705,7 +712,7 @@ def test_ssl_connect(self):
for ssl_ca in ("ca", None):
for ssl_verify_cert in ("foo", "bar", ""):
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
with mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -714,6 +721,7 @@ def test_ssl_connect(self):
ssl_cert="cert",
ssl_key="key",
ssl_verify_cert=ssl_verify_cert,
defer_connect=True,
)
assert create_default_context.called
assert not dummy_ssl_context.check_hostname
Expand All @@ -728,7 +736,7 @@ def test_ssl_connect(self):
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
with mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -737,6 +745,7 @@ def test_ssl_connect(self):
ssl_cert="cert",
ssl_key="key",
ssl_verify_identity=True,
defer_connect=True,
)
assert create_default_context.called
assert dummy_ssl_context.check_hostname
Expand All @@ -749,7 +758,7 @@ def test_ssl_connect(self):
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
with mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -759,6 +768,7 @@ def test_ssl_connect(self):
ssl_key="key",
ssl_key_password="password",
ssl_verify_identity=True,
defer_connect=True,
)
assert create_default_context.called
assert dummy_ssl_context.check_hostname
Expand All @@ -771,7 +781,7 @@ def test_ssl_connect(self):
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
with mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -782,11 +792,12 @@ def test_ssl_connect(self):
"cert": "cert",
"key": "key",
},
defer_connect=True,
)
assert not create_default_context.called

dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
with mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
) as create_default_context:
Expand All @@ -795,6 +806,7 @@ def test_ssl_connect(self):
ssl_ca="ca",
ssl_cert="cert",
ssl_key="key",
defer_connect=True,
)
assert not create_default_context.called

Expand Down