Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Commit

Permalink
Add 'supplement' test for 'user_registered' signal
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Sep 11, 2015
1 parent a5300c2 commit b8129a4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
34 changes: 34 additions & 0 deletions src/registration/tests/test_backends.py
Expand Up @@ -15,6 +15,7 @@
from registration.backends import get_backend
from registration.backends.default import DefaultRegistrationBackend
from registration.models import RegistrationProfile
from registration.tests.utils import with_apps
from registration.tests.mock import mock_request
from registration.tests.compat import override_settings

Expand Down Expand Up @@ -228,6 +229,39 @@ def receiver(sender, user, profile, **kwargs):
self.assertEqual(len(received_signals), 1)
self.assertEqual(received_signals, [signals.user_registered])

@with_apps(
'django.contrib.contenttypes',
'registration.supplements.default'
)
@override_settings(
REGISTRATION_SUPPLEMENT_CLASS=(
'registration.supplements.default.models.DefaultRegistrationSupplement'),
)
def test_registration_signal_with_supplement(self):
from registration.supplements.default.models import DefaultRegistrationSupplement
supplement = DefaultRegistrationSupplement(remarks='foo')

def receiver(sender, user, profile, **kwargs):
self.assertEqual(user.username, 'bob')
self.assertEqual(user.registration_profile, profile)
self.assertEqual(user.registration_profile.supplement,
profile.supplement)
self.assertEqual(profile.supplement.remarks, 'foo')
received_signals.append(kwargs.get('signal'))

received_signals = []
signals.user_registered.connect(receiver, sender=self.backend.__class__)

self.backend.register(
username='bob', email='bob@example.com',
request=self.mock_request,
supplement=supplement,
)

self.assertEqual(len(received_signals), 1)
self.assertEqual(received_signals, [signals.user_registered])


def test_acceptance_signal(self):
def receiver(sender, user, profile, **kwargs):
self.assertEqual(user.username, 'bob')
Expand Down
11 changes: 1 addition & 10 deletions src/registration/tests/test_supplements.py
Expand Up @@ -12,19 +12,10 @@
from registration.conf import settings
from registration.supplements import get_supplement_class
from registration.models import RegistrationProfile
from registration.tests.utils import with_apps
from registration.tests.compat import override_settings


def with_apps(*apps):
"""
Class decorator that makes sure the passed apps are present in
INSTALLED_APPS.
"""
apps_set = set(settings.INSTALLED_APPS)
apps_set.update(apps)
return override_settings(INSTALLED_APPS=list(apps_set))


class RegistrationSupplementRetrievalTests(TestCase):

def test_get_supplement_class(self):
Expand Down
13 changes: 13 additions & 0 deletions src/registration/tests/utils.py
Expand Up @@ -31,3 +31,16 @@ def clear_all_meta_caches():
from django.contrib.contenttypes.models import ContentType
for ct in ContentType.objects.iterator():
clear_meta_caches(ct.model_class())

def with_apps(*apps):
"""
Class decorator that makes sure the passed apps are present in
INSTALLED_APPS.
"""
from django.conf import settings
from registration.tests.compat import override_settings
apps_set = set(settings.INSTALLED_APPS)
apps_set.update(apps)
return override_settings(INSTALLED_APPS=list(apps_set))


0 comments on commit b8129a4

Please sign in to comment.