test_exceptions.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright 2022 Google Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import pytest # type: ignore
  15. from google.auth import exceptions # type:ignore
  16. @pytest.fixture(
  17. params=[
  18. exceptions.GoogleAuthError,
  19. exceptions.TransportError,
  20. exceptions.RefreshError,
  21. exceptions.UserAccessTokenError,
  22. exceptions.DefaultCredentialsError,
  23. exceptions.MutualTLSChannelError,
  24. exceptions.OAuthError,
  25. exceptions.ReauthFailError,
  26. exceptions.ReauthSamlChallengeFailError,
  27. ]
  28. )
  29. def retryable_exception(request):
  30. return request.param
  31. @pytest.fixture(params=[exceptions.ClientCertError])
  32. def non_retryable_exception(request):
  33. return request.param
  34. def test_default_retryable_exceptions(retryable_exception):
  35. assert not retryable_exception().retryable
  36. @pytest.mark.parametrize("retryable", [True, False])
  37. def test_retryable_exceptions(retryable_exception, retryable):
  38. retryable_exception = retryable_exception(retryable=retryable)
  39. assert retryable_exception.retryable == retryable
  40. @pytest.mark.parametrize("retryable", [True, False])
  41. def test_non_retryable_exceptions(non_retryable_exception, retryable):
  42. non_retryable_exception = non_retryable_exception(retryable=retryable)
  43. assert not non_retryable_exception.retryable