1
from ..models import User
2
from .actions import BaseActionTest
5
class LoginActionTest(BaseActionTest):
9
def test_login_with_partial_pipeline(self):
10
self.do_login_with_partial_pipeline()
12
def test_fields_stored_in_session(self):
13
self.strategy.set_settings({
14
'SOCIAL_AUTH_FIELDS_STORED_IN_SESSION': ['foo', 'bar']
16
self.strategy.set_request_data({'foo': '1', 'bar': '2'}, self.backend)
18
self.assertEqual(self.strategy.session_get('foo'), '1')
19
self.assertEqual(self.strategy.session_get('bar'), '2')
21
def test_redirect_value(self):
22
self.strategy.set_request_data({'next': '/after-login'}, self.backend)
23
redirect = self.do_login(after_complete_checks=False)
24
self.assertEqual(redirect.url, '/after-login')
26
def test_login_with_invalid_partial_pipeline(self):
27
def before_complete():
28
partial_token = self.strategy.session_get('partial_pipeline_token')
29
partial = self.strategy.storage.partial.load(partial_token)
30
partial.data['backend'] = 'foobar'
31
self.do_login_with_partial_pipeline(before_complete)
33
def test_new_user(self):
34
self.strategy.set_settings({
35
'SOCIAL_AUTH_NEW_USER_REDIRECT_URL': '/new-user'
37
redirect = self.do_login(after_complete_checks=False)
38
self.assertEqual(redirect.url, '/new-user')
40
def test_inactive_user(self):
41
self.strategy.set_settings({
42
'SOCIAL_AUTH_INACTIVE_USER_URL': '/inactive'
44
User.set_active(False)
45
redirect = self.do_login(after_complete_checks=False)
46
self.assertEqual(redirect.url, '/inactive')
48
def test_invalid_user(self):
49
self.strategy.set_settings({
50
'SOCIAL_AUTH_LOGIN_ERROR_URL': '/error',
51
'SOCIAL_AUTH_PIPELINE': (
52
'social_core.pipeline.social_auth.social_details',
53
'social_core.pipeline.social_auth.social_uid',
54
'social_core.pipeline.social_auth.auth_allowed',
55
'social_core.pipeline.social_auth.social_user',
56
'social_core.pipeline.user.get_username',
57
'social_core.pipeline.user.create_user',
58
'social_core.pipeline.social_auth.associate_user',
59
'social_core.pipeline.social_auth.load_extra_data',
60
'social_core.pipeline.user.user_details',
61
'social_core.tests.pipeline.remove_user'
64
redirect = self.do_login(after_complete_checks=False)
65
self.assertEqual(redirect.url, '/error')