From b8129a49a2913fcc20eb450fa3ffcee2c5ed8e44 Mon Sep 17 00:00:00 2001 From: lambdalisue Date: Fri, 11 Sep 2015 15:27:13 +0900 Subject: [PATCH] Add 'supplement' test for 'user_registered' signal --- src/registration/tests/test_backends.py | 34 ++++++++++++++++++++++ src/registration/tests/test_supplements.py | 11 +------ src/registration/tests/utils.py | 13 +++++++++ 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/registration/tests/test_backends.py b/src/registration/tests/test_backends.py index cef8695..77ba210 100644 --- a/src/registration/tests/test_backends.py +++ b/src/registration/tests/test_backends.py @@ -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 @@ -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') diff --git a/src/registration/tests/test_supplements.py b/src/registration/tests/test_supplements.py index 767d8cb..5546646 100644 --- a/src/registration/tests/test_supplements.py +++ b/src/registration/tests/test_supplements.py @@ -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): diff --git a/src/registration/tests/utils.py b/src/registration/tests/utils.py index 6814005..b6b0a4c 100644 --- a/src/registration/tests/utils.py +++ b/src/registration/tests/utils.py @@ -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)) + +