Browse Source

#453: tests for testmailsetup

Rafał Pitoń 10 years ago
parent
commit
f63d296f47
1 changed files with 43 additions and 0 deletions
  1. 43 0
      misago/core/tests/test_testmailsetup.py

+ 43 - 0
misago/core/tests/test_testmailsetup.py

@@ -0,0 +1,43 @@
+from django.core import mail
+from django.test import TestCase
+from django.utils.six import StringIO
+
+from misago.core.management.commands import testemailsetup
+
+
+class TestEmailSetupTests(TestCase):
+    def test_email_setup(self):
+        """command sets test email in outbox"""
+        command = testemailsetup.Command()
+
+        out = StringIO()
+        command.execute("t@mail.com", stdout=out)
+        command_output = out.getvalue().splitlines()[0].strip()
+
+        self.assertEqual(command_output, 'Test message was sent to t@mail.com')
+        self.assertEqual('Test Message', mail.outbox[0].subject)
+
+    def test_invalid_args(self):
+        """
+        there are no unhandled exceptions when command receives invalid args
+        """
+        command = testemailsetup.Command()
+
+        out = StringIO()
+        err = StringIO()
+
+        command.execute(stdout=out, stderr=err)
+        command_output = err.getvalue().splitlines()[-1].strip()
+        self.assertEqual(
+            command_output,
+            "Command accepts exactly one argument (e-mail address)")
+
+        command.execute("baww", "awww", stdout=out, stderr=err)
+        command_output = err.getvalue().splitlines()[-1].strip()
+        self.assertEqual(
+            command_output,
+            "Command accepts exactly one argument (e-mail address)")
+
+        command.execute("bawww", stdout=out, stderr=err)
+        command_output = err.getvalue().splitlines()[-1].strip()
+        self.assertEqual(command_output, "This isn't valid e-mail address")