rn-forge-web 0.3.1__tar.gz → 0.3.2__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.
Files changed (35) hide show
  1. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/PKG-INFO +26 -19
  2. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/README.md +24 -17
  3. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/pyproject.toml +4 -4
  4. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/pyproject.toml.orig +4 -4
  5. rn_forge_web-0.3.2/src/rn_forge/web/conformance/_pagination.py +380 -0
  6. rn_forge_web-0.3.2/src/rn_forge/web/conformance/_platform.py +299 -0
  7. rn_forge_web-0.3.2/src/rn_forge/web/conformance/_problem.py +174 -0
  8. rn_forge_web-0.3.2/src/rn_forge/web/conformance/_shared.py +59 -0
  9. rn_forge_web-0.3.2/src/rn_forge/web/conformance/_transfer.py +572 -0
  10. rn_forge_web-0.3.2/src/rn_forge/web/conformance/_writes.py +480 -0
  11. rn_forge_web-0.3.2/src/rn_forge/web/conformance/cases.py +61 -0
  12. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/health.py +53 -17
  13. rn_forge_web-0.3.1/src/rn_forge/web/conformance/cases.py +0 -1890
  14. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/LICENSE +0 -0
  15. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/__init__.py +0 -0
  16. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/asgi.py +0 -0
  17. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/auth.py +0 -0
  18. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/concurrency.py +0 -0
  19. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/conformance/__init__.py +0 -0
  20. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/conformance/types.py +0 -0
  21. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/deprecation.py +0 -0
  22. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/exceptions.py +0 -0
  23. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/idempotency.py +0 -0
  24. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/merge_patch.py +0 -0
  25. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/models.py +0 -0
  26. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/openapi.py +0 -0
  27. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/operations.py +0 -0
  28. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/pagination.py +0 -0
  29. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/problem.py +0 -0
  30. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/py.typed +0 -0
  31. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/read_mask.py +0 -0
  32. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/security.py +0 -0
  33. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/soft_delete.py +0 -0
  34. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/tracing.py +0 -0
  35. {rn_forge_web-0.3.1 → rn_forge_web-0.3.2}/src/rn_forge/web/transfer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rn-forge-web
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Framework-agnostic HTTP/API primitives built on rn-forge-commons
5
5
  Author: Rohit Narayanan
6
6
  Author-email: Rohit Narayanan <rohit.nn@gmail.com>
@@ -13,7 +13,7 @@ Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3 :: Only
14
14
  Classifier: Programming Language :: Python :: 3.14
15
15
  Classifier: Typing :: Typed
16
- Requires-Dist: rn-forge-commons[pydantic]>=0.8.0,<0.10
16
+ Requires-Dist: rn-forge-commons[pydantic]>=0.8.0,<0.11
17
17
  Requires-Dist: opentelemetry-api>=1.44
18
18
  Requires-Dist: secure>=2.0.1 ; extra == 'security'
19
19
  Requires-Dist: assertpy>=2.35 ; extra == 'testing'
@@ -43,25 +43,16 @@ envelope, the idempotency contract, the readiness aggregate, the authentication
43
43
  contract, the OpenAPI naming rules, and the conformance table the framework
44
44
  packages are tested against.
45
45
 
46
- Fourteen flat modules, all one kind of mechanism: **inbound** HTTP wire
47
- semantics.
46
+ Flat modules, all one kind of mechanism: **inbound** HTTP wire semantics.
48
47
 
49
48
  ## Where it sits
50
49
 
51
- ```text
52
- commons ──► web ──► auth ──► django
53
- │ └───► fastapi
54
- └───► sqlalchemy
55
- ```
56
-
57
50
  `rn-forge-web` depends on **`rn-forge-commons` and nothing else in the
58
51
  workspace**. It never imports `rn_forge.cli` or `rn_forge.tooling` — those are
59
52
  the command-line and file-owning layers, and a package that ships into an ASGI
60
53
  server has no business reaching either. It never imports a web framework: not
61
- `django`, not `fastapi`, not `starlette`, not `rest_framework`.
62
-
63
- `.importlinter` at the repo root carries the `web-is-framework-free` and
64
- `web-layers` contracts, and `uv run lint-imports` proves them.
54
+ `django`, not `fastapi`, not `starlette`, not `rest_framework`. `task lint`
55
+ proves them.
65
56
 
66
57
  ## Inbound, not outbound
67
58
 
