forked from sergey-galasov/psn-galaxy
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf94685
commit c06b31f
Showing
6 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
from unittest.mock import MagicMock | ||
import asyncio | ||
|
||
|
||
class AsyncMock(MagicMock): | ||
async def __call__(self, *args, **kwargs): | ||
# pylint: disable=useless-super-delegation | ||
return super(AsyncMock, self).__call__(*args, **kwargs) | ||
|
||
|
||
class AsyncMockDelayed(MagicMock): | ||
async def __call__(self, *args, **kwargs): | ||
await asyncio.sleep(0.1) | ||
# pylint: disable=useless-super-delegation | ||
return super(AsyncMockDelayed, self).__call__(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import asyncio | ||
import pytest | ||
from unittest.mock import Mock | ||
from galaxy.api.errors import AuthenticationRequired | ||
from http_client import AuthenticatedHttpClient | ||
from tests.async_mock import AsyncMockDelayed, AsyncMock | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_multiple_refreshing(): | ||
EXPIRED_TOKEN = "old access token" | ||
REFRESHED_TOKEN = "refreshed access token" | ||
def raise_on_old_token(*args, **kwargs): | ||
if http_client._access_token == EXPIRED_TOKEN: | ||
raise AuthenticationRequired() | ||
return 'ok' | ||
http_client = AuthenticatedHttpClient(Mock, Mock) | ||
http_client.can_refresh.set() | ||
http_client._access_token = EXPIRED_TOKEN | ||
http_client.get_access_token = AsyncMockDelayed(return_value=REFRESHED_TOKEN) | ||
http_client._oauth_request = AsyncMock(side_effect=raise_on_old_token) | ||
responses = await asyncio.gather( | ||
http_client.request('url'), | ||
http_client.request('url'), | ||
) | ||
for i in responses: | ||
assert i == 'ok' |