viewrium 2.3.0__tar.gz → 2.5.0__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.
- {viewrium-2.3.0 → viewrium-2.5.0}/.gitignore +3 -0
- {viewrium-2.3.0 → viewrium-2.5.0}/PKG-INFO +1 -2
- {viewrium-2.3.0 → viewrium-2.5.0}/README.md +0 -1
- {viewrium-2.3.0 → viewrium-2.5.0}/package.json +2 -1
- {viewrium-2.3.0 → viewrium-2.5.0}/pyproject.toml +1 -1
- {viewrium-2.3.0 → viewrium-2.5.0}/src/viewrium/__init__.py +1 -7
- {viewrium-2.3.0 → viewrium-2.5.0}/src/viewrium/_client.py +13 -18
- {viewrium-2.3.0 → viewrium-2.5.0}/src/viewrium/_models.py +36 -33
- {viewrium-2.3.0 → viewrium-2.5.0}/tests/test_client.py +27 -0
- {viewrium-2.3.0 → viewrium-2.5.0}/tests/test_import.py +1 -1
- viewrium-2.5.0/tests/test_schema_drift.py +137 -0
- viewrium-2.5.0/turbo.json +16 -0
- {viewrium-2.3.0 → viewrium-2.5.0}/uv.lock +1 -1
- viewrium-2.3.0/turbo.json +0 -10
- {viewrium-2.3.0 → viewrium-2.5.0}/.python-version +0 -0
- {viewrium-2.3.0 → viewrium-2.5.0}/LICENSE +0 -0
- {viewrium-2.3.0 → viewrium-2.5.0}/src/viewrium/_errors.py +0 -0
- {viewrium-2.3.0 → viewrium-2.5.0}/src/viewrium/py.typed +0 -0
|
@@ -56,3 +56,6 @@ next-env.d.ts
|
|
|
56
56
|
# Agent worktrees (Claude Code); never tracked, never committed - the directories are
|
|
57
57
|
# throwaway checkouts and their node_modules.
|
|
58
58
|
.claude/worktrees/
|
|
59
|
+
|
|
60
|
+
# Listing videos (large binaries; uploaded to YouTube, never committed)
|
|
61
|
+
notes/marketing/shopify-listing/*.mp4
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: viewrium
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.5.0
|
|
4
4
|
Summary: Official Python client for the Viewrium API: AR and 3D product visualization for furniture retailers.
|
|
5
5
|
Project-URL: Homepage, https://www.viewrium.com
|
|
6
6
|
Project-URL: Documentation, https://www.viewrium.com/docs/sdks/python
|
|
@@ -171,7 +171,6 @@ See [How generation works](https://www.viewrium.com/docs/generation) and
|
|
|
171
171
|
| `client.api_keys` | `list`, `create`, `revoke` |
|
|
172
172
|
| `client.usage` | `get` |
|
|
173
173
|
| `client.webhooks` | `list`, `create`, `retrieve`, `update`, `delete`, `list_deliveries` |
|
|
174
|
-
| `client.projects` | `list`, `retrieve` |
|
|
175
174
|
| `client.beacon` | `send` |
|
|
176
175
|
| `client` | `health()` |
|
|
177
176
|
|
|
@@ -145,7 +145,6 @@ See [How generation works](https://www.viewrium.com/docs/generation) and
|
|
|
145
145
|
| `client.api_keys` | `list`, `create`, `revoke` |
|
|
146
146
|
| `client.usage` | `get` |
|
|
147
147
|
| `client.webhooks` | `list`, `create`, `retrieve`, `update`, `delete`, `list_deliveries` |
|
|
148
|
-
| `client.projects` | `list`, `retrieve` |
|
|
149
148
|
| `client.beacon` | `send` |
|
|
150
149
|
| `client` | `health()` |
|
|
151
150
|
|
|
@@ -20,7 +20,6 @@ from ._client import (
|
|
|
20
20
|
ApiKeysResource,
|
|
21
21
|
BeaconResource,
|
|
22
22
|
ProductsResource,
|
|
23
|
-
ProjectsResource,
|
|
24
23
|
UsageResource,
|
|
25
24
|
Viewrium,
|
|
26
25
|
WebhooksResource,
|
|
@@ -94,8 +93,6 @@ from ._models import (
|
|
|
94
93
|
ProductSummary,
|
|
95
94
|
ProductUpdateRequest,
|
|
96
95
|
ProductWarning,
|
|
97
|
-
Project,
|
|
98
|
-
ProjectListResponse,
|
|
99
96
|
PublicProduct,
|
|
100
97
|
ReviewStatus,
|
|
101
98
|
ShadowContact,
|
|
@@ -129,7 +126,7 @@ from ._models import (
|
|
|
129
126
|
WidthAxis,
|
|
130
127
|
)
|
|
131
128
|
|
|
132
|
-
__version__ = "2.
|
|
129
|
+
__version__ = "2.5.0"
|
|
133
130
|
|
|
134
131
|
__all__ = [
|
|
135
132
|
"__version__",
|
|
@@ -139,7 +136,6 @@ __all__ = [
|
|
|
139
136
|
"ApiKeysResource",
|
|
140
137
|
"UsageResource",
|
|
141
138
|
"WebhooksResource",
|
|
142
|
-
"ProjectsResource",
|
|
143
139
|
"BeaconResource",
|
|
144
140
|
# errors
|
|
145
141
|
"ViewriumError",
|
|
@@ -241,7 +237,5 @@ __all__ = [
|
|
|
241
237
|
"WebhookEndpointCreateResponse",
|
|
242
238
|
"WebhookDelivery",
|
|
243
239
|
"WebhookDeliveryListResponse",
|
|
244
|
-
"Project",
|
|
245
|
-
"ProjectListResponse",
|
|
246
240
|
"HealthResponse",
|
|
247
241
|
]
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Method shapes mirror ``@viewrium/sdk`` (one ``products.create`` entrypoint, ``products.list`` /
|
|
4
4
|
``retrieve`` / ``retrieve_by_custom_id`` / ``update`` / ``delete`` / ``batch_delete`` /
|
|
5
5
|
``publish`` / ``tags`` / ``review`` / ``update_image`` / ``update_model`` / ``rescale`` /
|
|
6
|
-
``order`` / ``export``, plus ``api_keys``, ``usage``, ``webhooks``, ``
|
|
6
|
+
``order`` / ``export``, plus ``api_keys``, ``usage``, ``webhooks``, ``beacon``).
|
|
7
7
|
Auth is an ``sk_`` secret key (or ``pk_`` publishable key) sent as ``Authorization: Bearer``.
|
|
8
8
|
"""
|
|
9
9
|
|
|
@@ -43,8 +43,6 @@ from ._models import (
|
|
|
43
43
|
ProductReviewResponse,
|
|
44
44
|
ProductSortField,
|
|
45
45
|
ProductUpdateRequest,
|
|
46
|
-
Project,
|
|
47
|
-
ProjectListResponse,
|
|
48
46
|
ReviewStatus,
|
|
49
47
|
SortOrder,
|
|
50
48
|
TagsResponse,
|
|
@@ -139,7 +137,6 @@ class Viewrium:
|
|
|
139
137
|
self.api_keys = ApiKeysResource(self)
|
|
140
138
|
self.usage = UsageResource(self)
|
|
141
139
|
self.webhooks = WebhooksResource(self)
|
|
142
|
-
self.projects = ProjectsResource(self)
|
|
143
140
|
self.beacon = BeaconResource(self)
|
|
144
141
|
|
|
145
142
|
def health(self) -> HealthResponse:
|
|
@@ -335,6 +332,17 @@ class ProductsResource:
|
|
|
335
332
|
"POST", f"/v1/products/{product_id}/tickets", Ticket, json=_body(request)
|
|
336
333
|
)
|
|
337
334
|
|
|
335
|
+
def qr(self, product_id: str, *, guide: bool = False, size: int = 1024) -> bytes:
|
|
336
|
+
"""GET /v1/products/{id}/qr - the product's QR code as a square PNG, ``size`` px on a
|
|
337
|
+
side (256-2048), as bytes. The code encodes the product's ``viewer_url`` and carries the
|
|
338
|
+
Viewrium mark. ``guide=True`` renders the whole "View in your room" card with its three
|
|
339
|
+
steps; the default is the minimal "View in your room" + code + "Powered by Viewrium".
|
|
340
|
+
Answered before the product is published too, but the link opens only once it is."""
|
|
341
|
+
params: Params = {"guide": guide, "size": size}
|
|
342
|
+
return self._client.request_bytes(
|
|
343
|
+
"GET", f"/v1/products/{product_id}/qr", params=params
|
|
344
|
+
).content
|
|
345
|
+
|
|
338
346
|
def order(self, product_id: str, request: ProductOrderRequest) -> ProductOrderParked:
|
|
339
347
|
"""POST /v1/products/{id}/order - order the missing half. It PARKS: commit the
|
|
340
348
|
returned token with ``create``."""
|
|
@@ -400,7 +408,6 @@ class UsageResource:
|
|
|
400
408
|
org_id: str | None = None,
|
|
401
409
|
scope: ListScope | None = None,
|
|
402
410
|
product_id: str | None = None,
|
|
403
|
-
project_id: str | None = None,
|
|
404
411
|
model_id: str | None = None,
|
|
405
412
|
event_type: UsageEventType | None = None,
|
|
406
413
|
granularity: Literal["hour", "day"] | None = None,
|
|
@@ -411,7 +418,7 @@ class UsageResource:
|
|
|
411
418
|
|
|
412
419
|
Scope: one org (``org_id``, or the principal's only org), every org a session reaches
|
|
413
420
|
(``scope=ListScope.ALL``), or one product (``product_id``, which needs no ``org_id``).
|
|
414
|
-
``
|
|
421
|
+
``model_id`` is the v1 scan-era filter.
|
|
415
422
|
|
|
416
423
|
``start`` / ``end`` are arbitrary - any window, not a preset - and default to the last
|
|
417
424
|
30 days. ``granularity`` buckets by hour or day. Org-internal traffic (an org's own
|
|
@@ -429,7 +436,6 @@ class UsageResource:
|
|
|
429
436
|
"org_id": org_id,
|
|
430
437
|
"scope": scope,
|
|
431
438
|
"product_id": product_id,
|
|
432
|
-
"project_id": project_id,
|
|
433
439
|
"model_id": model_id,
|
|
434
440
|
"event_type": event_type,
|
|
435
441
|
"granularity": granularity,
|
|
@@ -475,17 +481,6 @@ class WebhooksResource:
|
|
|
475
481
|
)
|
|
476
482
|
|
|
477
483
|
|
|
478
|
-
class ProjectsResource:
|
|
479
|
-
def __init__(self, client: Viewrium) -> None:
|
|
480
|
-
self._client = client
|
|
481
|
-
|
|
482
|
-
def list(self) -> ProjectListResponse:
|
|
483
|
-
return self._client.request("GET", "/v1/projects", ProjectListResponse)
|
|
484
|
-
|
|
485
|
-
def retrieve(self, project_id: str) -> Project:
|
|
486
|
-
return self._client.request("GET", f"/v1/projects/{project_id}", Project)
|
|
487
|
-
|
|
488
|
-
|
|
489
484
|
class BeaconResource:
|
|
490
485
|
def __init__(self, client: Viewrium) -> None:
|
|
491
486
|
self._client = client
|
|
@@ -135,14 +135,25 @@ class UsageEventType(StrEnum):
|
|
|
135
135
|
|
|
136
136
|
|
|
137
137
|
class WebhookEventType(StrEnum):
|
|
138
|
-
"""
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
"""The events an endpoint subscribes to. Every product event's ``data`` is the product's
|
|
139
|
+
public snapshot plus the event's own fields; ``product.deleted`` carries only ``id`` and
|
|
140
|
+
``custom_id``, ``export.ready`` only ids and counts. No payload carries a model file URL.
|
|
141
|
+
|
|
142
|
+
``model.ready`` / ``model.failed`` are DEPRECATED scan-era names: still accepted on an
|
|
143
|
+
endpoint, never sent."""
|
|
141
144
|
|
|
142
145
|
MODEL_READY = "model.ready"
|
|
143
146
|
MODEL_FAILED = "model.failed"
|
|
147
|
+
PRODUCT_CREATED = "product.created"
|
|
148
|
+
PRODUCT_GENERATING = "product.generating"
|
|
144
149
|
PRODUCT_COMPLETED = "product.completed"
|
|
145
150
|
PRODUCT_FAILED = "product.failed"
|
|
151
|
+
PRODUCT_REVIEWED = "product.reviewed"
|
|
152
|
+
PRODUCT_PUBLISHED = "product.published"
|
|
153
|
+
PRODUCT_UNPUBLISHED = "product.unpublished"
|
|
154
|
+
PRODUCT_UPDATED = "product.updated"
|
|
155
|
+
PRODUCT_DELETED = "product.deleted"
|
|
156
|
+
EXPORT_READY = "export.ready"
|
|
146
157
|
|
|
147
158
|
|
|
148
159
|
class DimensionUnit(StrEnum):
|
|
@@ -287,7 +298,8 @@ class ProductOverrides(_Base):
|
|
|
287
298
|
``force_model`` is what an API caller passes to take a model the gate refused - a
|
|
288
299
|
transparent product, a geometry or texture risk, or two or more invented viewpoints
|
|
289
300
|
(``ModelPlan.unseen_views``). The dashboard always forces and shows the risks instead,
|
|
290
|
-
so the refusal binds API and SDK callers only.
|
|
301
|
+
so the refusal binds API and SDK callers only. It never overrides ``missing_3d_view``: with
|
|
302
|
+
no photograph to build from, nothing can be generated and the quote cannot be committed.
|
|
291
303
|
"""
|
|
292
304
|
|
|
293
305
|
generate_unseen: bool | None = None
|
|
@@ -497,9 +509,8 @@ class ProductFilters(_Base):
|
|
|
497
509
|
|
|
498
510
|
class ApiKeyCreateRequest(_Base):
|
|
499
511
|
key_type: KeyType
|
|
500
|
-
# Session-created keys bind to an org
|
|
512
|
+
# Session-created keys bind to an org.
|
|
501
513
|
org_id: str | None = None
|
|
502
|
-
project_id: str | None = None
|
|
503
514
|
name: str | None = None
|
|
504
515
|
scopes: list[str] = Field(default_factory=list)
|
|
505
516
|
|
|
@@ -509,7 +520,6 @@ class WebhookEndpointCreateRequest(_Base):
|
|
|
509
520
|
events: list[WebhookEventType]
|
|
510
521
|
description: str | None = None
|
|
511
522
|
org_id: str | None = None
|
|
512
|
-
project_id: str | None = None
|
|
513
523
|
|
|
514
524
|
|
|
515
525
|
class WebhookEndpointUpdateRequest(_Base):
|
|
@@ -584,7 +594,9 @@ class ModelPlan(_Base):
|
|
|
584
594
|
``blocked_by`` vocabulary: ``missing_3d_view``, ``transparent``, ``geometry_risk``,
|
|
585
595
|
``texture_risk``, ``unseen_views``. A refusal binds API and SDK callers, who pass
|
|
586
596
|
``ProductOverrides(force_model=True)`` or turn the org's *always generate models* on; the
|
|
587
|
-
dashboard always forces and treats Generate as the approval.
|
|
597
|
+
dashboard always forces and treats Generate as the approval. ``missing_3d_view`` (no
|
|
598
|
+
photograph to build from) is the exception: nothing overrides it, and it refuses the images
|
|
599
|
+
too.
|
|
588
600
|
"""
|
|
589
601
|
|
|
590
602
|
ordered: bool
|
|
@@ -821,6 +833,9 @@ class ProductSummary(_Base):
|
|
|
821
833
|
owner: ProductOwner | None = None
|
|
822
834
|
created_at: datetime
|
|
823
835
|
updated_at: datetime | None = None
|
|
836
|
+
#: The product's hosted viewer page - what its QR code (``products.qr``) encodes. It opens
|
|
837
|
+
#: only while the product is published.
|
|
838
|
+
viewer_url: str | None = None
|
|
824
839
|
|
|
825
840
|
|
|
826
841
|
class Product(ProductSummary):
|
|
@@ -863,6 +878,9 @@ class PublicProduct(_Base):
|
|
|
863
878
|
#: How the embed shows it; the element's ``desktop`` / ``mobile`` attributes override these.
|
|
864
879
|
viewer_desktop: ViewerDesktopMode = ViewerDesktopMode.VIEWER
|
|
865
880
|
viewer_mobile: ViewerMobileMode = ViewerMobileMode.VIEWER
|
|
881
|
+
#: Whether the viewer shows the disclaimer that the model might differ from the product (the
|
|
882
|
+
#: organization's setting; on by default).
|
|
883
|
+
viewer_disclaimer: bool = True
|
|
866
884
|
|
|
867
885
|
|
|
868
886
|
class Ticket(_Base):
|
|
@@ -885,9 +903,9 @@ class ProductListResponse(_Base):
|
|
|
885
903
|
class ProductBatchResponse(_Base):
|
|
886
904
|
"""Per-id outcome; 200 even when some ids were missing."""
|
|
887
905
|
|
|
888
|
-
affected: list[str]
|
|
889
|
-
not_found: list[str]
|
|
890
|
-
forbidden: list[str]
|
|
906
|
+
affected: list[str]
|
|
907
|
+
not_found: list[str]
|
|
908
|
+
forbidden: list[str]
|
|
891
909
|
|
|
892
910
|
|
|
893
911
|
class ProductReviewResponse(_Base):
|
|
@@ -910,9 +928,7 @@ class ProductExportQueued(_Base):
|
|
|
910
928
|
|
|
911
929
|
class ApiKey(_Base):
|
|
912
930
|
id: str
|
|
913
|
-
#
|
|
914
|
-
org_id: str | None = None
|
|
915
|
-
project_id: str | None = None
|
|
931
|
+
org_id: str | None = None # a key binds to its org
|
|
916
932
|
key_type: KeyType
|
|
917
933
|
key_prefix: str
|
|
918
934
|
name: str | None = None
|
|
@@ -965,15 +981,15 @@ class UsageProductTotals(_Base):
|
|
|
965
981
|
|
|
966
982
|
product_id: str
|
|
967
983
|
title: str | None = None
|
|
968
|
-
totals: dict[str, int]
|
|
984
|
+
totals: dict[str, int]
|
|
969
985
|
|
|
970
986
|
|
|
971
987
|
class UsageResponse(_Base):
|
|
972
988
|
start: datetime
|
|
973
989
|
end: datetime
|
|
974
990
|
granularity: Literal["hour", "day"]
|
|
975
|
-
buckets: list[UsageBucket]
|
|
976
|
-
totals: dict[str, int]
|
|
991
|
+
buckets: list[UsageBucket]
|
|
992
|
+
totals: dict[str, int]
|
|
977
993
|
#: event_type -> duration aggregate over the whole window. Only ever keyed by
|
|
978
994
|
#: ``ar_session_ended``; the key is absent when nothing in the window carried one.
|
|
979
995
|
durations: dict[str, UsageDuration] = Field(default_factory=dict)
|
|
@@ -993,9 +1009,7 @@ class TagsResponse(_Base):
|
|
|
993
1009
|
|
|
994
1010
|
class WebhookEndpoint(_Base):
|
|
995
1011
|
id: str
|
|
996
|
-
#
|
|
997
|
-
org_id: str | None = None
|
|
998
|
-
project_id: str | None = None
|
|
1012
|
+
org_id: str | None = None # an endpoint binds to its org
|
|
999
1013
|
url: str
|
|
1000
1014
|
description: str | None = None
|
|
1001
1015
|
events: list[WebhookEventType]
|
|
@@ -1024,6 +1038,8 @@ class WebhookDelivery(_Base):
|
|
|
1024
1038
|
succeeded_at: datetime | None = None
|
|
1025
1039
|
last_attempt_at: datetime | None = None
|
|
1026
1040
|
last_error: str | None = None
|
|
1041
|
+
# When the next retry is due; None once it succeeded or its six attempts ran out.
|
|
1042
|
+
next_attempt_at: datetime | None = None
|
|
1027
1043
|
payload_json: dict[str, Any] | None = None
|
|
1028
1044
|
|
|
1029
1045
|
|
|
@@ -1033,19 +1049,6 @@ class WebhookDeliveryListResponse(_Base):
|
|
|
1033
1049
|
offset: int
|
|
1034
1050
|
|
|
1035
1051
|
|
|
1036
|
-
class Project(_Base):
|
|
1037
|
-
id: str
|
|
1038
|
-
org_id: str
|
|
1039
|
-
name: str
|
|
1040
|
-
allowed_domains: list[str] = Field(default_factory=list)
|
|
1041
|
-
always_generate: bool = False
|
|
1042
|
-
created_at: datetime
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
class ProjectListResponse(_Base):
|
|
1046
|
-
data: list[Project]
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
1052
|
class HealthResponse(_Base):
|
|
1050
1053
|
status: str = "ok"
|
|
1051
1054
|
version: str | None = None
|
|
@@ -276,6 +276,7 @@ def test_the_public_projection_carries_a_paintings_settings() -> None:
|
|
|
276
276
|
# Absent from an older API's response: the default the embed always had.
|
|
277
277
|
assert product.viewer_desktop is ViewerDesktopMode.VIEWER
|
|
278
278
|
assert product.viewer_mobile is ViewerMobileMode.VIEWER
|
|
279
|
+
assert product.viewer_disclaimer is True
|
|
279
280
|
|
|
280
281
|
|
|
281
282
|
def test_update_sends_the_embed_display_modes_and_reads_them_back() -> None:
|
|
@@ -417,6 +418,32 @@ def test_products_export_answers_a_queued_export() -> None:
|
|
|
417
418
|
assert result.to_finish == 15 and result.notify_email == "a@example.com"
|
|
418
419
|
|
|
419
420
|
|
|
421
|
+
def test_products_qr_returns_the_png_bytes() -> None:
|
|
422
|
+
client, rec = make_client(
|
|
423
|
+
httpx.Response(200, content=b"\x89PNG\r\n", headers={"content-type": "image/png"})
|
|
424
|
+
)
|
|
425
|
+
png = client.products.qr("p1", guide=True, size=512)
|
|
426
|
+
|
|
427
|
+
assert png == b"\x89PNG\r\n"
|
|
428
|
+
assert rec.request is not None
|
|
429
|
+
assert rec.request.url.path == "/v1/products/p1/qr"
|
|
430
|
+
assert rec.request.url.params["guide"] == "true"
|
|
431
|
+
assert rec.request.url.params["size"] == "512"
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
def test_products_qr_defaults_to_the_minimal_1024_square() -> None:
|
|
435
|
+
client, rec = make_client(httpx.Response(200, content=b"\x89PNG"))
|
|
436
|
+
client.products.qr("p1")
|
|
437
|
+
|
|
438
|
+
assert rec.request is not None
|
|
439
|
+
assert rec.request.url.params["guide"] == "false"
|
|
440
|
+
assert rec.request.url.params["size"] == "1024"
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
def test_product_carries_its_viewer_url() -> None:
|
|
444
|
+
assert Product.model_fields["viewer_url"].default is None
|
|
445
|
+
|
|
446
|
+
|
|
420
447
|
def test_usage_group_by_product_ranks_and_names_them() -> None:
|
|
421
448
|
body = {
|
|
422
449
|
"start": "2026-09-01T00:00:00Z",
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"""Drift guard: the hand-written models in `viewrium._models` against the API's public OpenAPI
|
|
2
|
+
schema (`apps/api/openapi.json`, the file the JS SDK is generated from).
|
|
3
|
+
|
|
4
|
+
Every public component schema must have a Python counterpart with the same field names and the
|
|
5
|
+
same requiredness (an object), or the same values (an enum). Names differ where the SDK chose a
|
|
6
|
+
friendlier class name (`SCHEMA_TO_MODEL`); anything the SDK deliberately does differently is in
|
|
7
|
+
an allow-list below, each entry with its reason. A new API field fails this test until the SDK
|
|
8
|
+
mirrors it or the difference is allow-listed on purpose.
|
|
9
|
+
|
|
10
|
+
It runs as part of `test` and again as the package's `check` task, which CI runs on every PR
|
|
11
|
+
(unlike `test`, which CI runs only for affected packages).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
from enum import StrEnum
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any
|
|
20
|
+
|
|
21
|
+
import pytest
|
|
22
|
+
from pydantic import BaseModel
|
|
23
|
+
|
|
24
|
+
import viewrium
|
|
25
|
+
from viewrium import _models
|
|
26
|
+
|
|
27
|
+
OPENAPI_PATH = Path(__file__).resolve().parents[3] / "apps" / "api" / "openapi.json"
|
|
28
|
+
|
|
29
|
+
# OpenAPI component name -> `viewrium._models` class name, where they differ.
|
|
30
|
+
SCHEMA_TO_MODEL: dict[str, str] = {
|
|
31
|
+
"ApiKeyResponse": "ApiKey",
|
|
32
|
+
"ModelPlanResponse": "ModelPlan",
|
|
33
|
+
"ProductExportQueuedResponse": "ProductExportQueued",
|
|
34
|
+
"ProductImageResponse": "ProductImage",
|
|
35
|
+
"ProductModelResponse": "ProductModel",
|
|
36
|
+
"ProductOrderParkedResponse": "ProductOrderParked",
|
|
37
|
+
"ProductParkedResponse": "ProductParked",
|
|
38
|
+
"ProductResponse": "Product",
|
|
39
|
+
"ProductSourceResponse": "ProductSource",
|
|
40
|
+
"PublicProductResponse": "PublicProduct",
|
|
41
|
+
"TicketResponse": "Ticket",
|
|
42
|
+
"WebhookDeliveryResponse": "WebhookDelivery",
|
|
43
|
+
"WebhookEndpointResponse": "WebhookEndpoint",
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
# Component schemas with no Python model, on purpose.
|
|
47
|
+
UNMODELLED: dict[str, str] = {
|
|
48
|
+
"ErrorEnvelope": "parsed into the ViewriumError hierarchy (_errors.py), not a model",
|
|
49
|
+
"ErrorDetail": "parsed into the ViewriumError hierarchy (_errors.py), not a model",
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# (component, field) pairs whose requiredness differs on purpose.
|
|
53
|
+
REQUIREDNESS_EXCEPTIONS: dict[tuple[str, str], str] = {}
|
|
54
|
+
|
|
55
|
+
# (component, field) pairs present on one side only, on purpose.
|
|
56
|
+
FIELD_EXCEPTIONS: dict[tuple[str, str], str] = {}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _schemas() -> dict[str, dict[str, Any]]:
|
|
60
|
+
document = json.loads(OPENAPI_PATH.read_text(encoding="utf-8"))
|
|
61
|
+
schemas: dict[str, dict[str, Any]] = document["components"]["schemas"]
|
|
62
|
+
return schemas
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
SCHEMAS = _schemas()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _model_for(name: str) -> type[Any] | None:
|
|
69
|
+
found = getattr(_models, SCHEMA_TO_MODEL.get(name, name), None)
|
|
70
|
+
return found if isinstance(found, type) else None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@pytest.mark.parametrize("name", sorted(SCHEMAS))
|
|
74
|
+
def test_every_public_schema_has_a_python_counterpart(name: str) -> None:
|
|
75
|
+
if name in UNMODELLED:
|
|
76
|
+
return
|
|
77
|
+
model = _model_for(name)
|
|
78
|
+
assert model is not None, (
|
|
79
|
+
f"OpenAPI schema {name!r} has no model in viewrium._models "
|
|
80
|
+
f"(add one, map it in SCHEMA_TO_MODEL, or allow-list it in UNMODELLED with a reason)"
|
|
81
|
+
)
|
|
82
|
+
# The docs' object pages name every model as `viewrium.<Name>`.
|
|
83
|
+
assert getattr(viewrium, model.__name__, None) is model, (
|
|
84
|
+
f"{model.__name__} is not exported from the viewrium package"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@pytest.mark.parametrize("name", sorted(n for n, s in SCHEMAS.items() if "enum" in s))
|
|
89
|
+
def test_enum_values_match(name: str) -> None:
|
|
90
|
+
model = _model_for(name)
|
|
91
|
+
if model is None:
|
|
92
|
+
pytest.skip("reported by test_every_public_schema_has_a_python_counterpart")
|
|
93
|
+
assert issubclass(model, StrEnum), f"{name}: expected a StrEnum, got {model!r}"
|
|
94
|
+
assert {m.value for m in model} == set(SCHEMAS[name]["enum"]), f"{name}: enum values differ"
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@pytest.mark.parametrize("name", sorted(n for n, s in SCHEMAS.items() if "properties" in s))
|
|
98
|
+
def test_object_fields_and_requiredness_match(name: str) -> None:
|
|
99
|
+
if name in UNMODELLED:
|
|
100
|
+
return
|
|
101
|
+
model = _model_for(name)
|
|
102
|
+
if model is None:
|
|
103
|
+
pytest.skip("reported by test_every_public_schema_has_a_python_counterpart")
|
|
104
|
+
assert issubclass(model, BaseModel), f"{name}: expected a pydantic model, got {model!r}"
|
|
105
|
+
schema = SCHEMAS[name]
|
|
106
|
+
api_fields = set(schema["properties"])
|
|
107
|
+
py_fields = set(model.model_fields)
|
|
108
|
+
one_sided = {f for f in api_fields ^ py_fields if (name, f) not in FIELD_EXCEPTIONS}
|
|
109
|
+
assert not one_sided, (
|
|
110
|
+
f"{name} vs {model.__name__}: only in the API {sorted(api_fields - py_fields)}, "
|
|
111
|
+
f"only in the SDK {sorted(py_fields - api_fields)}"
|
|
112
|
+
)
|
|
113
|
+
api_required = set(schema.get("required", []))
|
|
114
|
+
mismatched = sorted(
|
|
115
|
+
f
|
|
116
|
+
for f in api_fields & py_fields
|
|
117
|
+
if (f in api_required) != model.model_fields[f].is_required()
|
|
118
|
+
and (name, f) not in REQUIREDNESS_EXCEPTIONS
|
|
119
|
+
)
|
|
120
|
+
assert not mismatched, (
|
|
121
|
+
f"{name} vs {model.__name__}: requiredness differs for {mismatched} "
|
|
122
|
+
f"(API required: {sorted(api_required & set(mismatched))})"
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def test_allow_lists_name_real_entries() -> None:
|
|
127
|
+
"""A stale allow-list entry hides nothing and would let the next real drift through."""
|
|
128
|
+
for name in UNMODELLED:
|
|
129
|
+
assert name in SCHEMAS, f"UNMODELLED names {name!r}, which the schema no longer has"
|
|
130
|
+
for name in SCHEMA_TO_MODEL:
|
|
131
|
+
assert name in SCHEMAS, f"SCHEMA_TO_MODEL maps {name!r}, which the schema no longer has"
|
|
132
|
+
for name, field in REQUIREDNESS_EXCEPTIONS:
|
|
133
|
+
assert field in SCHEMAS.get(name, {}).get("properties", {}), (
|
|
134
|
+
f"REQUIREDNESS_EXCEPTIONS names {name}.{field}, which the schema no longer has"
|
|
135
|
+
)
|
|
136
|
+
for name, _field in FIELD_EXCEPTIONS:
|
|
137
|
+
assert name in SCHEMAS, f"FIELD_EXCEPTIONS names {name!r}, which the schema no longer has"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://turborepo.dev/schema.json",
|
|
3
|
+
"extends": ["//"],
|
|
4
|
+
"tags": ["package"],
|
|
5
|
+
"tasks": {
|
|
6
|
+
"build": {
|
|
7
|
+
"outputs": []
|
|
8
|
+
},
|
|
9
|
+
"test": {
|
|
10
|
+
"inputs": ["$TURBO_DEFAULT$", "$TURBO_ROOT$/apps/api/openapi.json"]
|
|
11
|
+
},
|
|
12
|
+
"check": {
|
|
13
|
+
"inputs": ["$TURBO_DEFAULT$", "$TURBO_ROOT$/apps/api/openapi.json"]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
viewrium-2.3.0/turbo.json
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|