@@ -97,9 +88,26 @@ Require the package by version range:
97
88
  dependencies = ["rn-forge-web>=0.3,<0.4"]
98
89
  ```
99
90
 
100
- Inside this workspace, `[tool.uv.sources]` overrides the requirement with the
101
- local checkout; that override is for local development only and does not survive
102
- into a built wheel.
91
+ Its dependencies are `rn-forge-commons[pydantic]` and `opentelemetry-api`. The
92
+ `security` extra adds `secure`, for `rn_forge.web.security`; the `testing` extra
93
+ adds `assertpy` and `pytest`.
94
+
95
+ ## Minimum example
96
+
97
+ ```python
98
+ from rn_forge.web import default_registry, render_problem
99
+
100
+ registry = default_registry()
101
+ rendered = render_problem(registry, exc, instance="/orders/1")
102
+ # rendered.status, rendered.body, rendered.headers: application/problem+json
103
+ ```
104
+
105
+ ## Errors
106
+
107
+ Every exception here is an `AppException` and renders as an RFC 9457
108
+ `application/problem+json` body: `AuthenticationFailed` 401, `PermissionDenied`
109
+ 403, `VersionConflict` 412, `PreconditionRequired` 428. A 5xx carries a fixed
110
+ generic detail, never `str(exc)`.
103
111
 
104
112
  ## Dependencies and why
105
113
 
@@ -132,8 +140,7 @@ different wire shape.
132
140
 
133
141
  ## Documentation
134
142
 
135
- `uv run --directory packages/rn-forge-web --group docs mkdocs build --strict`,
136
- or the combined site from the repo root. `docs/guides/api-conventions.md` is the
143
+ `task docs:build` builds every site. `docs/guides/api-conventions.md` is the
137
144
  normative wire contract for an application's specification.
138
145
  `docs/guides/model-conventions.md` compares implemented ORM building blocks and
139
146
  optional application design advice.
@@ -14,25 +14,16 @@ envelope, the idempotency contract, the readiness aggregate, the authentication
14
14
  contract, the OpenAPI naming rules, and the conformance table the framework
15
15
  packages are tested against.
16
16
 
17
- Fourteen flat modules, all one kind of mechanism: **inbound** HTTP wire
18
- semantics.
17
+ Flat modules, all one kind of mechanism: **inbound** HTTP wire semantics.
19
18
 
20
19
  ## Where it sits
21
20
 
22
- ```text
23
- commons ──► web ──► auth ──► django
24
- │ └───► fastapi
25
- └───► sqlalchemy
26
- ```
27
-
28
21
  `rn-forge-web` depends on **`rn-forge-commons` and nothing else in the
29
22
  workspace**. It never imports `rn_forge.cli` or `rn_forge.tooling` — those are
30
23
  the command-line and file-owning layers, and a package that ships into an ASGI
31
24
  server has no business reaching either. It never imports a web framework: not
32
- `django`, not `fastapi`, not `starlette`, not `rest_framework`.
33
-
34
- `.importlinter` at the repo root carries the `web-is-framework-free` and
35
- `web-layers` contracts, and `uv run lint-imports` proves them.
25
+ `django`, not `fastapi`, not `starlette`, not `rest_framework`. `task lint`
26
+ proves them.
36
27
 
37
28
  ## Inbound, not outbound
38
29
 
@@ -68,9 +59,26 @@ Require the package by version range:
68
59
  dependencies = ["rn-forge-web>=0.3,<0.4"]
69
60
  ```
70
61
 
71
- Inside this workspace, `[tool.uv.sources]` overrides the requirement with the
72
- local checkout; that override is for local development only and does not survive
73
- into a built wheel.
62
+ Its dependencies are `rn-forge-commons[pydantic]` and `opentelemetry-api`. The
63
+ `security` extra adds `secure`, for `rn_forge.web.security`; the `testing` extra
64
+ adds `assertpy` and `pytest`.
65
+
66
+ ## Minimum example
67
+
68
+ ```python
69
+ from rn_forge.web import default_registry, render_problem
70
+
71
+ registry = default_registry()
72
+ rendered = render_problem(registry, exc, instance="/orders/1")
73
+ # rendered.status, rendered.body, rendered.headers: application/problem+json
74
+ ```
75
+
76
+ ## Errors
77
+
78
+ Every exception here is an `AppException` and renders as an RFC 9457
79
+ `application/problem+json` body: `AuthenticationFailed` 401, `PermissionDenied`
80
+ 403, `VersionConflict` 412, `PreconditionRequired` 428. A 5xx carries a fixed
81
+ generic detail, never `str(exc)`.
74
82
 
