mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	test_email_change: User create_confirmation_link for url.
This is a prep refactor, instead of creating Confirmation object and using `confirmation_url` for generating confirmation link/url, using `create_confirmation_link` would be a cleaner approach, also this can help us avoid failing test in case Confirmation model is changed. Part of #16359.
This commit is contained in:
		@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user