|
2 | 2 | import datetime
|
3 | 3 |
|
4 | 4 | import pytest
|
| 5 | +from django.conf import settings |
5 | 6 | from django.conf.urls import include
|
6 | 7 | from django.contrib.auth import get_user_model
|
7 | 8 | from django.http import HttpResponse
|
|
12 | 13 |
|
13 | 14 | from oauth2_provider.models import get_access_token_model, get_application_model
|
14 | 15 | from oauth2_provider.oauth2_validators import OAuth2Validator
|
| 16 | +from oauth2_provider.settings import oauth2_settings |
15 | 17 | from oauth2_provider.views import ScopedProtectedResourceView
|
16 | 18 |
|
17 | 19 | from . import presets
|
@@ -154,6 +156,25 @@ def test_get_token_from_authentication_server_existing_token(self, mock_get):
|
154 | 156 | self.assertEqual(token.user.username, "foo_user")
|
155 | 157 | self.assertEqual(token.scope, "read write dolphin")
|
156 | 158 |
|
| 159 | + @mock.patch("requests.post", side_effect=mocked_requests_post) |
| 160 | + def test_get_token_from_authentication_server_expires_timezone(self, mock_get): |
| 161 | + """ |
| 162 | + Test method _get_token_from_authentication_server for projects with USE_TZ False |
| 163 | + """ |
| 164 | + settings_use_tz_backup = settings.USE_TZ |
| 165 | + settings.USE_TZ = False |
| 166 | + try: |
| 167 | + self.validator._get_token_from_authentication_server( |
| 168 | + "foo", |
| 169 | + oauth2_settings.RESOURCE_SERVER_INTROSPECTION_URL, |
| 170 | + oauth2_settings.RESOURCE_SERVER_AUTH_TOKEN, |
| 171 | + oauth2_settings.RESOURCE_SERVER_INTROSPECTION_CREDENTIALS, |
| 172 | + ) |
| 173 | + except ValueError as exception: |
| 174 | + self.fail(str(exception)) |
| 175 | + finally: |
| 176 | + settings.USE_TZ = settings_use_tz_backup |
| 177 | + |
157 | 178 | @mock.patch("requests.post", side_effect=mocked_requests_post)
|
158 | 179 | def test_validate_bearer_token(self, mock_get):
|
159 | 180 | """
|
|
0 commit comments