Statistics
| Branch: | Tag: | Revision:

root / social / tests / actions / test_disconnect.py @ a0a04c0a

History | View | Annotate | Download (2.1 kB)

1
import requests
2

    
3
from sure import expect
4
from httpretty import HTTPretty
5

    
6
from social.actions import do_disconnect
7
from social.exceptions import NotAllowedToDisconnect
8
from social.utils import parse_qs
9

    
10
from social.tests.models import User
11
from social.tests.actions.actions import BaseActionTest
12

    
13

    
14
class DisconnectActionTest(BaseActionTest):
15
    def test_not_allowed_to_disconnect(self):
16
        self.do_login()
17
        user = User.get(self.expected_username)
18
        do_disconnect.when.called_with(self.backend, user).should.throw(
19
            NotAllowedToDisconnect
20
        )
21

    
22
    def test_disconnect(self):
23
        self.do_login()
24
        user = User.get(self.expected_username)
25
        user.password = 'password'
26
        do_disconnect(self.backend, user)
27
        expect(len(user.social)).to.equal(0)
28

    
29
    def test_disconnect_with_partial_pipeline(self):
30
        self.strategy.set_settings({
31
            'SOCIAL_AUTH_DISCONNECT_PIPELINE': (
32
                'social.pipeline.partial.save_status_to_session',
33
                'social.tests.pipeline.ask_for_password',
34
                'social.tests.pipeline.set_password',
35
                'social.pipeline.disconnect.allowed_to_disconnect',
36
                'social.pipeline.disconnect.get_entries',
37
                'social.pipeline.disconnect.revoke_tokens',
38
                'social.pipeline.disconnect.disconnect'
39
            )
40
        })
41
        self.do_login()
42
        user = User.get(self.expected_username)
43
        redirect = do_disconnect(self.backend, user)
44

    
45
        url = self.strategy.build_absolute_uri('/password')
46
        expect(redirect.url).to.equal(url)
47
        HTTPretty.register_uri(HTTPretty.GET, redirect.url, status=200,
48
                               body='foobar')
49
        HTTPretty.register_uri(HTTPretty.POST, redirect.url, status=200)
50

    
51
        password = 'foobar'
52
        requests.get(url)
53
        requests.post(url, data={'password': password})
54
        data = parse_qs(HTTPretty.last_request.body)
55
        expect(data['password']).to.equal(password)
56
        self.strategy.session_set('password', data['password'])
57

    
58
        redirect = do_disconnect(self.backend, user)
59
        expect(len(user.social)).to.equal(0)