Debian Codegraph @

tests/apps/socialaccount/providers/steam/tests.py

raw
1 from unittest.mock import Mock, patch
2
3 from django.conf import settings
4 from django.test import TestCase
5 from django.urls import reverse
6
7 from openid.yadis.discover import DiscoveryFailure
8 from pytest_django.asserts import assertRedirects
9
10 from allauth.socialaccount.providers.steam import views
11 from allauth.socialaccount.providers.steam.provider import SteamOpenIDProvider
12 from tests.apps.socialaccount.base import setup_app
13
14
15 class SteamTests(TestCase):
16 def setUp(self):
17 self.app = setup_app(SteamOpenIDProvider.id)
18
19 def test_redirect(self):
20 with patch(
21 "allauth.socialaccount.providers.steam.provider._openid_consumer"
22 ) as consumer_mock:
23 consumer_client = Mock()
24 begin = Mock()
25 auth_request = Mock()
26 redirectURL = Mock()
27 consumer_mock.return_value = consumer_client
28 consumer_client.begin = begin
29 begin.return_value = auth_request
30 auth_request.redirectURL = redirectURL
31 redirectURL.return_value = "https://steamcommunity.com/openid/login?XXX"
32
33 resp = self.client.post(reverse(views.steam_login))
34 assertRedirects(
35 resp,
36 "https://steamcommunity.com/openid/login?XXX",
37 fetch_redirect_response=False,
38 )
39
40 def test_redirect_error(self):
41 with patch(
42 "allauth.socialaccount.providers.steam.provider._openid_consumer"
43 ) as consumer_mock:
44 consumer_client = Mock()
45 begin = Mock()
46 consumer_mock.return_value = consumer_client
47 consumer_client.begin = begin
48
49 def discovery_failure(*args, **kwargs):
50 raise DiscoveryFailure(
51 "HTTP Response status from identity URL host is not 200. Got status 502",
52 None,
53 )
54
55 begin.side_effect = discovery_failure
56
57 resp = self.client.post(reverse(views.steam_login))
58 template_ext = getattr(settings, "ACCOUNT_TEMPLATE_EXTENSION", "html")
59 self.assertTemplateUsed(
60 resp, f"socialaccount/authentication_error.{template_ext}"
61 )