|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
from __future__ import unicode_literals |
|
3
|
|
|
""" |
|
4
|
|
|
""" |
|
5
|
|
|
__author__ = 'Alisue <[email protected]>' |
|
6
|
|
|
from django.test import TestCase |
|
7
|
|
|
from django.contrib.auth.models import AnonymousUser |
|
8
|
|
|
from registration.backends.default import DefaultRegistrationBackend |
|
9
|
|
|
from registration.tests.mock import mock_request |
|
10
|
|
|
from registration.tests.compat import override_settings |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
@override_settings( |
|
14
|
|
|
ACCOUNT_ACTIVATION_DAYS=7, |
|
15
|
|
|
REGISTRATION_OPEN=True, |
|
16
|
|
|
REGISTRATION_SUPPLEMENT_CLASS=None, |
|
17
|
|
|
REGISTRATION_BACKEND_CLASS=( |
|
18
|
|
|
'registration.backends.default.DefaultRegistrationBackend'), |
|
19
|
|
|
REGISTRATION_AUTO_LOGIN=True, |
|
20
|
|
|
_REGISTRATION_AUTO_LOGIN_IN_TESTS=True, |
|
21
|
|
|
) |
|
22
|
|
|
class RegistrationAutoLoginTestCase(TestCase): |
|
23
|
|
|
backend = DefaultRegistrationBackend() |
|
24
|
|
|
mock_request = mock_request() |
|
25
|
|
|
|
|
26
|
|
View Code Duplication |
def test_no_auto_login_with_setting(self): |
|
|
|
|
|
|
27
|
|
|
"""Auto login feature should be able to off with ``REGISTRATION_AUTO_LOGIN = False``""" |
|
28
|
|
|
self.mock_request.user = AnonymousUser() |
|
29
|
|
|
|
|
30
|
|
|
with override_settings(REGISTRATION_AUTO_LOGIN = False): |
|
31
|
|
|
|
|
32
|
|
|
new_user = self.backend.register( |
|
33
|
|
|
'bob', '[email protected]', request=self.mock_request, |
|
34
|
|
|
) |
|
35
|
|
|
self.backend.accept( |
|
36
|
|
|
new_user.registration_profile, request=self.mock_request, |
|
37
|
|
|
) |
|
38
|
|
|
self.backend.activate( |
|
39
|
|
|
new_user.registration_profile.activation_key, |
|
40
|
|
|
password='password',request=self.mock_request, |
|
41
|
|
|
) |
|
42
|
|
|
|
|
43
|
|
|
self.failIf(self.mock_request.user.is_authenticated()) |
|
44
|
|
|
|
|
45
|
|
View Code Duplication |
def test_no_auto_login_with_no_password(self): |
|
|
|
|
|
|
46
|
|
|
"""Auto login feature should not be occur with no password |
|
47
|
|
|
(programatically activated by Django Admin action) |
|
48
|
|
|
|
|
49
|
|
|
""" |
|
50
|
|
|
self.mock_request.user = AnonymousUser() |
|
51
|
|
|
|
|
52
|
|
|
new_user = self.backend.register( |
|
53
|
|
|
'bob', '[email protected]', request=self.mock_request, |
|
54
|
|
|
) |
|
55
|
|
|
self.backend.accept( |
|
56
|
|
|
new_user.registration_profile, request=self.mock_request, |
|
57
|
|
|
) |
|
58
|
|
|
self.backend.activate( |
|
59
|
|
|
new_user.registration_profile.activation_key, |
|
60
|
|
|
request=self.mock_request, |
|
61
|
|
|
) |
|
62
|
|
|
|
|
63
|
|
|
self.failIf(self.mock_request.user.is_authenticated()) |
|
64
|
|
|
|
|
65
|
|
View Code Duplication |
def test_auto_login(self): |
|
|
|
|
|
|
66
|
|
|
"""Wheather auto login feature works correctly""" |
|
67
|
|
|
self.mock_request.user = AnonymousUser() |
|
68
|
|
|
|
|
69
|
|
|
new_user = self.backend.register( |
|
70
|
|
|
'bob', '[email protected]', request=self.mock_request, |
|
71
|
|
|
) |
|
72
|
|
|
self.backend.accept( |
|
73
|
|
|
new_user.registration_profile, request=self.mock_request, |
|
74
|
|
|
) |
|
75
|
|
|
self.backend.activate( |
|
76
|
|
|
new_user.registration_profile.activation_key, |
|
77
|
|
|
password='password',request=self.mock_request, |
|
78
|
|
|
) |
|
79
|
|
|
|
|
80
|
|
|
self.failUnless(self.mock_request.user.is_authenticated()) |
|
81
|
|
|
|