Debian Codegraph @

tests/apps/socialaccount/providers/gitea/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.gitea.provider import GiteaProvider
7 from tests.apps.socialaccount.base import OAuth2TestsMixin
8 from tests.mocking import MockedResponse
9
10
11 class GiteaTests(OAuth2TestsMixin, TestCase):
12 provider_id = GiteaProvider.id
13
14 def get_mocked_response(self):
15 return MockedResponse(
16 HTTPStatus.OK,
17 """
18 {
19 "id": 4940,
20 "login": "giteauser",
21 "full_name": "",
22 "email": "[email protected]",
23 "avatar_url": "https://gitea.com/user/avatar/giteauser/-1",
24 "language": "en-US",
25 "is_admin": true,
26 "last_login": "2021-08-20T20:07:39Z",
27 "created": "2018-05-03T16:04:34Z",
28 "restricted": false,
29 "active": true,
30 "prohibit_login": false,
31 "location": "",
32 "website": "",
33 "description": "",
34 "visibility": "public",
35 "followers_count": 0,
36 "following_count": 0,
37 "starred_repos_count": 0,
38 "username": "giteauser"
39 }""",
40 )
41
42 def get_expected_to_str(self):
43 return "giteauser"
44
45 def test_account_name_null(self):
46 """String conversion when Gitea responds with empty username"""
47 data = """{
48 "id": 4940,
49 "login": "giteauser",
50 "username": null
51 }"""
52 self.login(MockedResponse(HTTPStatus.OK, data))
53 socialaccount = SocialAccount.objects.get(uid="4940")
54 self.assertIsNone(socialaccount.extra_data.get("name"))
55 account = socialaccount.get_provider_account()
56 self.assertIsNotNone(account.to_str())
57 self.assertEqual(account.to_str(), "giteauser")