summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego GuimarĂ£es <diegobr.sistemas@gmail.com>2014-12-05 14:15:33 -0200
committerTim Graham <timograham@gmail.com>2014-12-06 12:06:06 -0500
commite32a8a99d99c3d6c3015e220f6719f6ddc48b4f1 (patch)
treef1b23f31dea8d6e935c6353fdcb738ef6a565a95
parent5281d9620d13386fd4403f7aa6b9a2afd9b5a93f (diff)
Refs #23947 -- Isolated a mail test.
-rw-r--r--tests/mail/tests.py45
1 files changed, 28 insertions, 17 deletions
diff --git a/tests/mail/tests.py b/tests/mail/tests.py
index e4b568939c..5b5c9e1c70 100644
--- a/tests/mail/tests.py
+++ b/tests/mail/tests.py
@@ -886,12 +886,11 @@ class FakeSMTPServer(smtpd.SMTPServer, threading.Thread):
self.join()
-class SMTPBackendTests(BaseEmailBackendTests, SimpleTestCase):
- email_backend = 'django.core.mail.backends.smtp.EmailBackend'
+class SMTPBackendTestsBase(SimpleTestCase):
@classmethod
def setUpClass(cls):
- super(SMTPBackendTests, cls).setUpClass()
+ super(SMTPBackendTestsBase, cls).setUpClass()
cls.server = FakeSMTPServer(('127.0.0.1', 0), None)
cls._settings_override = override_settings(
EMAIL_HOST="127.0.0.1",
@@ -903,7 +902,11 @@ class SMTPBackendTests(BaseEmailBackendTests, SimpleTestCase):
def tearDownClass(cls):
cls._settings_override.disable()
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):
super(SMTPBackendTests, self).setUp()
@@ -966,19 +969,6 @@ class SMTPBackendTests(BaseEmailBackendTests, SimpleTestCase):
backend.close()
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)
def test_email_tls_use_settings(self):
backend = smtp.EmailBackend()
@@ -1110,3 +1100,24 @@ class SMTPBackendTests(BaseEmailBackendTests, SimpleTestCase):
finally:
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)