test_int_client_credentials.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import pytest
  2. from clean_python.oauth2.client_credentials import CCTokenGateway
  3. from clean_python.oauth2.client_credentials import is_token_usable
  4. from clean_python.oauth2.client_credentials import OAuth2CCSettings
  5. from clean_python.oauth2.client_credentials import SyncCCTokenGateway
  6. @pytest.fixture
  7. def settings(fastapi_example_app) -> OAuth2CCSettings:
  8. # these settings match those hardcoded in the example app
  9. return OAuth2CCSettings(
  10. token_url=fastapi_example_app + "/v1/token",
  11. client_id="testclient",
  12. client_secret="supersecret",
  13. scope="all",
  14. )
  15. @pytest.fixture
  16. def gateway(settings) -> CCTokenGateway:
  17. return CCTokenGateway(settings)
  18. async def test_fetch_token(gateway: CCTokenGateway):
  19. response = await gateway._fetch_token()
  20. assert is_token_usable(response, 0)
  21. @pytest.fixture
  22. def sync_gateway(settings) -> SyncCCTokenGateway:
  23. return SyncCCTokenGateway(settings)
  24. def test_fetch_token_sync(sync_gateway: SyncCCTokenGateway):
  25. response = sync_gateway._fetch_token()
  26. assert is_token_usable(response, 0)