|
7 | 7 | from django.test.utils import override_settings |
8 | 8 | from rest_framework.test import APITestCase |
9 | 9 | from rest_framework.permissions import DjangoModelPermissionsOrAnonReadOnly |
10 | | -from httpretty import HTTPretty |
| 10 | +import responses |
11 | 11 | from social_core.utils import parse_qs |
12 | 12 |
|
13 | 13 | from .base import BaseFacebookAPITestCase, BaseTwitterApiTestCase |
@@ -43,6 +43,7 @@ class TestSocialAuth2(APITestCase, BaseFacebookAPITestCase): |
43 | 43 |
|
44 | 44 | @modify_settings(**session_modify_settings) |
45 | 45 | def _check_login_social_session(self, url, data): |
| 46 | + self.setup_api_mocks() |
46 | 47 | resp = self.client.post(url, data) |
47 | 48 | self.assertEqual(resp.status_code, 200) |
48 | 49 | self.assertEqual(resp.data['email'], self.email) |
@@ -75,31 +76,34 @@ def test_unknown_provider_session(self): |
75 | 76 | self.assertEqual(resp.status_code, 404) |
76 | 77 |
|
77 | 78 | def test_login_social_http_origin(self): |
| 79 | + self.setup_api_mocks() |
78 | 80 | resp = self.client.post( |
79 | 81 | reverse('login_social_session'), |
80 | 82 | data={'provider': 'facebook', 'code': '3D52VoM1uiw94a1ETnGvYlCw'}, |
81 | 83 | HTTP_ORIGIN="http://frontend.com") |
82 | 84 | self.assertEqual(resp.status_code, 200) |
83 | | - url_params = dict(parse_qsl(urlparse(HTTPretty.latest_requests[0].path).query)) |
| 85 | + url_params = dict(parse_qsl(urlparse(responses.calls[0].request.path_url).query)) |
84 | 86 | self.assertEqual(url_params['redirect_uri'], "http://frontend.com/") |
85 | 87 |
|
86 | 88 | @override_settings(REST_SOCIAL_OAUTH_ABSOLUTE_REDIRECT_URI='http://myproject.com/') |
87 | 89 | def test_login_absolute_redirect(self): |
| 90 | + self.setup_api_mocks() |
88 | 91 | resp = self.client.post( |
89 | 92 | reverse('login_social_session'), |
90 | 93 | data={'provider': 'facebook', 'code': '3D52VoM1uiw94a1ETnGvYlCw'}) |
91 | 94 | self.assertEqual(resp.status_code, 200) |
92 | | - url_params = dict(parse_qsl(urlparse(HTTPretty.latest_requests[0].path).query)) |
| 95 | + url_params = dict(parse_qsl(urlparse(responses.calls[0].request.path_url).query)) |
93 | 96 | self.assertEqual('http://myproject.com/', url_params['redirect_uri']) |
94 | 97 |
|
95 | 98 | @override_settings(REST_SOCIAL_OAUTH_ABSOLUTE_REDIRECT_URI='http://myproject.com/') |
96 | 99 | def test_login_manual_redirect(self): |
| 100 | + self.setup_api_mocks() |
97 | 101 | resp = self.client.post( |
98 | 102 | reverse('login_social_session'), |
99 | 103 | data={'provider': 'facebook', 'code': '3D52VoM1uiw94a1ETnGvYlCw', |
100 | 104 | 'redirect_uri': 'http://manualdomain.com/'}) |
101 | 105 | self.assertEqual(resp.status_code, 200) |
102 | | - url_params = dict(parse_qsl(urlparse(HTTPretty.latest_requests[0].path).query)) |
| 106 | + url_params = dict(parse_qsl(urlparse(responses.calls[0].request.path_url).query)) |
103 | 107 | self.assertEqual('http://manualdomain.com/', url_params['redirect_uri']) |
104 | 108 |
|
105 | 109 | @mock.patch('rest_framework.views.APIView.permission_classes') |
|
0 commit comments