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

« back to all changes in this revision

Viewing changes to social_core/tests/backends/test_yahoo.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
import json
 
2
import requests
 
3
from httpretty import HTTPretty
 
4
 
 
5
from six.moves.urllib_parse import urlencode
 
6
 
 
7
from .oauth import OAuth1Test
 
8
 
 
9
 
 
10
class YahooOAuth1Test(OAuth1Test):
 
11
    backend_path = 'social_core.backends.yahoo.YahooOAuth'
 
12
    user_data_url = 'https://social.yahooapis.com/v1/user/a-guid/profile?' \
 
13
                    'format=json'
 
14
    expected_username = 'foobar'
 
15
    access_token_body = json.dumps({
 
16
        'access_token': 'foobar',
 
17
        'token_type': 'bearer'
 
18
    })
 
19
    request_token_body = urlencode({
 
20
        'oauth_token_secret': 'foobar-secret',
 
21
        'oauth_token': 'foobar',
 
22
        'oauth_callback_confirmed': 'true'
 
23
    })
 
24
    guid_body = json.dumps({
 
25
        'guid': {
 
26
            'uri': 'https://social.yahooapis.com/v1/me/guid',
 
27
            'value': 'a-guid'
 
28
        }
 
29
    })
 
30
    user_data_body = json.dumps({
 
31
        'profile': {
 
32
            'bdRestricted': True,
 
33
            'memberSince': '2007-12-11T14:40:30Z',
 
34
            'image': {
 
35
                'width': 192,
 
36
                'imageUrl': 'http://l.yimg.com/dh/ap/social/profile/'
 
37
                            'profile_b192.png',
 
38
                'size': '192x192',
 
39
                'height': 192
 
40
            },
 
41
            'created': '2013-03-18T04:15:08Z',
 
42
            'uri': 'https://social.yahooapis.com/v1/user/a-guid/profile',
 
43
            'isConnected': False,
 
44
            'profileUrl': 'http://profile.yahoo.com/a-guid',
 
45
            'guid': 'a-guid',
 
46
            'nickname': 'foobar',
 
47
            'emails': [{
 
48
                'handle': 'foobar@yahoo.com',
 
49
                'id': 1,
 
50
                'primary': True,
 
51
                'type': 'HOME',
 
52
            }, {
 
53
                'handle': 'foobar@email.com',
 
54
                'id': 2,
 
55
                'type': 'HOME',
 
56
            }],
 
57
        }
 
58
    })
 
59
 
 
60
    def test_login(self):
 
61
        HTTPretty.register_uri(
 
62
            HTTPretty.GET,
 
63
            'https://social.yahooapis.com/v1/me/guid?format=json',
 
64
            status=200,
 
65
            body=self.guid_body
 
66
        )
 
67
        self.do_login()
 
68
 
 
69
    def test_partial_pipeline(self):
 
70
        self.do_partial_pipeline()
 
71
 
 
72
    def test_get_user_details(self):
 
73
        HTTPretty.register_uri(
 
74
            HTTPretty.GET,
 
75
            self.user_data_url,
 
76
            status=200,
 
77
            body=self.user_data_body
 
78
        )
 
79
        response = requests.get(self.user_data_url)
 
80
        user_details = self.backend.get_user_details(
 
81
            response.json()['profile']
 
82
        )
 
83
        self.assertEqual(user_details['email'], 'foobar@yahoo.com')