File: test_exceptions.py

package info (click to toggle)
python-social-auth 0.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,828 kB
  • ctags: 3,245
  • sloc: python: 12,867; makefile: 119; sh: 3
file content (89 lines) | stat: -rw-r--r-- 2,914 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import unittest
from sure import expect

from social.exceptions import SocialAuthBaseException, WrongBackend, \
                              AuthFailed, AuthTokenError, \
                              AuthMissingParameter, AuthStateMissing, \
                              NotAllowedToDisconnect, AuthException, \
                              AuthCanceled, AuthUnknownError, \
                              AuthStateForbidden, AuthAlreadyAssociated, \
                              AuthTokenRevoked


class BaseExceptionTestCase(unittest.TestCase):
    exception = None
    expected_message = ''

    def test_exception_message(self):
        if self.exception is None and self.expected_message == '':
            return
        try:
            raise self.exception
        except SocialAuthBaseException as err:
            expect(str(err)).to.equal(self.expected_message)


class WrongBackendTest(BaseExceptionTestCase):
    exception = WrongBackend('foobar')
    expected_message = 'Incorrect authentication service "foobar"'


class AuthFailedTest(BaseExceptionTestCase):
    exception = AuthFailed('foobar', 'wrong_user')
    expected_message = 'Authentication failed: wrong_user'


class AuthFailedDeniedTest(BaseExceptionTestCase):
    exception = AuthFailed('foobar', 'access_denied')
    expected_message = 'Authentication process was canceled'


class AuthTokenErrorTest(BaseExceptionTestCase):
    exception = AuthTokenError('foobar', 'Incorrect tokens')
    expected_message = 'Token error: Incorrect tokens'


class AuthMissingParameterTest(BaseExceptionTestCase):
    exception = AuthMissingParameter('foobar', 'username')
    expected_message = 'Missing needed parameter username'


class AuthStateMissingTest(BaseExceptionTestCase):
    exception = AuthStateMissing('foobar')
    expected_message = 'Session value state missing.'


class NotAllowedToDisconnectTest(BaseExceptionTestCase):
    exception = NotAllowedToDisconnect()
    expected_message = ''


class AuthExceptionTest(BaseExceptionTestCase):
    exception = AuthException('foobar', 'message')
    expected_message = 'message'


class AuthCanceledTest(BaseExceptionTestCase):
    exception = AuthCanceled('foobar')
    expected_message = 'Authentication process canceled'


class AuthUnknownErrorTest(BaseExceptionTestCase):
    exception = AuthUnknownError('foobar', 'some error')
    expected_message = 'An unknown error happened while ' \
                       'authenticating some error'


class AuthStateForbiddenTest(BaseExceptionTestCase):
    exception = AuthStateForbidden('foobar')
    expected_message = 'Wrong state parameter given.'


class AuthAlreadyAssociatedTest(BaseExceptionTestCase):
    exception = AuthAlreadyAssociated('foobar')
    expected_message = ''


class AuthTokenRevokedTest(BaseExceptionTestCase):
    exception = AuthTokenRevoked('foobar')
    expected_message = 'User revoke access to the token'