Browse Source

Add unit tests for sending emails

sh4nks 9 years ago
parent
commit
fd5bf46ba6
1 changed files with 27 additions and 0 deletions
  1. 27 0
      tests/unit/test_email.py

+ 27 - 0
tests/unit/test_email.py

@@ -0,0 +1,27 @@
+from flask import current_app
+from flaskbb.extensions import mail
+from flaskbb.email import send_reset_token, send_activation_token
+
+
+def test_send_reset_token_to_user(default_settings, user):
+    """ Deliver a contact email. """
+
+    with current_app.test_request_context():
+        with mail.record_messages() as outbox:
+            send_reset_token(user)
+
+            assert len(outbox) == 1
+            assert "/auth/reset-password" in outbox[0].body  # from /auth/reset-password/<token>
+            assert "/auth/reset-password" in outbox[0].html
+
+
+def test_send_activation_token_to_user(default_settings, user):
+    """ Deliver a contact email. """
+
+    with current_app.test_request_context():
+        with mail.record_messages() as outbox:
+            send_activation_token(user)
+
+            assert len(outbox) == 1
+            assert "/auth/activate" in outbox[0].body  # from /auth/activate/<token>
+            assert "/auth/activate" in outbox[0].html