macss-modular-api 0.7.1__tar.gz → 0.7.3__tar.gz
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.
- {macss_modular_api-0.7.1/src/macss_modular_api.egg-info → macss_modular_api-0.7.3}/PKG-INFO +5 -5
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/pyproject.toml +5 -5
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3/src/macss_modular_api.egg-info}/PKG-INFO +5 -5
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/macss_modular_api.egg-info/SOURCES.txt +1 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/metrics/metric_registry.py +7 -1
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/usecase_handler.py +33 -3
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/openapi/swagger_docs.py +1 -1
- macss_modular_api-0.7.3/tests/test_malformed_body.py +117 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/tests/test_packaging.py +4 -3
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/LICENSE +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/README.md +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/setup.cfg +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/macss_modular_api.egg-info/dependency_links.txt +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/macss_modular_api.egg-info/requires.txt +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/macss_modular_api.egg-info/top_level.txt +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/error_response_middleware.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/health/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/health/health_check.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/health/health_handler.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/health/health_service.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/logger/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/logger/logger.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/logger/logging_middleware.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/metrics/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/metrics/metric.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/metrics/metrics_middleware.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/modular_api.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/module_builder.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/official_plugins.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/plugin.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/registry.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/request_pipeline_audit.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/tracing/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/tracing/cloud_trace_propagator.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/tracing/propagation_policy.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/tracing/server_span.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/tracing/tracing_middleware.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/tracing/tracing_options.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/use_case_exception.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/usecase.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/dto.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/catalog/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/catalog/graphql_catalog_builder.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/metadata/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/metadata/graphql_metadata_parser.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/read/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/read/sql_read_contract.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/read/sqlserver_read_compiler.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/runtime/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/runtime/graphql_artifacts.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/runtime/graphql_runtime_options.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/runtime/graphql_runtime_plugin.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/schema/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/schema/graphql_schema_sdl_generator.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/sqlserver/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/sqlserver/physical_model.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/sqlserver/sql_server_connection_settings.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/sqlserver/sql_server_metadata_reader.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/middlewares/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/middlewares/cors.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/openapi/__init__.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/openapi/openapi.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/py.typed +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/tests/test_auto_schema.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/tests/test_clean_room_driver_isolation.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/tests/test_dto_typing.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/tests/test_field_example.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/tests/test_fromjson_validation.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/tests/test_modular_api.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/tests/test_module_builder.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/tests/test_schema_conformance.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/tests/test_use_case_exception.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/tests/test_usecase.py +0 -0
- {macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/tests/test_usecase_handler.py +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: macss-modular-api
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.3
|
|
4
4
|
Summary: Use-case-centric toolkit for building modular APIs with Starlette. Define UseCase classes (input → validate → execute → output), connect them to HTTP routes, and expose OpenAPI documentation automatically.
|
|
5
5
|
Author: ccisne.dev
|
|
6
6
|
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/
|
|
8
|
-
Project-URL: Repository, https://github.com/
|
|
9
|
-
Project-URL: Issues, https://github.com/
|
|
10
|
-
Project-URL: Documentation, https://github.com/
|
|
7
|
+
Project-URL: Homepage, https://github.com/ccisnedev/modular_api
|
|
8
|
+
Project-URL: Repository, https://github.com/ccisnedev/modular_api/tree/main/code/modular_api/py
|
|
9
|
+
Project-URL: Issues, https://github.com/ccisnedev/modular_api/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/ccisnedev/modular_api/tree/main/code/modular_api/py#readme
|
|
11
11
|
Keywords: api,usecase,openapi,starlette,modular,macss
|
|
12
12
|
Classifier: Development Status :: 4 - Beta
|
|
13
13
|
Classifier: Framework :: AsyncIO
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "macss-modular-api"
|
|
7
|
-
version = "0.7.
|
|
7
|
+
version = "0.7.3"
|
|
8
8
|
description = "Use-case-centric toolkit for building modular APIs with Starlette. Define UseCase classes (input → validate → execute → output), connect them to HTTP routes, and expose OpenAPI documentation automatically."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -52,10 +52,10 @@ dev = [
|
|
|
52
52
|
]
|
|
53
53
|
|
|
54
54
|
[project.urls]
|
|
55
|
-
Homepage = "https://github.com/
|
|
56
|
-
Repository = "https://github.com/
|
|
57
|
-
Issues = "https://github.com/
|
|
58
|
-
Documentation = "https://github.com/
|
|
55
|
+
Homepage = "https://github.com/ccisnedev/modular_api"
|
|
56
|
+
Repository = "https://github.com/ccisnedev/modular_api/tree/main/code/modular_api/py"
|
|
57
|
+
Issues = "https://github.com/ccisnedev/modular_api/issues"
|
|
58
|
+
Documentation = "https://github.com/ccisnedev/modular_api/tree/main/code/modular_api/py#readme"
|
|
59
59
|
|
|
60
60
|
[tool.setuptools.packages.find]
|
|
61
61
|
where = ["src"]
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: macss-modular-api
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.3
|
|
4
4
|
Summary: Use-case-centric toolkit for building modular APIs with Starlette. Define UseCase classes (input → validate → execute → output), connect them to HTTP routes, and expose OpenAPI documentation automatically.
|
|
5
5
|
Author: ccisne.dev
|
|
6
6
|
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/
|
|
8
|
-
Project-URL: Repository, https://github.com/
|
|
9
|
-
Project-URL: Issues, https://github.com/
|
|
10
|
-
Project-URL: Documentation, https://github.com/
|
|
7
|
+
Project-URL: Homepage, https://github.com/ccisnedev/modular_api
|
|
8
|
+
Project-URL: Repository, https://github.com/ccisnedev/modular_api/tree/main/code/modular_api/py
|
|
9
|
+
Project-URL: Issues, https://github.com/ccisnedev/modular_api/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/ccisnedev/modular_api/tree/main/code/modular_api/py#readme
|
|
11
11
|
Keywords: api,usecase,openapi,starlette,modular,macss
|
|
12
12
|
Classifier: Development Status :: 4 - Beta
|
|
13
13
|
Classifier: Framework :: AsyncIO
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/metrics/metric_registry.py
RENAMED
|
@@ -126,7 +126,13 @@ class MetricRegistry:
|
|
|
126
126
|
|
|
127
127
|
@staticmethod
|
|
128
128
|
def _serialize_counter(parts: list[str], counter: Counter) -> None:
|
|
129
|
-
|
|
129
|
+
samples = counter.collect()
|
|
130
|
+
if not samples:
|
|
131
|
+
# Root counter with no labeled children — emit the root value, like a gauge.
|
|
132
|
+
# Once a labeled child exists, the root value is not serialized.
|
|
133
|
+
parts.append(f"{counter.name} {_format_value(counter.value)}")
|
|
134
|
+
return
|
|
135
|
+
for sample in samples:
|
|
130
136
|
parts.append(
|
|
131
137
|
f"{counter.name}{_format_labels(sample.labels)} {_format_value(sample.value)}"
|
|
132
138
|
)
|
|
@@ -52,6 +52,25 @@ def _format_validation_message(field: str, error_type: str) -> str:
|
|
|
52
52
|
return f"Field '{field}' must be of type {openapi_type}"
|
|
53
53
|
|
|
54
54
|
|
|
55
|
+
def _bad_request(request: Request, message: str, cause: BaseException | None) -> Response:
|
|
56
|
+
"""A 400 for a body that cannot become the use case input.
|
|
57
|
+
|
|
58
|
+
The cause goes to the log at warning level, never into the response: it is a client error,
|
|
59
|
+
not an unexpected server failure.
|
|
60
|
+
"""
|
|
61
|
+
logger = getattr(request.state, LOGGER_STATE_KEY, None)
|
|
62
|
+
if logger is not None:
|
|
63
|
+
fields: dict[str, object] = {"status": 400}
|
|
64
|
+
if cause is not None:
|
|
65
|
+
fields["error"] = f"{type(cause).__name__}: {cause}"
|
|
66
|
+
logger.warning(message, fields=fields)
|
|
67
|
+
return Response(
|
|
68
|
+
content=json.dumps({"error": message}),
|
|
69
|
+
status_code=400,
|
|
70
|
+
media_type=_JSON_CONTENT_TYPE,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
55
74
|
def usecase_handler(factory: UseCaseFactory) -> Any:
|
|
56
75
|
"""Wraps a UseCase factory into an async Starlette endpoint.
|
|
57
76
|
|
|
@@ -78,7 +97,10 @@ def usecase_handler(factory: UseCaseFactory) -> Any:
|
|
|
78
97
|
# a bare string, an array, a number — so the guard below is load-bearing. Declaring
|
|
79
98
|
# the result a dict made a type checker call that guard dead code, which is exactly
|
|
80
99
|
# backwards: the annotation was the thing that was wrong.
|
|
81
|
-
|
|
100
|
+
try:
|
|
101
|
+
payload: object = await request.json()
|
|
102
|
+
except ValueError: # json.JSONDecodeError, also for an empty body
|
|
103
|
+
return _bad_request(request, "Invalid JSON in request body", None)
|
|
82
104
|
|
|
83
105
|
if not isinstance(payload, dict):
|
|
84
106
|
return Response(
|
|
@@ -89,8 +111,16 @@ def usecase_handler(factory: UseCaseFactory) -> Any:
|
|
|
89
111
|
|
|
90
112
|
data = cast("dict[str, Any]", payload)
|
|
91
113
|
|
|
92
|
-
# 2. Build use case
|
|
93
|
-
|
|
114
|
+
# 2. Build use case. `from_json` only maps untrusted input into the use case input, so a
|
|
115
|
+
# TypeError, KeyError or ValueError raised there means the body has the wrong shape:
|
|
116
|
+
# a client error. Pydantic's ValidationError and UseCaseException keep their own
|
|
117
|
+
# handling below.
|
|
118
|
+
try:
|
|
119
|
+
use_case = factory(data)
|
|
120
|
+
except (UseCaseException, ValidationError):
|
|
121
|
+
raise
|
|
122
|
+
except (TypeError, KeyError, ValueError) as exc:
|
|
123
|
+
return _bad_request(request, "Invalid request body", exc)
|
|
94
124
|
|
|
95
125
|
# 2b. Inject request-scoped logger (if logging middleware placed one)
|
|
96
126
|
logger = getattr(request.state, LOGGER_STATE_KEY, None)
|
|
@@ -5,7 +5,7 @@ system-aware dark mode. The local ``/openapi.json`` endpoint provides
|
|
|
5
5
|
the spec. Styling, dark mode, and Swagger UI loading are handled
|
|
6
6
|
entirely by docs-ui — no inline CSS or JS in this template.
|
|
7
7
|
|
|
8
|
-
See: https://github.com/
|
|
8
|
+
See: https://github.com/ccisnedev/modular_api/tree/main/code/docs-ui
|
|
9
9
|
"""
|
|
10
10
|
|
|
11
11
|
from __future__ import annotations
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""A body that cannot become the use case input is a client error: 400, not 500 (#44)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
from starlette.applications import Starlette
|
|
10
|
+
from starlette.routing import Route
|
|
11
|
+
from starlette.testclient import TestClient
|
|
12
|
+
|
|
13
|
+
from modular_api.core.use_case_exception import UseCaseException
|
|
14
|
+
from modular_api.core.usecase import Input, Output, UseCase
|
|
15
|
+
from modular_api.core.usecase_handler import usecase_handler
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class CountInput(Input):
|
|
19
|
+
count: int = 0
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class CountOutput(Output):
|
|
23
|
+
count: int = 0
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def status_code(self) -> int:
|
|
27
|
+
return 200
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class CountUseCase(UseCase[CountInput, CountOutput]):
|
|
31
|
+
"""A hand-written from_json that trusts the shape of the body, as fromJson code often does."""
|
|
32
|
+
|
|
33
|
+
def __init__(self, data: dict[str, Any]) -> None:
|
|
34
|
+
raw = data["count"] # KeyError when missing
|
|
35
|
+
if raw == "boom":
|
|
36
|
+
raise UseCaseException(status_code=422, message="No boom", error_code="BOOM")
|
|
37
|
+
self._input = CountInput(count=int(raw)) # ValueError / TypeError on a bad shape
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def input(self) -> CountInput:
|
|
41
|
+
return self._input
|
|
42
|
+
|
|
43
|
+
def validate(self) -> str | None:
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
async def execute(self) -> CountOutput:
|
|
47
|
+
return CountOutput(count=self._input.count)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class _SpyLogger:
|
|
51
|
+
def __init__(self) -> None:
|
|
52
|
+
self.calls: list[tuple[str, str, dict[str, object] | None]] = []
|
|
53
|
+
|
|
54
|
+
def __getattr__(self, level: str) -> Any:
|
|
55
|
+
def log(msg: str, *, fields: dict[str, object] | None = None) -> None:
|
|
56
|
+
self.calls.append((level, msg, fields))
|
|
57
|
+
|
|
58
|
+
return log
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _client(logger: _SpyLogger | None = None) -> TestClient:
|
|
62
|
+
async def with_logger(request: Any) -> Any:
|
|
63
|
+
if logger is not None:
|
|
64
|
+
request.state.modular_logger = logger
|
|
65
|
+
return await usecase_handler(CountUseCase)(request)
|
|
66
|
+
|
|
67
|
+
app = Starlette(routes=[Route("/count", with_logger, methods=["POST"])])
|
|
68
|
+
return TestClient(app, raise_server_exceptions=False)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _post(client: TestClient, body: str) -> Any:
|
|
72
|
+
return client.post("/count", content=body, headers={"content-type": "application/json"})
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@pytest.mark.parametrize("body", ["{not json", "", "{", "nul"])
|
|
76
|
+
def test_unparseable_body_returns_400(body: str) -> None:
|
|
77
|
+
resp = _post(_client(), body)
|
|
78
|
+
assert resp.status_code == 400
|
|
79
|
+
assert resp.json() == {"error": "Invalid JSON in request body"}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@pytest.mark.parametrize("body", ["[1, 2]", '"text"', "42", "null", "true"])
|
|
83
|
+
def test_json_that_is_not_an_object_returns_400(body: str) -> None:
|
|
84
|
+
resp = _post(_client(), body)
|
|
85
|
+
assert resp.status_code == 400
|
|
86
|
+
assert resp.json() == {"error": "Request body must be a JSON object"}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@pytest.mark.parametrize(
|
|
90
|
+
"payload",
|
|
91
|
+
[
|
|
92
|
+
{}, # KeyError: missing field
|
|
93
|
+
{"count": "abc"}, # ValueError: int("abc")
|
|
94
|
+
{"count": [1]}, # TypeError: int([1])
|
|
95
|
+
],
|
|
96
|
+
)
|
|
97
|
+
def test_error_inside_from_json_returns_400_without_details(payload: dict[str, Any]) -> None:
|
|
98
|
+
logger = _SpyLogger()
|
|
99
|
+
resp = _post(_client(logger), json.dumps(payload))
|
|
100
|
+
|
|
101
|
+
assert resp.status_code == 400
|
|
102
|
+
assert resp.json() == {"error": "Invalid request body"}
|
|
103
|
+
levels = [level for level, _, _ in logger.calls]
|
|
104
|
+
assert "warning" in levels
|
|
105
|
+
assert "error" not in levels
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def test_use_case_exception_inside_from_json_keeps_its_status() -> None:
|
|
109
|
+
resp = _post(_client(), json.dumps({"count": "boom"}))
|
|
110
|
+
assert resp.status_code == 422
|
|
111
|
+
assert resp.json()["error"] == "BOOM"
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_well_formed_body_still_succeeds() -> None:
|
|
115
|
+
resp = _post(_client(), json.dumps({"count": "7"}))
|
|
116
|
+
assert resp.status_code == 200
|
|
117
|
+
assert resp.json() == {"count": 7}
|
|
@@ -20,7 +20,8 @@ from pathlib import Path
|
|
|
20
20
|
|
|
21
21
|
import pytest
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
# code/<package>/py/tests/test_packaging.py -> code/
|
|
24
|
+
_CODE_ROOT = Path(__file__).resolve().parents[3]
|
|
24
25
|
|
|
25
26
|
_PACKAGES = (
|
|
26
27
|
"modular_api",
|
|
@@ -32,7 +33,7 @@ _PACKAGES = (
|
|
|
32
33
|
|
|
33
34
|
|
|
34
35
|
def _manifest(package: str) -> dict[str, object]:
|
|
35
|
-
return tomllib.loads((
|
|
36
|
+
return tomllib.loads((_CODE_ROOT / package / "py" / "pyproject.toml").read_text(encoding="utf-8"))
|
|
36
37
|
|
|
37
38
|
|
|
38
39
|
def _import_package_dir(package: str) -> Path:
|
|
@@ -41,7 +42,7 @@ def _import_package_dir(package: str) -> Path:
|
|
|
41
42
|
Found rather than assumed: the distribution name, the directory under ``src/`` and the import name
|
|
42
43
|
are three different strings in this repo, and an ``egg-info`` directory sits alongside.
|
|
43
44
|
"""
|
|
44
|
-
source =
|
|
45
|
+
source = _CODE_ROOT / package / "py" / "src"
|
|
45
46
|
candidates = [child for child in source.iterdir() if (child / "__init__.py").is_file()]
|
|
46
47
|
assert len(candidates) == 1, f"expected exactly one importable package under {source}"
|
|
47
48
|
return candidates[0]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/macss_modular_api.egg-info/requires.txt
RENAMED
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/macss_modular_api.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/health/health_check.py
RENAMED
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/health/health_handler.py
RENAMED
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/health/health_service.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/metrics/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/official_plugins.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/request_pipeline_audit.py
RENAMED
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/tracing/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/tracing/server_span.py
RENAMED
|
File without changes
|
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/tracing/tracing_options.py
RENAMED
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/core/use_case_exception.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/catalog/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/metadata/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/read/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/runtime/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/schema/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/src/modular_api/graphql/sqlserver/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{macss_modular_api-0.7.1 → macss_modular_api-0.7.3}/tests/test_clean_room_driver_isolation.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|