Refs #23947 -- Isolated a mail test.
This commit is contained in:
parent
5281d9620d
commit
e32a8a99d9
|
@ -886,12 +886,11 @@ class FakeSMTPServer(smtpd.SMTPServer, threading.Thread):
|
||||||
self.join()
|
self.join()
|
||||||
|
|
||||||
|
|
||||||
class SMTPBackendTests(BaseEmailBackendTests, SimpleTestCase):
|
class SMTPBackendTestsBase(SimpleTestCase):
|
||||||
email_backend = 'django.core.mail.backends.smtp.EmailBackend'
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(SMTPBackendTests, cls).setUpClass()
|
super(SMTPBackendTestsBase, cls).setUpClass()
|
||||||
cls.server = FakeSMTPServer(('127.0.0.1', 0), None)
|
cls.server = FakeSMTPServer(('127.0.0.1', 0), None)
|
||||||
cls._settings_override = override_settings(
|
cls._settings_override = override_settings(
|
||||||
EMAIL_HOST="127.0.0.1",
|
EMAIL_HOST="127.0.0.1",
|
||||||
|
@ -903,7 +902,11 @@ class SMTPBackendTests(BaseEmailBackendTests, SimpleTestCase):
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
cls._settings_override.disable()
|
cls._settings_override.disable()
|
||||||
cls.server.stop()
|
cls.server.stop()
|
||||||
super(SMTPBackendTests, cls).tearDownClass()
|
super(SMTPBackendTestsBase, cls).tearDownClass()
|
||||||
|
|
||||||
|
|
||||||
|
class SMTPBackendTests(BaseEmailBackendTests, SMTPBackendTestsBase):
|
||||||
|
email_backend = 'django.core.mail.backends.smtp.EmailBackend'
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(SMTPBackendTests, self).setUp()
|
super(SMTPBackendTests, self).setUp()
|
||||||
|
@ -966,19 +969,6 @@ class SMTPBackendTests(BaseEmailBackendTests, SimpleTestCase):
|
||||||
backend.close()
|
backend.close()
|
||||||
self.assertTrue(opened)
|
self.assertTrue(opened)
|
||||||
|
|
||||||
def test_server_stopped(self):
|
|
||||||
"""
|
|
||||||
Test that closing the backend while the SMTP server is stopped doesn't
|
|
||||||
raise an exception.
|
|
||||||
"""
|
|
||||||
backend = smtp.EmailBackend(username='', password='')
|
|
||||||
backend.open()
|
|
||||||
self.server.stop()
|
|
||||||
try:
|
|
||||||
backend.close()
|
|
||||||
except Exception as e:
|
|
||||||
self.fail("close() unexpectedly raised an exception: %s" % e)
|
|
||||||
|
|
||||||
@override_settings(EMAIL_USE_TLS=True)
|
@override_settings(EMAIL_USE_TLS=True)
|
||||||
def test_email_tls_use_settings(self):
|
def test_email_tls_use_settings(self):
|
||||||
backend = smtp.EmailBackend()
|
backend = smtp.EmailBackend()
|
||||||
|
@ -1110,3 +1100,24 @@ class SMTPBackendTests(BaseEmailBackendTests, SimpleTestCase):
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
SMTP.send = send
|
SMTP.send = send
|
||||||
|
|
||||||
|
|
||||||
|
class SMTPBackendStoppedServerTest(SMTPBackendTestsBase):
|
||||||
|
"""
|
||||||
|
This test requires a separate class, because it shuts down the
|
||||||
|
FakeSMTPServer started in setUpClass(). It cannot be restarted
|
||||||
|
("RuntimeError: threads can only be started once").
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_server_stopped(self):
|
||||||
|
"""
|
||||||
|
Test that closing the backend while the SMTP server is stopped doesn't
|
||||||
|
raise an exception.
|
||||||
|
"""
|
||||||
|
backend = smtp.EmailBackend(username='', password='')
|
||||||
|
backend.open()
|
||||||
|
self.server.stop()
|
||||||
|
try:
|
||||||
|
backend.close()
|
||||||
|
except Exception as e:
|
||||||
|
self.fail("close() unexpectedly raised an exception: %s" % e)
|
||||||
|
|
Loading…
Reference in New Issue