Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @pytest.mark.asyncio()
- async def test_acquire_handles_out_of_date_token(self, mock_token):
- mock_old_token = mock.AsyncMock(
- applications.PartialOAuth2Token,
- expires_in=datetime.timedelta(weeks=1),
- token_type=applications.TokenType.BEARER,
- access_token="old.mock.token",
- refresh_token="refresh.mock.token"
- )
- mock_rest = mock.AsyncMock(authorize_access_token=mock.AsyncMock(return_value=mock_token))
- strategy = rest.OAuthCredentialsStrategy(client=123456789, client_secret="123123123", auth_code="auth#code", redirect_uri="https://web.site/auth/discord")
- token = await strategy.acquire(
- mock.AsyncMock(authorize_access_token=mock.AsyncMock(return_value=mock_old_token))
- )
- with mock.patch.object(time, "monotonic", return_value=99999999999):
- new_token = await strategy.acquire(mock_rest)
- mock_rest.authorize_access_token.assert_awaited_once_with(
- client=123456789,
- client_secret="123123123",
- code="auth#code",
- redirect_uri="https://web.site/auth/discord",
- )
- assert new_token != token
- assert new_token == "mockmock.tokentoken.mocktoken"
Advertisement
Add Comment
Please, Sign In to add comment