Debian Codegraph @

tests/apps/socialaccount/providers/flickr/tests.py

raw
1 from http import HTTPStatus
2
3 from django.test import TestCase
4
5 from allauth.socialaccount.models import SocialAccount
6 from allauth.socialaccount.providers.flickr.provider import FlickrProvider
7 from tests.apps.socialaccount.base import OAuthTestsMixin
8 from tests.mocking import MockedResponse
9
10
11 class FlickrTests(OAuthTestsMixin, TestCase):
12 provider_id = FlickrProvider.id
13
14 def get_mocked_response(self):
15 #
16 return [
17 MockedResponse(
18 HTTPStatus.OK,
19 r"""
20 {"stat": "ok",
21 "user": {
22 "username": {
23 "_content": "pennersr"},
24 "id": "12345678@N00"}}
25 """,
26 ), # noqa
27 MockedResponse(
28 HTTPStatus.OK,
29 r"""
30 {"person": {"username": {"_content": "pennersr"}, "photosurl": {"_content":
31 "http://www.flickr.com/photos/12345678@N00/"},
32 "nsid": "12345678@N00",
33 "path_alias": null, "photos": {"count": {"_content": 0},
34 "firstdatetaken": {"_content": null}, "views": {"_content": "28"},
35 "firstdate": {"_content": null}}, "iconserver": "0",
36 "description": {"_content": ""}, "mobileurl": {"_content":
37 "http://m.flickr.com/photostream.gne?id=6294613"},
38 "profileurl": {
39 "_content": "http://www.flickr.com/people/12345678@N00/"},
40 "mbox_sha1sum": {"_content":
41 "5e5b359c123e54f95236209c8808d607a5cdd21e"},
42 "ispro": 0, "location": {"_content": ""},
43 "id": "12345678@N00",
44 "realname": {"_content": "raymond penners"},
45 "iconfarm": 0}, "stat": "ok"}
46 """,
47 ),
48 ] # noqa
49
50 def get_expected_to_str(self):
51 return "pennersr"
52
53 def test_login(self):
54 super().test_login()
55 account = SocialAccount.objects.get(uid="12345678@N00")
56 f_account = account.get_provider_account()
57 self.assertEqual(account.user.first_name, "raymond")
58 self.assertEqual(account.user.last_name, "penners")
59 self.assertEqual(
60 f_account.get_profile_url(),
61 "http://www.flickr.com/people/12345678@N00/",
62 )
63 self.assertEqual(f_account.to_str(), "pennersr")
64
65
66 class FlickrWithoutRealNameTests(OAuthTestsMixin, TestCase):
67 """Separate test for Flickr accounts without real names"""
68
69 provider_id = FlickrProvider.id
70
71 def get_mocked_response(self):
72 #
73 return [
74 MockedResponse(
75 HTTPStatus.OK,
76 r"""
77 {"stat": "ok",
78 "user": {
79 "username": {
80 "_content": "pennersr"},
81 "id": "12345678@N00"}}
82 """,
83 ), # noqa
84 MockedResponse(
85 HTTPStatus.OK,
86 r"""
87 {"person": {"username": {"_content": "pennersr"}, "photosurl": {"_content":
88 "http://www.flickr.com/photos/12345678@N00/"},
89 "nsid": "12345678@N00",
90 "path_alias": null, "photos": {"count": {"_content": 0},
91 "firstdatetaken": {"_content": null}, "views": {"_content": "28"},
92 "firstdate": {"_content": null}}, "iconserver": "0",
93 "description": {"_content": ""}, "mobileurl": {"_content":
94 "http://m.flickr.com/photostream.gne?id=6294613"},
95 "profileurl": {
96 "_content": "http://www.flickr.com/people/12345678@N00/"},
97 "mbox_sha1sum": {"_content":
98 "5e5b359c123e54f95236209c8808d607a5cdd21e"},
99 "ispro": 0, "location": {"_content": ""},
100 "id": "12345678@N00",
101 "realname": {"_content": ""},
102 "iconfarm": 0}, "stat": "ok"}
103 """,
104 ),
105 ] # noqa
106
107 def get_expected_to_str(self):
108 return "pennersr"
109
110 def test_login(self):
111 super().test_login()
112 account = SocialAccount.objects.get(uid="12345678@N00")
113 f_account = account.get_provider_account()
114 self.assertEqual(account.user.first_name, "")
115 self.assertEqual(account.user.last_name, "")
116 self.assertEqual(
117 f_account.get_profile_url(),
118 "http://www.flickr.com/people/12345678@N00/",
119 )
120 self.assertEqual(f_account.to_str(), "pennersr")