Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

test_email_change: User create_confirmation_link for url.

shanukun5cee9dee125c
diff --git a/zerver/tests/test_email_change.py b/zerver/tests/test_email_change.py
index 236b8bf7a05..6c5d3fc7d66 100644
--- a/zerver/tests/test_email_change.py
+++ b/zerver/tests/test_email_change.py
@@ -1,10 +1,16 @@
import datetime
+from unittest import mock
from django.conf import settings
from django.core import mail
from django.utils.timezone import now
-from confirmation.models import Confirmation, confirmation_url, generate_key
+from confirmation.models import (
+ Confirmation,
+ confirmation_url,
+ create_confirmation_link,
+ generate_key,
+)
from zerver.lib.actions import do_set_realm_property, do_start_email_change_process
from zerver.lib.test_classes import ZulipTestCase
from zerver.models import (
@@ -46,15 +52,10 @@ class EmailChangeTestCase(ZulipTestCase):
user_profile=user_profile,
realm=user_profile.realm,
)
- key = generate_key()
date_sent = now() - datetime.timedelta(days=2)
- Confirmation.objects.create(
- content_object=obj,
- date_sent=date_sent,
- confirmation_key=key,
- type=Confirmation.EMAIL_CHANGE,
- )
- url = confirmation_url(key, user_profile.realm, Confirmation.EMAIL_CHANGE)
+ with mock.patch("confirmation.models.timezone_now", return_value=date_sent):
+ url = create_confirmation_link(obj, Confirmation.EMAIL_CHANGE)
+
response = self.client_get(url)
self.assert_in_success_response(
["The confirmation link has expired or been deactivated."], response
@@ -79,14 +80,7 @@ class EmailChangeTestCase(ZulipTestCase):
user_profile=user_profile,
realm=user_profile.realm,
)
- key = generate_key()
- Confirmation.objects.create(
- content_object=obj,
- date_sent=now(),
- confirmation_key=key,
- type=Confirmation.EMAIL_CHANGE,
- )
- url = confirmation_url(key, user_profile.realm, Confirmation.EMAIL_CHANGE)
+ url = create_confirmation_link(obj, Confirmation.EMAIL_CHANGE)
response = self.client_get(url)
self.assertEqual(response.status_code, 200)
@@ -233,14 +227,7 @@ class EmailChangeTestCase(ZulipTestCase):
user_profile=user_profile,
realm=user_profile.realm,
)
- key = generate_key()
- Confirmation.objects.create(
- content_object=obj,
- date_sent=now(),
- confirmation_key=key,
- type=Confirmation.EMAIL_CHANGE,
- )
- url = confirmation_url(key, user_profile.realm, Confirmation.EMAIL_CHANGE)
+ url = create_confirmation_link(obj, Confirmation.EMAIL_CHANGE)
response = self.client_get(url)
self.assertEqual(response.status_code, 200)