75
83
  ## Dependencies and why
76
84
 
@@ -103,8 +111,7 @@ different wire shape.
103
111
 
104
112
  ## Documentation
105
113
 
106
- `uv run --directory packages/rn-forge-web --group docs mkdocs build --strict`,
107
- or the combined site from the repo root. `docs/guides/api-conventions.md` is the
114
+ `task docs:build` builds every site. `docs/guides/api-conventions.md` is the
108
115
  normative wire contract for an application's specification.
109
116
  `docs/guides/model-conventions.md` compares implemented ORM building blocks and
110
117
  optional application design advice.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "rn-forge-web"
3
- version = "0.3.1"
3
+ version = "0.3.2"
4
4
  description = "Framework-agnostic HTTP/API primitives built on rn-forge-commons"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -16,7 +16,7 @@ classifiers = [
16
16
  ]
17
17
  requires-python = ">=3.14"
18
18
  dependencies = [
19
- "rn-forge-commons[pydantic]>=0.8.0,<0.10",
19
+ "rn-forge-commons[pydantic]>=0.8.0,<0.11",
20
20
  "opentelemetry-api>=1.44",
21
21
  ]
22
22
 
@@ -76,7 +76,7 @@ dev = [
76
76
  "pytest-asyncio>=1.3.0",
77
77
  "pytest-cov>=7.1.0",
78
78
  "pytest-randomly>=4.1.0",
79
- "rn-forge-auth>=0.1.0,<0.2",
79
+ "rn-forge-auth>=0.1.0,<0.3",
80
80
  "rn-forge-web[security]",
81
81
  "ruff>=0.15.21",
82
82
  ]
@@ -85,6 +85,6 @@ docs = [
85
85
  "mkdocs-material>=9.7.6",
86
86
  "mkdocstrings[python]>=1.0.6",
87
87
  "opentelemetry-instrumentation-asgi>=0.65b0",
88
- "rn-forge-auth>=0.1.0,<0.2",
88
+ "rn-forge-auth>=0.1.0,<0.3",
89
89
  "rn-forge-web[security]",
90
90
  ]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "rn-forge-web"
3
- version = "0.3.1"
3
+ version = "0.3.2"
4
4
  description = "Framework-agnostic HTTP/API primitives built on rn-forge-commons"
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Rohit Narayanan", email = "rohit.nn@gmail.com" }]
@@ -22,7 +22,7 @@ requires-python = ">=3.14"
22
22
  # `opentelemetry-api`, following OpenTelemetry's own library guidance (a no-op
23
23
  # until the application configures the SDK). See "Dependencies and why" in README.md.
24
24
  dependencies = [
25
- "rn-forge-commons[pydantic]>=0.8.0,<0.10",
25
+ "rn-forge-commons[pydantic]>=0.8.0,<0.11",
26
26
  "opentelemetry-api>=1.44",
27
27
  ]
28
28
 
@@ -75,7 +75,7 @@ dev = [
75
75
  "pytest-cov>=7.1.0",
76
76
  "pytest-randomly>=4.1.0",
77
77
  # The guide examples, which the tests run, import rn-forge-auth.
78
- "rn-forge-auth>=0.1.0,<0.2",
78
+ "rn-forge-auth>=0.1.0,<0.3",
79
79
  "rn-forge-web[security]",
80
80
  "ruff>=0.15.21",
81
81
  ]
@@ -84,6 +84,6 @@ docs = [
84
84
  "mkdocs-material>=9.7.6",
85
85
  "mkdocstrings[python]>=1.0.6",
86
86
  "opentelemetry-instrumentation-asgi>=0.65b0",
87
- "rn-forge-auth>=0.1.0,<0.2",
87
+ "rn-forge-auth>=0.1.0,<0.3",
88
88
  "rn-forge-web[security]",
89
89
  ]
