refactor: use defer_connect instead of mock (#1199) · PyMySQL/PyMySQL@5f6533f · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit 5f6533f

Browse files
authored
refactor: use defer_connect instead of mock (#1199)
1 parent 66ad1ea commit 5f6533f

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

pymysql/tests/test_connection.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ def test_defer_connect(self):
559559

560560
def test_ssl_connect(self):
561561
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
562-
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
562+
with mock.patch(
563563
"pymysql.connections.ssl.create_default_context",
564564
new=mock.Mock(return_value=dummy_ssl_context),
565565
) as create_default_context:
@@ -570,6 +570,7 @@ def test_ssl_connect(self):
570570
"key": "key",
571571
"cipher": "cipher",
572572
},
573+
defer_connect=True,
573574
)
574575
assert create_default_context.called
575576
assert dummy_ssl_context.check_hostname
@@ -582,7 +583,7 @@ def test_ssl_connect(self):
582583
dummy_ssl_context.set_ciphers.assert_called_with("cipher")
583584

584585
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
585-
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
586+
with mock.patch(
586587
"pymysql.connections.ssl.create_default_context",
587588
new=mock.Mock(return_value=dummy_ssl_context),
588589
) as create_default_context:
@@ -592,6 +593,7 @@ def test_ssl_connect(self):
592593
"cert": "cert",
593594
"key": "key",
594595
},
596+
defer_connect=True,
595597
)
596598
assert create_default_context.called
597599
assert dummy_ssl_context.check_hostname
@@ -604,7 +606,7 @@ def test_ssl_connect(self):
604606
dummy_ssl_context.set_ciphers.assert_not_called
605607

606608
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
607-
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
609+
with mock.patch(
608610
"pymysql.connections.ssl.create_default_context",
609611
new=mock.Mock(return_value=dummy_ssl_context),
610612
) as create_default_context:
@@ -615,6 +617,7 @@ def test_ssl_connect(self):
615617
"key": "key",
616618
"password": "password",
617619
},
620+
defer_connect=True,
618621
)
619622
assert create_default_context.called
620623
assert dummy_ssl_context.check_hostname
@@ -627,12 +630,13 @@ def test_ssl_connect(self):
627630
dummy_ssl_context.set_ciphers.assert_not_called
628631

629632
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
630-
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
633+
with mock.patch(
631634
"pymysql.connections.ssl.create_default_context",
632635
new=mock.Mock(return_value=dummy_ssl_context),
633636
) as create_default_context:
634637
pymysql.connect(
635638
ssl_ca="ca",
639+
defer_connect=True,
636640
)
637641
assert create_default_context.called
638642
assert not dummy_ssl_context.check_hostname
@@ -641,14 +645,15 @@ def test_ssl_connect(self):
641645
dummy_ssl_context.set_ciphers.assert_not_called
642646

643647
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
644-
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
648+
with mock.patch(
645649
"pymysql.connections.ssl.create_default_context",
646650
new=mock.Mock(return_value=dummy_ssl_context),
647651
) as create_default_context:
648652
pymysql.connect(
649653
ssl_ca="ca",
650654
ssl_cert="cert",
651655
ssl_key="key",
656+
defer_connect=True,
652657
)
653658
assert create_default_context.called
654659
assert not dummy_ssl_context.check_hostname
@@ -662,14 +667,15 @@ def test_ssl_connect(self):
662667

663668
for ssl_verify_cert in (True, "1", "yes", "true"):
664669
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
665-
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
670+
with mock.patch(
666671
"pymysql.connections.ssl.create_default_context",
667672
new=mock.Mock(return_value=dummy_ssl_context),
668673
) as create_default_context:
669674
pymysql.connect(
670675
ssl_cert="cert",
671676
ssl_key="key",
672677
ssl_verify_cert=ssl_verify_cert,
678+
defer_connect=True,
673679
)
674680
assert create_default_context.called
675681
assert not dummy_ssl_context.check_hostname
@@ -683,14 +689,15 @@ def test_ssl_connect(self):
683689

684690
for ssl_verify_cert in (None, False, "0", "no", "false"):
685691
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
686-
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
692+
with mock.patch(
687693
"pymysql.connections.ssl.create_default_context",
688694
new=mock.Mock(return_value=dummy_ssl_context),
689695
) as create_default_context:
690696
pymysql.connect(
691697
ssl_cert="cert",
692698
ssl_key="key",
693699
ssl_verify_cert=ssl_verify_cert,
700+
defer_connect=True,
694701
)
695702
assert create_default_context.called
696703
assert not dummy_ssl_context.check_hostname
@@ -705,7 +712,7 @@ def test_ssl_connect(self):
705712
for ssl_ca in ("ca", None):
706713
for ssl_verify_cert in ("foo", "bar", ""):
707714
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
708-
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
715+
with mock.patch(
709716
"pymysql.connections.ssl.create_default_context",
710717
new=mock.Mock(return_value=dummy_ssl_context),
711718
) as create_default_context:
@@ -714,6 +721,7 @@ def test_ssl_connect(self):
714721
ssl_cert="cert",
715722
ssl_key="key",
716723
ssl_verify_cert=ssl_verify_cert,
724+
defer_connect=True,
717725
)
718726
assert create_default_context.called
719727
assert not dummy_ssl_context.check_hostname
@@ -728,7 +736,7 @@ def test_ssl_connect(self):
728736
dummy_ssl_context.set_ciphers.assert_not_called
729737

730738
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
731-
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
739+
with mock.patch(
732740
"pymysql.connections.ssl.create_default_context",
733741
new=mock.Mock(return_value=dummy_ssl_context),
734742
) as create_default_context:
@@ -737,6 +745,7 @@ def test_ssl_connect(self):
737745
ssl_cert="cert",
738746
ssl_key="key",
739747
ssl_verify_identity=True,
748+
defer_connect=True,
740749
)
741750
assert create_default_context.called
742751
assert dummy_ssl_context.check_hostname
@@ -749,7 +758,7 @@ def test_ssl_connect(self):
749758
dummy_ssl_context.set_ciphers.assert_not_called
750759

751760
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
752-
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
761+
with mock.patch(
753762
"pymysql.connections.ssl.create_default_context",
754763
new=mock.Mock(return_value=dummy_ssl_context),
755764
) as create_default_context:
@@ -759,6 +768,7 @@ def test_ssl_connect(self):
759768
ssl_key="key",
760769
ssl_key_password="password",
761770
ssl_verify_identity=True,
771+
defer_connect=True,
762772
)
763773
assert create_default_context.called
764774
assert dummy_ssl_context.check_hostname
@@ -771,7 +781,7 @@ def test_ssl_connect(self):
771781
dummy_ssl_context.set_ciphers.assert_not_called
772782

773783
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
774-
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
784+
with mock.patch(
775785
"pymysql.connections.ssl.create_default_context",
776786
new=mock.Mock(return_value=dummy_ssl_context),
777787
) as create_default_context:
@@ -782,11 +792,12 @@ def test_ssl_connect(self):
782792
"cert": "cert",
783793
"key": "key",
784794
},
795+
defer_connect=True,
785796
)
786797
assert not create_default_context.called
787798

788799
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
789-
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
800+
with mock.patch(
790801
"pymysql.connections.ssl.create_default_context",
791802
new=mock.Mock(return_value=dummy_ssl_context),
792803
) as create_default_context:
@@ -795,6 +806,7 @@ def test_ssl_connect(self):
795806
ssl_ca="ca",
796807
ssl_cert="cert",
797808
ssl_key="key",
809+
defer_connect=True,
798810
)
799811
assert not create_default_context.called
800812

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.