~ubuntu-branches/debian/sid/social-auth-core/sid

« back to all changes in this revision

Viewing changes to social_core/tests/actions/test_login.py

  • Committer: Package Import Robot
  • Author(s): Andre Bianchi
  • Date: 2018-02-22 19:49:12 UTC
  • Revision ID: package-import@ubuntu.com-20180222194912-4lqv8mlhnqc4ncd3
Tags: upstream-1.7.0
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from ..models import User
 
2
from .actions import BaseActionTest
 
3
 
 
4
 
 
5
class LoginActionTest(BaseActionTest):
 
6
    def test_login(self):
 
7
        self.do_login()
 
8
 
 
9
    def test_login_with_partial_pipeline(self):
 
10
        self.do_login_with_partial_pipeline()
 
11
 
 
12
    def test_fields_stored_in_session(self):
 
13
        self.strategy.set_settings({
 
14
            'SOCIAL_AUTH_FIELDS_STORED_IN_SESSION': ['foo', 'bar']
 
15
        })
 
16
        self.strategy.set_request_data({'foo': '1', 'bar': '2'}, self.backend)
 
17
        self.do_login()
 
18
        self.assertEqual(self.strategy.session_get('foo'), '1')
 
19
        self.assertEqual(self.strategy.session_get('bar'), '2')
 
20
 
 
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')
 
25
 
 
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)
 
32
 
 
33
    def test_new_user(self):
 
34
        self.strategy.set_settings({
 
35
            'SOCIAL_AUTH_NEW_USER_REDIRECT_URL': '/new-user'
 
36
        })
 
37
        redirect = self.do_login(after_complete_checks=False)
 
38
        self.assertEqual(redirect.url, '/new-user')
 
39
 
 
40
    def test_inactive_user(self):
 
41
        self.strategy.set_settings({
 
42
            'SOCIAL_AUTH_INACTIVE_USER_URL': '/inactive'
 
43
        })
 
44
        User.set_active(False)
 
45
        redirect = self.do_login(after_complete_checks=False)
 
46
        self.assertEqual(redirect.url, '/inactive')
 
47
 
 
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'
 
62
            )
 
63
        })
 
64
        redirect = self.do_login(after_complete_checks=False)
 
65
        self.assertEqual(redirect.url, '/error')