@@ 232-262 (lines=31) @@ | ||
229 | self.assertEqual(len(received_signals), 1) |
|
230 | self.assertEqual(received_signals, [signals.user_registered]) |
|
231 | ||
232 | @with_apps( |
|
233 | 'django.contrib.contenttypes', |
|
234 | 'registration.supplements.default' |
|
235 | ) |
|
236 | @override_settings( |
|
237 | REGISTRATION_SUPPLEMENT_CLASS=( |
|
238 | 'registration.supplements.default.models.DefaultRegistrationSupplement'), |
|
239 | ) |
|
240 | def test_registration_signal_with_supplement(self): |
|
241 | from registration.supplements.default.models import DefaultRegistrationSupplement |
|
242 | supplement = DefaultRegistrationSupplement(remarks='foo') |
|
243 | ||
244 | def receiver(sender, user, profile, **kwargs): |
|
245 | self.assertEqual(user.username, 'bob') |
|
246 | self.assertEqual(user.registration_profile, profile) |
|
247 | self.assertEqual(user.registration_profile.supplement, |
|
248 | profile.supplement) |
|
249 | self.assertEqual(profile.supplement.remarks, 'foo') |
|
250 | received_signals.append(kwargs.get('signal')) |
|
251 | ||
252 | received_signals = [] |
|
253 | signals.user_registered.connect(receiver, sender=self.backend.__class__) |
|
254 | ||
255 | self.backend.register( |
|
256 | username='bob', email='[email protected]', |
|
257 | request=self.mock_request, |
|
258 | supplement=supplement, |
|
259 | ) |
|
260 | ||
261 | self.assertEqual(len(received_signals), 1) |
|
262 | self.assertEqual(received_signals, [signals.user_registered]) |
|
263 | ||
264 | ||
265 | def test_acceptance_signal(self): |
|
@@ 281-297 (lines=17) @@ | ||
278 | self.assertEqual(len(received_signals), 1) |
|
279 | self.assertEqual(received_signals, [signals.user_accepted]) |
|
280 | ||
281 | def test_acceptance_signal_fail(self): |
|
282 | def receiver(sender, user, profile, **kwargs): |
|
283 | self.assertEqual(user.username, 'bob') |
|
284 | self.assertEqual(user.registration_profile, profile) |
|
285 | received_signals.append(kwargs.get('signal')) |
|
286 | ||
287 | received_signals = [] |
|
288 | ||
289 | self.backend.register(username='bob', email='[email protected]', request=self.mock_request) |
|
290 | profile = RegistrationProfile.objects.get(user__username='bob') |
|
291 | self.backend.accept(profile, request=self.mock_request) |
|
292 | ||
293 | signals.user_accepted.connect(receiver, sender=self.backend.__class__) |
|
294 | # accept -> accept is not allowed thus fail |
|
295 | self.backend.accept(profile, request=self.mock_request) |
|
296 | ||
297 | self.assertEqual(len(received_signals), 0) |
|
298 | ||
299 | def test_rejection_signal(self): |
|
300 | def receiver(sender, user, profile, **kwargs): |
|
@@ 315-330 (lines=16) @@ | ||
312 | self.assertEqual(len(received_signals), 1) |
|
313 | self.assertEqual(received_signals, [signals.user_rejected]) |
|
314 | ||
315 | def test_rejection_signal_fail(self): |
|
316 | def receiver(sender, user, profile, **kwargs): |
|
317 | self.assertEqual(user.username, 'bob') |
|
318 | self.assertEqual(user.registration_profile, profile) |
|
319 | received_signals.append(kwargs.get('signal')) |
|
320 | ||
321 | received_signals = [] |
|
322 | signals.user_rejected.connect(receiver, sender=self.backend.__class__) |
|
323 | ||
324 | self.backend.register(username='bob', email='[email protected]', request=self.mock_request) |
|
325 | profile = RegistrationProfile.objects.get(user__username='bob') |
|
326 | self.backend.accept(profile, request=self.mock_request) |
|
327 | # accept -> reject is not allowed |
|
328 | self.backend.reject(profile, request=self.mock_request) |
|
329 | ||
330 | self.assertEqual(len(received_signals), 0) |
|
331 | ||
332 | def test_activation_signal(self): |
|
333 | def receiver(sender, user, password, is_generated, **kwargs): |
|
@@ 299-313 (lines=15) @@ | ||
296 | ||
297 | self.assertEqual(len(received_signals), 0) |
|
298 | ||
299 | def test_rejection_signal(self): |
|
300 | def receiver(sender, user, profile, **kwargs): |
|
301 | self.assertEqual(user.username, 'bob') |
|
302 | self.assertEqual(user.registration_profile, profile) |
|
303 | received_signals.append(kwargs.get('signal')) |
|
304 | ||
305 | received_signals = [] |
|
306 | signals.user_rejected.connect(receiver, sender=self.backend.__class__) |
|
307 | ||
308 | self.backend.register(username='bob', email='[email protected]', request=self.mock_request) |
|
309 | profile = RegistrationProfile.objects.get(user__username='bob') |
|
310 | self.backend.reject(profile, request=self.mock_request) |
|
311 | ||
312 | self.assertEqual(len(received_signals), 1) |
|
313 | self.assertEqual(received_signals, [signals.user_rejected]) |
|
314 | ||
315 | def test_rejection_signal_fail(self): |
|
316 | def receiver(sender, user, profile, **kwargs): |
|
@@ 265-279 (lines=15) @@ | ||
262 | self.assertEqual(received_signals, [signals.user_registered]) |
|
263 | ||
264 | ||
265 | def test_acceptance_signal(self): |
|
266 | def receiver(sender, user, profile, **kwargs): |
|
267 | self.assertEqual(user.username, 'bob') |
|
268 | self.assertEqual(user.registration_profile, profile) |
|
269 | received_signals.append(kwargs.get('signal')) |
|
270 | ||
271 | received_signals = [] |
|
272 | signals.user_accepted.connect(receiver, sender=self.backend.__class__) |
|
273 | ||
274 | self.backend.register(username='bob', email='[email protected]', request=self.mock_request) |
|
275 | profile = RegistrationProfile.objects.get(user__username='bob') |
|
276 | self.backend.accept(profile, request=self.mock_request) |
|
277 | ||
278 | self.assertEqual(len(received_signals), 1) |
|
279 | self.assertEqual(received_signals, [signals.user_accepted]) |
|
280 | ||
281 | def test_acceptance_signal_fail(self): |
|
282 | def receiver(sender, user, profile, **kwargs): |