root / social / tests / actions / test_disconnect.py @ a0a04c0a
History | View | Annotate | Download (2.1 kB)
1 | a0a04c0a | Kroustouris Stauros | import requests |
---|---|---|---|
2 | a0a04c0a | Kroustouris Stauros | |
3 | a0a04c0a | Kroustouris Stauros | from sure import expect |
4 | a0a04c0a | Kroustouris Stauros | from httpretty import HTTPretty |
5 | a0a04c0a | Kroustouris Stauros | |
6 | a0a04c0a | Kroustouris Stauros | from social.actions import do_disconnect |
7 | a0a04c0a | Kroustouris Stauros | from social.exceptions import NotAllowedToDisconnect |
8 | a0a04c0a | Kroustouris Stauros | from social.utils import parse_qs |
9 | a0a04c0a | Kroustouris Stauros | |
10 | a0a04c0a | Kroustouris Stauros | from social.tests.models import User |
11 | a0a04c0a | Kroustouris Stauros | from social.tests.actions.actions import BaseActionTest |
12 | a0a04c0a | Kroustouris Stauros | |
13 | a0a04c0a | Kroustouris Stauros | |
14 | a0a04c0a | Kroustouris Stauros | class DisconnectActionTest(BaseActionTest): |
15 | a0a04c0a | Kroustouris Stauros | def test_not_allowed_to_disconnect(self): |
16 | a0a04c0a | Kroustouris Stauros | self.do_login()
|
17 | a0a04c0a | Kroustouris Stauros | user = User.get(self.expected_username)
|
18 | a0a04c0a | Kroustouris Stauros | do_disconnect.when.called_with(self.backend, user).should.throw(
|
19 | a0a04c0a | Kroustouris Stauros | NotAllowedToDisconnect |
20 | a0a04c0a | Kroustouris Stauros | ) |
21 | a0a04c0a | Kroustouris Stauros | |
22 | a0a04c0a | Kroustouris Stauros | def test_disconnect(self): |
23 | a0a04c0a | Kroustouris Stauros | self.do_login()
|
24 | a0a04c0a | Kroustouris Stauros | user = User.get(self.expected_username)
|
25 | a0a04c0a | Kroustouris Stauros | user.password = 'password'
|
26 | a0a04c0a | Kroustouris Stauros | do_disconnect(self.backend, user)
|
27 | a0a04c0a | Kroustouris Stauros | expect(len(user.social)).to.equal(0) |
28 | a0a04c0a | Kroustouris Stauros | |
29 | a0a04c0a | Kroustouris Stauros | def test_disconnect_with_partial_pipeline(self): |
30 | a0a04c0a | Kroustouris Stauros | self.strategy.set_settings({
|
31 | a0a04c0a | Kroustouris Stauros | 'SOCIAL_AUTH_DISCONNECT_PIPELINE': (
|
32 | a0a04c0a | Kroustouris Stauros | 'social.pipeline.partial.save_status_to_session',
|
33 | a0a04c0a | Kroustouris Stauros | 'social.tests.pipeline.ask_for_password',
|
34 | a0a04c0a | Kroustouris Stauros | 'social.tests.pipeline.set_password',
|
35 | a0a04c0a | Kroustouris Stauros | 'social.pipeline.disconnect.allowed_to_disconnect',
|
36 | a0a04c0a | Kroustouris Stauros | 'social.pipeline.disconnect.get_entries',
|
37 | a0a04c0a | Kroustouris Stauros | 'social.pipeline.disconnect.revoke_tokens',
|
38 | a0a04c0a | Kroustouris Stauros | 'social.pipeline.disconnect.disconnect'
|
39 | a0a04c0a | Kroustouris Stauros | ) |
40 | a0a04c0a | Kroustouris Stauros | }) |
41 | a0a04c0a | Kroustouris Stauros | self.do_login()
|
42 | a0a04c0a | Kroustouris Stauros | user = User.get(self.expected_username)
|
43 | a0a04c0a | Kroustouris Stauros | redirect = do_disconnect(self.backend, user)
|
44 | a0a04c0a | Kroustouris Stauros | |
45 | a0a04c0a | Kroustouris Stauros | url = self.strategy.build_absolute_uri('/password') |
46 | a0a04c0a | Kroustouris Stauros | expect(redirect.url).to.equal(url) |
47 | a0a04c0a | Kroustouris Stauros | HTTPretty.register_uri(HTTPretty.GET, redirect.url, status=200,
|
48 | a0a04c0a | Kroustouris Stauros | body='foobar')
|
49 | a0a04c0a | Kroustouris Stauros | HTTPretty.register_uri(HTTPretty.POST, redirect.url, status=200)
|
50 | a0a04c0a | Kroustouris Stauros | |
51 | a0a04c0a | Kroustouris Stauros | password = 'foobar'
|
52 | a0a04c0a | Kroustouris Stauros | requests.get(url) |
53 | a0a04c0a | Kroustouris Stauros | requests.post(url, data={'password': password})
|
54 | a0a04c0a | Kroustouris Stauros | data = parse_qs(HTTPretty.last_request.body) |
55 | a0a04c0a | Kroustouris Stauros | expect(data['password']).to.equal(password)
|
56 | a0a04c0a | Kroustouris Stauros | self.strategy.session_set('password', data['password']) |
57 | a0a04c0a | Kroustouris Stauros | |
58 | a0a04c0a | Kroustouris Stauros | redirect = do_disconnect(self.backend, user)
|
59 | a0a04c0a | Kroustouris Stauros | expect(len(user.social)).to.equal(0) |