Coverage for fake_kubernetes_client/exceptions.py: 9%
35 statements
« prev ^ index » next coverage.py v7.10.1, created at 2025-07-29 12:31 +0300
« prev ^ index » next coverage.py v7.10.1, created at 2025-07-29 12:31 +0300
1"""Exception classes for fake Kubernetes client"""
3from typing import Union
5# Import exceptions from kubernetes.dynamic - use real ones for compatibility
6try:
7 from kubernetes.dynamic.exceptions import (
8 ApiException,
9 ConflictError,
10 ForbiddenError,
11 MethodNotAllowedError,
12 NotFoundError,
13 ResourceNotFoundError,
14 ServerTimeoutError,
15 )
16except ImportError:
17 # Fallback implementations if kubernetes module is not available
18 class FakeClientApiException(Exception):
19 def __init__(
20 self, status: Union[int, None] = None, reason: Union[str, None] = None, body: Union[str, None] = None
21 ) -> None:
22 super().__init__(f"API Exception: {status} - {reason}")
23 self.status = status
24 self.reason = reason
25 self.body = body
27 class FakeClientNotFoundError(FakeClientApiException):
28 def __init__(self, reason: str = "Not Found") -> None:
29 super().__init__(status=404, reason=reason)
31 class FakeClientConflictError(FakeClientApiException):
32 def __init__(self, reason: str = "Conflict") -> None:
33 super().__init__(status=409, reason=reason)
35 class FakeClientForbiddenError(FakeClientApiException):
36 def __init__(self, reason: str = "Forbidden") -> None:
37 super().__init__(status=403, reason=reason)
39 class FakeClientMethodNotAllowedError(FakeClientApiException):
40 def __init__(self, reason: str = "Method Not Allowed") -> None:
41 super().__init__(status=405, reason=reason)
43 class FakeClientResourceNotFoundError(FakeClientApiException):
44 def __init__(self, reason: str = "Resource Not Found") -> None:
45 super().__init__(status=404, reason=reason)
47 class FakeClientServerTimeoutError(FakeClientApiException):
48 def __init__(self, reason: str = "Server Timeout") -> None:
49 super().__init__(status=504, reason=reason)
51 # Create aliases with expected names
52 ApiException = FakeClientApiException
53 NotFoundError = FakeClientNotFoundError
54 ConflictError = FakeClientConflictError
55 ForbiddenError = FakeClientForbiddenError
56 MethodNotAllowedError = FakeClientMethodNotAllowedError
57 ResourceNotFoundError = FakeClientResourceNotFoundError
58 ServerTimeoutError = FakeClientServerTimeoutError