@@ -0,0 +1,380 @@
1
+ """HTTP conformance cases for pagination behavior."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Final
6
+
7
+ from rn_forge.web.conformance._shared import (
8
+ _BOOKS_GET,
9
+ _ITEMS_PATH,
10
+ _JSON,
11
+ _PROBLEM,
12
+ PAGE_1_NEXT_TOKEN,
13
+ _problem_body,
14
+ )
15
+ from rn_forge.web.conformance.types import ConformanceCase, RequestSpec
16
+ from rn_forge.web.pagination import encode_cursor
17
+ from rn_forge.web.problem import BAD_REQUEST
18
+
19
+ __all__ = ["PAGINATION_CASES"]
20
+
21
+ _ORDER_ID_DESC: Final = "id desc"
22
+
23
+ _PROFILE_PATH: Final = "/conformance/profiles/1"
24
+
25
+ _PROFILE_ADA: Final = {
26
+ "id": "1",
27
+ "displayName": "Ada",
28
+ "address": {"city": "London", "postcode": "N1"},
29
+ "phones": [{"kind": "home", "number": "1"}, {"kind": "work", "number": "2"}],
30
+ "settings": {"theme": "dark"},
31
+ }
32
+
33
+ _PEOPLE_PATH: Final = "/conformance/people"
34
+
35
+ _ORDER_TEAM_SCORE_DESC: Final = "team,score desc"
36
+
37
+ ORDERED_PAGE_1_NEXT_TOKEN: Final = encode_cursor(("2",), "2", _ORDER_ID_DESC)
38
+ """The deterministic token returned by the first ordered page."""
39
+
40
+ COMPOSITE_PAGE_1_TOKEN: Final = encode_cursor(("a", 10), "1", _ORDER_TEAM_SCORE_DESC)
41
+
42
+ COMPOSITE_PAGE_2_TOKEN: Final = encode_cursor(("b", 5), "4", _ORDER_TEAM_SCORE_DESC)
43
+
44
+ COMPOSITE_NULL_TOKEN: Final = encode_cursor(("a", None), "3", _ORDER_TEAM_SCORE_DESC)
45
+
46
+ _PEOPLE: Final = {
47
+ 1: ("a", 10),
48
+ 2: ("b", None),
49
+ 3: ("a", None),
50
+ 4: ("b", 5),
51
+ 5: ("a", 10),
52
+ }
53
+
54
+
55
+ def _people(*ids: int) -> list[dict[str, object]]:
56
+ """The ``/conformance/people`` items with these ids, in this order."""
57
+ return [{"id": str(i), "team": _PEOPLE[i][0], "score": _PEOPLE[i][1]} for i in ids]
58
+
59
+
60
+ PAGINATION_CASES: Final[tuple[ConformanceCase, ...]] = (
61
+ ConformanceCase(
62
+ id="pagination.first-page-carries-a-next-token",
63
+ area="pagination",
64
+ description="The AIP-158 envelope: items + nextPageToken, and totalSize absent by default.",
65
+ request=RequestSpec("GET", _ITEMS_PATH, query={"pageSize": "2"}),
66
+ expect_status=200,
67
+ expect_headers=_JSON,
68
+ expect_body={
69
+ "items": [{"id": "1"}, {"id": "2"}],
70
+ "nextPageToken": PAGE_1_NEXT_TOKEN,
71
+ },
72
+ ),
73
+ ConformanceCase(
74
+ id="pagination.last-page-has-a-null-next-token",
75
+ area="pagination",
76
+ description=(
77
+ "nextPageToken is present and null on the last page rather than omitted, "
78
+ "so a generated client's type does not change shape between pages."
79
+ ),
80
+ request=RequestSpec(
81
+ "GET",
82
+ _ITEMS_PATH,
83
+ query={"pageSize": "2", "pageToken": PAGE_1_NEXT_TOKEN},
84
+ ),
85
+ expect_status=200,
86
+ expect_headers=_JSON,
87
+ expect_body={"items": [{"id": "3"}], "nextPageToken": None},
88
+ ),
89
+ ConformanceCase(
90
+ id="pagination.oversized-page-size-is-clamped-not-rejected",
91
+ area="pagination",
92
+ description=(
93
+ "AIP-158: coerce down to the maximum. A FastAPI Query(le=...) would 422 here, "
94
+ "and that is the divergence this case exists to catch."
95
+ ),
96
+ request=RequestSpec("GET", _ITEMS_PATH, query={"pageSize": "1000"}),
97
+ expect_status=200,
98
+ expect_headers=_JSON,
99
+ expect_body={
100
+ "items": [{"id": "1"}, {"id": "2"}],
101
+ "nextPageToken": PAGE_1_NEXT_TOKEN,
102
+ },
103
+ ),
104
+ ConformanceCase(
105
+ id="pagination.tampered-page-token-is-400",
106
+ area="pagination",
107
+ description="A malformed opaque token is InvalidCursor → 400, never a 500.",
108
+ request=RequestSpec(
109
+ "GET", _ITEMS_PATH, query={"pageToken": "!!!not-base64!!!"}
110
+ ),
111
+ expect_status=400,
112
+ expect_headers=_PROBLEM,
113
+ expect_body=_problem_body(BAD_REQUEST, "Malformed page token"),
114
+ ),
115
+ ConformanceCase(
116
+ id="pagination.order-by-descending-binds-the-token",
117
+ area="pagination",
118
+ description=(
119
+ "AIP-132: orderBy reorders the list, and the next token carries that "
120
+ "order so it cannot be replayed under another."
121
+ ),
122
+ request=RequestSpec(
123
+ "GET",
124
+ _ITEMS_PATH,
125
+ query={"pageSize": "2", "orderBy": _ORDER_ID_DESC},
126
+ ),
127
+ expect_status=200,
128
+ expect_headers=_JSON,
129
+ expect_body={
130
+ "items": [{"id": "3"}, {"id": "2"}],
131
+ "nextPageToken": ORDERED_PAGE_1_NEXT_TOKEN,
132
+ },
133
+ ),
134
+ ConformanceCase(
135
+ id="pagination.order-by-unlisted-field-is-400",
136
+ area="pagination",
137
+ description="An orderBy field the endpoint does not list is a 400, never silently ignored.",
138
+ request=RequestSpec("GET", _ITEMS_PATH, query={"orderBy": "secret"}),
139
+ expect_status=400,
140
+ expect_headers=_PROBLEM,
141
+ expect_body=_problem_body(BAD_REQUEST, "Cannot order by 'secret'; allowed: id"),
142
+ ),
143
+ ConformanceCase(
144
+ id="pagination.order-by-several-fields-sorts-by-each-in-turn",
145
+ area="pagination",
146
+ description=(
147
+ "AIP-132: orderBy is a comma-separated list; each term breaks the "
148
+ "ties of the one before, with its own direction."
149
+ ),
150
+ request=RequestSpec(
151
+ "GET",
152
+ _PEOPLE_PATH,
153
+ query={"orderBy": _ORDER_TEAM_SCORE_DESC, "pageSize": "5"},
154
+ ),
155
+ expect_status=200,
156
+ expect_headers=_JSON,
157
+ expect_body={"items": _people(5, 1, 3, 4, 2), "nextPageToken": None},
158
+ ),
159
+ ConformanceCase(
160
+ id="pagination.nulls-sort-last-ascending",
161
+ area="pagination",
162
+ description="Rows whose value is null come after those that have one, ascending.",
163
+ request=RequestSpec("GET", _PEOPLE_PATH, query={"orderBy": "score"}),
164
+ expect_status=200,
165
+ expect_headers=_JSON,
166
+ expect_body={"items": _people(4, 1, 5, 2, 3), "nextPageToken": None},
167
+ ),
168
+ ConformanceCase(
169
+ id="pagination.nulls-sort-last-descending",
170
+ area="pagination",
171
+ description="Rows whose value is null come after those that have one, descending too.",
172
+ request=RequestSpec("GET", _PEOPLE_PATH, query={"orderBy": "score desc"}),
173
+ expect_status=200,
174
+ expect_headers=_JSON,
175
+ expect_body={"items": _people(5, 1, 4, 3, 2), "nextPageToken": None},
176
+ ),
177
+ ConformanceCase(
178
+ id="pagination.first-page-carries-a-composite-token",
179
+ area="pagination",
180
+ description=(
181
+ "The token holds one sort value per orderBy term, so the next page "
182
+ "can resume from the whole order."
183
+ ),
184
+ request=RequestSpec(
185
+ "GET",
186
+ _PEOPLE_PATH,
187
+ query={"orderBy": _ORDER_TEAM_SCORE_DESC, "pageSize": "2"},
188
+ ),
189
+ expect_status=200,
190
+ expect_headers=_JSON,
191
+ expect_body={"items": _people(5, 1), "nextPageToken": COMPOSITE_PAGE_1_TOKEN},
192
+ ),
193
+ ConformanceCase(
194
+ id="pagination.composite-token-resumes-within-a-tie",
195
+ area="pagination",
196
+ description="Rows tied on every term but the key are neither skipped nor repeated.",
197
+ request=RequestSpec(
198
+ "GET",
199
+ _PEOPLE_PATH,
200
+ query={
201
+ "orderBy": _ORDER_TEAM_SCORE_DESC,
202
+ "pageSize": "2",
203
+ "pageToken": COMPOSITE_PAGE_1_TOKEN,
204
+ },
205
+ ),
206
+ expect_status=200,
207
+ expect_headers=_JSON,
208
+ expect_body={"items": _people(3, 4), "nextPageToken": COMPOSITE_PAGE_2_TOKEN},
209
+ ),
210
+ ConformanceCase(
211
+ id="pagination.composite-token-resumes-after-a-null",
212
+ area="pagination",
213
+ description="A token whose last value is null resumes among the rows that are null there.",
214
+ request=RequestSpec(
215
+ "GET",
216
+ _PEOPLE_PATH,
217
+ query={
218
+ "orderBy": _ORDER_TEAM_SCORE_DESC,
219
+ "pageSize": "3",
220
+ "pageToken": COMPOSITE_NULL_TOKEN,
221
+ },
222
+ ),
223
+ expect_status=200,
224
+ expect_headers=_JSON,
225
+ expect_body={"items": _people(4, 2), "nextPageToken": None},
226
+ ),
227
+ ConformanceCase(
228
+ id="pagination.repeated-order-by-field-is-400",
229
+ area="pagination",
230
+ description="A field named twice in orderBy is a 400, never silently ignored.",
231
+ request=RequestSpec("GET", _PEOPLE_PATH, query={"orderBy": "team,team desc"}),
232
+ expect_status=400,
233
+ expect_headers=_PROBLEM,
234
+ expect_body=_problem_body(BAD_REQUEST, "orderBy names 'team' more than once"),
235
+ ),
236
+ ConformanceCase(
237
+ id="pagination.token-with-the-wrong-number-of-values-is-400",
238
+ area="pagination",
239
+ description="A token with fewer values than orderBy has terms is rejected as malformed.",
240
+ request=RequestSpec(
241
+ "GET",
242
+ _PEOPLE_PATH,
243
+ query={
244
+ "orderBy": _ORDER_TEAM_SCORE_DESC,
245
+ "pageToken": encode_cursor(("a",), "1", _ORDER_TEAM_SCORE_DESC),
246
+ },
247
+ ),
248
+ expect_status=400,
249
+ expect_headers=_PROBLEM,
250
+ expect_body=_problem_body(BAD_REQUEST, "Malformed page token"),
251
+ ),
252
+ ConformanceCase(
253
+ id="pagination.token-under-a-different-order-by-is-400",
254
+ area="pagination",
255
+ description="A token issued for the default order is rejected once orderBy changes.",
256
+ request=RequestSpec(
257
+ "GET",
258
+ _ITEMS_PATH,
259
+ query={"orderBy": _ORDER_ID_DESC, "pageToken": PAGE_1_NEXT_TOKEN},
260
+ ),
261
+ expect_status=400,
262
+ expect_headers=_PROBLEM,
263
+ expect_body=_problem_body(BAD_REQUEST, "pageToken does not match orderBy"),
264
+ ),
265
+ ConformanceCase(
266
+ id="read-mask.get-returns-only-the-masked-fields",
267
+ area="read-mask",
268
+ description="AIP-157: readMask names top-level fields, and only those are returned.",
269
+ request=RequestSpec(
270
+ "GET", _PROFILE_PATH, query={"readMask": "displayName,settings"}
271
+ ),
272
+ expect_status=200,
273
+ expect_headers=_JSON,
274
+ expect_body={"displayName": "Ada", "settings": {"theme": "dark"}},
275
+ ),
276
+ ConformanceCase(
277
+ id="read-mask.nested-path-selects-a-sub-field",
278
+ area="read-mask",
279
+ description="A dotted path selects one field of a declared object.",
280
+ request=RequestSpec("GET", _PROFILE_PATH, query={"readMask": "address.city"}),
281
+ expect_status=200,
282
+ expect_headers=_JSON,
283
+ expect_body={"address": {"city": "London"}},
284
+ ),
285
+ ConformanceCase(
286
+ id="read-mask.path-through-a-list-applies-to-each-element",
287
+ area="read-mask",
288
+ description="A path through a list of objects applies to every element.",
289
+ request=RequestSpec("GET", _PROFILE_PATH, query={"readMask": "phones.number"}),
290
+ expect_status=200,
291
+ expect_headers=_JSON,
292
+ expect_body={"phones": [{"number": "1"}, {"number": "2"}]},
293
+ ),
294
+ ConformanceCase(
295
+ id="read-mask.overlapping-paths-merge",
296
+ area="read-mask",
297
+ description="A path and one of its sub-paths merge to the whole object.",
298
+ request=RequestSpec(
299
+ "GET", _PROFILE_PATH, query={"readMask": "address,address.city"}
300
+ ),
301
+ expect_status=200,
302
+ expect_headers=_JSON,
303
+ expect_body={"address": {"city": "London", "postcode": "N1"}},
304
+ ),
305
+ ConformanceCase(
306
+ id="read-mask.star-is-the-whole-resource",
307
+ area="read-mask",
308
+ description="A readMask of * returns the whole resource.",
309
+ request=RequestSpec("GET", _PROFILE_PATH, query={"readMask": "*"}),
310
+ expect_status=200,
311
+ expect_headers=_JSON,
312
+ expect_body=_PROFILE_ADA,
313
+ ),
314
+ ConformanceCase(
315
+ id="read-mask.list-masks-each-item",
316
+ area="read-mask",
317
+ description="On a collection the mask applies to each item, and the page members stay.",
318
+ request=RequestSpec(
319
+ "GET", "/conformance/profiles", query={"readMask": "id,displayName"}
320
+ ),
321
+ expect_status=200,
322
+ expect_headers=_JSON,
323
+ expect_body={
324
+ "items": [
325
+ {"id": "1", "displayName": "Ada"},
326
+ {"id": "2", "displayName": "Grace"},
327
+ ],
328
+ "nextPageToken": None,
329
+ },
330
+ ),
331
+ ConformanceCase(
332
+ id="read-mask.unknown-path-is-400",
333
+ area="read-mask",
334
+ description="A path that names no declared field is a 400, never ignored.",
335
+ request=RequestSpec("GET", _PROFILE_PATH, query={"readMask": "nickname"}),
336
+ expect_status=400,
337
+ expect_headers=_PROBLEM,
338
+ expect_body=_problem_body(BAD_REQUEST, "Unknown readMask path 'nickname'"),
339
+ ),
340
+ ConformanceCase(
341
+ id="read-mask.path-inside-a-free-form-field-is-400",
342
+ area="read-mask",
343
+ description="A free-form JSON field is a leaf: a path inside it names nothing declared.",
344
+ request=RequestSpec("GET", _PROFILE_PATH, query={"readMask": "settings.theme"}),
345
+ expect_status=400,
346
+ expect_headers=_PROBLEM,
347
+ expect_body=_problem_body(
348
+ BAD_REQUEST, "Unknown readMask path 'settings.theme'"
349
+ ),
350
+ ),
351
+ ConformanceCase(
352
+ id="read-mask.star-with-other-paths-is-400",
353
+ area="read-mask",
354
+ description="* selects everything, so combining it with a path is a 400.",
355
+ request=RequestSpec("GET", _PROFILE_PATH, query={"readMask": "*,displayName"}),
356
+ expect_status=400,
357
+ expect_headers=_PROBLEM,
358
+ expect_body=_problem_body(
359
+ BAD_REQUEST, "readMask '*' cannot be combined with other paths"
360
+ ),
361
+ ),
362
+ ConformanceCase(
363
+ id="read-mask.masked-read-keeps-the-etag",
364
+ area="read-mask",
365
+ description="A masked read carries the resource's ETag, so a client can follow with If-Match.",
366
+ request=RequestSpec("GET", _PROFILE_PATH, query={"readMask": "displayName"}),
367
+ expect_status=200,
368
+ expect_headers={**_JSON, "ETag": 'W/"1:1"'},
369
+ expect_body={"displayName": "Ada"},
370
+ ),
371
+ ConformanceCase(
372
+ id="read-mask.batch-get-masks-each-item",
373
+ area="read-mask",
374
+ description="A :batchGet applies the mask to each resource.",
375
+ request=RequestSpec("GET", _BOOKS_GET, query={"ids": "1", "readMask": "name"}),
376
+ expect_status=200,
377
+ expect_headers=_JSON,
378
+ expect_body={"books": [{"name": "alpha"}]},
379
+ ),
380
+ )