Skip to content

Commit 6443843

Browse files
author
Anonymous Committer
committed
Make OpenAPI resource count tests derive expectations dynamically
1 parent f82364e commit 6443843

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

tests/test_codegen.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@
1414
OVERRIDES_PATH = Path("openapi/sdk_overrides.yaml")
1515

1616

17+
def count_operations(spec: dict) -> int:
18+
return sum(
19+
1
20+
for path_item in spec.get("paths", {}).values()
21+
for method in path_item
22+
if not method.startswith("x-")
23+
)
24+
25+
26+
def collect_resource_namespaces(spec: dict) -> set[str]:
27+
return {
28+
operation["x-sdk-resource"]
29+
for path_item in spec.get("paths", {}).values()
30+
for method, operation in path_item.items()
31+
if not method.startswith("x-")
32+
}
33+
34+
1735
def test_normalize_spec_removes_token_and_adds_security_scheme():
1836
normalized = normalize_spec(
1937
load_json(RAW_SPEC_PATH), load_overrides(OVERRIDES_PATH)
@@ -33,10 +51,14 @@ def test_collect_resources_matches_expected_counts():
3351
load_json(RAW_SPEC_PATH), load_overrides(OVERRIDES_PATH)
3452
)
3553
resources = collect_resources(normalized)
54+
expected_namespaces = collect_resource_namespaces(normalized)
3655

37-
assert len(resources) == 25
38-
assert sum(len(resource.operations) for resource in resources) == 201
3956
namespace_set = {resource.namespace for resource in resources}
57+
assert len(resources) == len(expected_namespaces)
58+
assert sum(len(resource.operations) for resource in resources) == count_operations(
59+
normalized
60+
)
61+
assert namespace_set == expected_namespaces
4062
assert {"douyin", "douyin_xingtu", "tiktok_shop", "xiaohongshu_pgy"}.issubset(
4163
namespace_set
4264
)

tests/test_generated_surface.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
from __future__ import annotations
22

3+
from pathlib import Path
4+
35
from justoneapi import JustOneAPIClient
46
from justoneapi.generated.models import Result
57
from justoneapi.generated.resources import RESOURCE_CLASSES
8+
from tools.sdk_codegen import load_json
9+
10+
NORMALIZED_SPEC_PATH = Path("openapi/public-api.normalized.json")
11+
12+
13+
def expected_resource_namespaces() -> set[str]:
14+
spec = load_json(NORMALIZED_SPEC_PATH)
15+
return {
16+
operation["x-sdk-resource"]
17+
for path_item in spec.get("paths", {}).values()
18+
for method, operation in path_item.items()
19+
if not method.startswith("x-")
20+
}
621

722

823
def test_generated_resource_registry_matches_public_api_surface():
9-
assert len(RESOURCE_CLASSES) == 25
10-
assert "douyin" in RESOURCE_CLASSES
11-
assert "douyin_xingtu" in RESOURCE_CLASSES
12-
assert "xiaohongshu_pgy" in RESOURCE_CLASSES
13-
assert "twitter" in RESOURCE_CLASSES
24+
assert set(RESOURCE_CLASSES) == expected_resource_namespaces()
25+
assert {"douyin", "douyin_xingtu", "xiaohongshu_pgy", "twitter"}.issubset(
26+
RESOURCE_CLASSES
27+
)
1428

1529

1630
def test_client_exposes_generated_resources():

0 commit comments

Comments
 (0)