pyrestkit 0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyrestkit/__init__.py +35 -0
- pyrestkit/ai/__init__.py +17 -0
- pyrestkit/ai/analyzer.py +137 -0
- pyrestkit/ai/client.py +101 -0
- pyrestkit/ai/config/__init__.py +5 -0
- pyrestkit/ai/config/ai_config.py +200 -0
- pyrestkit/ai/exceptions.py +22 -0
- pyrestkit/ai/generators/__init__.py +0 -0
- pyrestkit/ai/models.py +44 -0
- pyrestkit/ai/parsers/__init__.py +0 -0
- pyrestkit/ai/prompts/failure_analysis.md +21 -0
- pyrestkit/ai/provider.py +58 -0
- pyrestkit/ai/providers/__init__.py +21 -0
- pyrestkit/ai/providers/anthropic.py +85 -0
- pyrestkit/ai/providers/azure_openai.py +84 -0
- pyrestkit/ai/providers/base.py +39 -0
- pyrestkit/ai/providers/bedrock.py +70 -0
- pyrestkit/ai/providers/cohere.py +82 -0
- pyrestkit/ai/providers/gemini.py +113 -0
- pyrestkit/ai/providers/groq.py +81 -0
- pyrestkit/ai/providers/mistral.py +88 -0
- pyrestkit/ai/providers/ollama.py +82 -0
- pyrestkit/ai/providers/openai.py +124 -0
- pyrestkit/ai/utils/__init__.py +0 -0
- pyrestkit/ai/utils/prompt_loader.py +52 -0
- pyrestkit/assertions/__init__.py +7 -0
- pyrestkit/assertions/assertion_exception.py +4 -0
- pyrestkit/assertions/response_assertions.py +181 -0
- pyrestkit/auth/__init__.py +11 -0
- pyrestkit/auth/auth_strategy.py +14 -0
- pyrestkit/auth/authentication_manager.py +35 -0
- pyrestkit/auth/strategies/__init__.py +5 -0
- pyrestkit/auth/strategies/api_key_auth.py +18 -0
- pyrestkit/auth/strategies/basic_auth.py +24 -0
- pyrestkit/auth/strategies/bearer_auth.py +17 -0
- pyrestkit/auth/token_cache.py +44 -0
- pyrestkit/auth/token_manager.py +32 -0
- pyrestkit/auth/token_provider.py +12 -0
- pyrestkit/auth/token_response.py +13 -0
- pyrestkit/builder/__init__.py +5 -0
- pyrestkit/builder/fluent_request_builder.py +167 -0
- pyrestkit/clients/__init__.py +7 -0
- pyrestkit/clients/base_client.py +68 -0
- pyrestkit/clients/user_client.py +66 -0
- pyrestkit/config/__init__.py +5 -0
- pyrestkit/config/config.py +97 -0
- pyrestkit/constants/__init__.py +0 -0
- pyrestkit/constants/content_types.py +0 -0
- pyrestkit/constants/headers.py +0 -0
- pyrestkit/constants/status_codes.py +0 -0
- pyrestkit/core/__init__.py +13 -0
- pyrestkit/core/api_client.py +129 -0
- pyrestkit/core/logger.py +41 -0
- pyrestkit/core/request_builder.py +45 -0
- pyrestkit/core/request_executor.py +64 -0
- pyrestkit/core/request_logger.py +0 -0
- pyrestkit/core/response_logger.py +0 -0
- pyrestkit/core/session_manager.py +19 -0
- pyrestkit/database/__init__.py +0 -0
- pyrestkit/endpoints/__init__.py +5 -0
- pyrestkit/endpoints/base_endpoints.py +32 -0
- pyrestkit/endpoints/order_endpoints.py +9 -0
- pyrestkit/endpoints/payment_endpoints.py +5 -0
- pyrestkit/endpoints/user_endpoints.py +48 -0
- pyrestkit/exceptions/__init__.py +21 -0
- pyrestkit/exceptions/api_exception.py +8 -0
- pyrestkit/exceptions/authentication_exception.py +10 -0
- pyrestkit/exceptions/configuration_exception.py +10 -0
- pyrestkit/exceptions/exception_mapper.py +32 -0
- pyrestkit/exceptions/network_exception.py +10 -0
- pyrestkit/exceptions/response_exception.py +10 -0
- pyrestkit/exceptions/serialization_exception.py +10 -0
- pyrestkit/exceptions/validation_exception.py +10 -0
- pyrestkit/factories/__init__.py +5 -0
- pyrestkit/factories/base_factory.py +25 -0
- pyrestkit/factories/user_factory.py +37 -0
- pyrestkit/hooks/__init__.py +5 -0
- pyrestkit/hooks/hook.py +27 -0
- pyrestkit/hooks/hook_manager.py +39 -0
- pyrestkit/hooks/request_hook.py +18 -0
- pyrestkit/hooks/response_hook.py +17 -0
- pyrestkit/hooks/timing_hook.py +32 -0
- pyrestkit/models/__init__.py +8 -0
- pyrestkit/models/base_response.py +11 -0
- pyrestkit/models/request/__init__.py +7 -0
- pyrestkit/models/request/create_user_request.py +11 -0
- pyrestkit/models/request/update_user_request.py +10 -0
- pyrestkit/models/response/__init__.py +5 -0
- pyrestkit/models/response/create_user_response.py +26 -0
- pyrestkit/models/response/get_user_response.py +28 -0
- pyrestkit/models/response/user_response.py +12 -0
- pyrestkit/pipeline/__init__.py +5 -0
- pyrestkit/pipeline/middleware.py +18 -0
- pyrestkit/pipeline/middleware_chain.py +11 -0
- pyrestkit/pipeline/pipeline.py +27 -0
- pyrestkit/pipeline/request_context.py +26 -0
- pyrestkit/response/__init__.py +8 -0
- pyrestkit/response/framework_response.py +271 -0
- pyrestkit/response/response_body.py +124 -0
- pyrestkit/retry/__init__.py +5 -0
- pyrestkit/retry/backoff.py +32 -0
- pyrestkit/retry/retry_handler.py +52 -0
- pyrestkit/retry/retry_policy.py +33 -0
- pyrestkit/serializers/__init__.py +0 -0
- pyrestkit/serializers/response_mapper.py +25 -0
- pyrestkit/types/__init__.py +0 -0
- pyrestkit/types/model_protocol.py +17 -0
- pyrestkit/utils/__init__.py +0 -0
- pyrestkit/validators/__init__.py +7 -0
- pyrestkit/validators/response_validator.py +57 -0
- pyrestkit/validators/schema_validator.py +33 -0
- pyrestkit-0.0.0.dist-info/METADATA +741 -0
- pyrestkit-0.0.0.dist-info/RECORD +115 -0
- pyrestkit-0.0.0.dist-info/WHEEL +5 -0
- pyrestkit-0.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from requests import Response
|
|
6
|
+
|
|
7
|
+
from pyrestkit.exceptions.validation_exception import ValidationException
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ResponseValidator:
|
|
11
|
+
def __init__(self, response: Response) -> None:
|
|
12
|
+
self.response = response
|
|
13
|
+
|
|
14
|
+
def status_code(self, expected: int) -> ResponseValidator:
|
|
15
|
+
if self.response.status_code != expected:
|
|
16
|
+
raise ValidationException(
|
|
17
|
+
"Expected status code "
|
|
18
|
+
f"{expected}, received {self.response.status_code}."
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
return self
|
|
22
|
+
|
|
23
|
+
def has_key(self, key: str) -> ResponseValidator:
|
|
24
|
+
payload = self._json_payload()
|
|
25
|
+
|
|
26
|
+
if key not in payload:
|
|
27
|
+
raise ValidationException(f"Response does not contain key '{key}'.")
|
|
28
|
+
|
|
29
|
+
return self
|
|
30
|
+
|
|
31
|
+
def field_equals(
|
|
32
|
+
self,
|
|
33
|
+
key: str,
|
|
34
|
+
value: Any,
|
|
35
|
+
) -> ResponseValidator:
|
|
36
|
+
payload = self._json_payload()
|
|
37
|
+
|
|
38
|
+
if key not in payload:
|
|
39
|
+
raise ValidationException(f"Response does not contain key '{key}'.")
|
|
40
|
+
|
|
41
|
+
if payload[key] != value:
|
|
42
|
+
raise ValidationException(
|
|
43
|
+
f"Response field '{key}' expected {value!r}, received {payload[key]!r}."
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
return self
|
|
47
|
+
|
|
48
|
+
def _json_payload(self) -> dict[str, Any]:
|
|
49
|
+
try:
|
|
50
|
+
payload = self.response.json()
|
|
51
|
+
except ValueError as exc:
|
|
52
|
+
raise ValidationException("Response body is not valid JSON.") from exc
|
|
53
|
+
|
|
54
|
+
if not isinstance(payload, dict):
|
|
55
|
+
raise ValidationException("Response body must be a JSON object.")
|
|
56
|
+
|
|
57
|
+
return payload
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from jsonschema import validate
|
|
8
|
+
|
|
9
|
+
from pyrestkit.response.framework_response import FrameworkResponse
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SchemaValidator:
|
|
13
|
+
"""
|
|
14
|
+
Validates a response against a JSON schema.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
@staticmethod
|
|
18
|
+
def validate(
|
|
19
|
+
response: FrameworkResponse,
|
|
20
|
+
schema_path: str,
|
|
21
|
+
) -> None:
|
|
22
|
+
schema_file = Path(schema_path)
|
|
23
|
+
|
|
24
|
+
with schema_file.open(
|
|
25
|
+
encoding="utf-8",
|
|
26
|
+
) as file:
|
|
27
|
+
schema: dict[str, Any] = json.load(file)
|
|
28
|
+
|
|
29
|
+
validate(
|
|
30
|
+
# instance=response.json(),
|
|
31
|
+
instance=response.body.to_dict(),
|
|
32
|
+
schema=schema,
|
|
33
|
+
)
|