Skip to content

Commit

Permalink
Update test_email_context to assert which elements should be present
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Etienne committed Mar 16, 2015
1 parent 21a373c commit ed0563f
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions user_management/models/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
import unittest

import django
from django.contrib.auth.tokens import default_token_generator
from django.contrib.sites.models import Site
from django.core import checks
from django.db.models import TextField
from django.db.utils import IntegrityError
from django.test import TestCase
from django.utils import six, timezone
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
from mock import Mock, patch

from user_management.models.tests import utils
Expand Down Expand Up @@ -181,19 +178,18 @@ def test_save(self):
self.assertTrue(user.email_verification_required)

def test_email_context(self):
user = self.model()
uid = urlsafe_base64_encode(force_bytes(user.pk))

notification = Mock()
notification.user = user
"""Assert `email_context` returns the correct data."""
class DummyNotification:
user = Mock()
site = Mock()

with patch.object(default_token_generator, 'make_token') as make_token:
context = email_context(notification)
notification = DummyNotification()
context = email_context(notification)

expected_context = {
'protocol': 'https',
'uid': uid,
'token': make_token(),
'uid': notification.user.generate_uid(),
'token': notification.user.generate_token(),
'site': notification.site,
}
self.assertEqual(context, expected_context)
Expand Down

2 comments on commit ed0563f

@kevinetienne
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ian-Foote is that what you had in mind?

@LilyFoote
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I might have defined user and site outside DummyNotification for simpler reference in expected_context, but that's a minor difference.

Please sign in to comment.