Guest User

Test

a guest
Mar 24th, 2023
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. @pytest.mark.asyncio()
  2. async def test_acquire_handles_out_of_date_token(self, mock_token):
  3. mock_old_token = mock.AsyncMock(
  4. applications.PartialOAuth2Token,
  5. expires_in=datetime.timedelta(weeks=1),
  6. token_type=applications.TokenType.BEARER,
  7. access_token="old.mock.token",
  8. refresh_token="refresh.mock.token"
  9. )
  10. mock_rest = mock.AsyncMock(authorize_access_token=mock.AsyncMock(return_value=mock_token))
  11. strategy = rest.OAuthCredentialsStrategy(client=123456789, client_secret="123123123", auth_code="auth#code", redirect_uri="https://web.site/auth/discord")
  12. token = await strategy.acquire(
  13. mock.AsyncMock(authorize_access_token=mock.AsyncMock(return_value=mock_old_token))
  14. )
  15.  
  16. with mock.patch.object(time, "monotonic", return_value=99999999999):
  17. new_token = await strategy.acquire(mock_rest)
  18.  
  19. mock_rest.authorize_access_token.assert_awaited_once_with(
  20. client=123456789,
  21. client_secret="123123123",
  22. code="auth#code",
  23. redirect_uri="https://web.site/auth/discord",
  24. )
  25. assert new_token != token
  26. assert new_token == "mockmock.tokentoken.mocktoken"
Advertisement
Add Comment
Please, Sign In to add comment