forked from justoneapi/justoneapi-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_codegen.py
More file actions
70 lines (57 loc) · 2.04 KB
/
test_codegen.py
File metadata and controls
70 lines (57 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from __future__ import annotations
from pathlib import Path
from tools.sdk_codegen import (
build_diff_summary,
collect_resources,
load_json,
load_overrides,
normalize_spec,
)
RAW_SPEC_PATH = Path("openapi/public-api.json")
OVERRIDES_PATH = Path("openapi/sdk_overrides.yaml")
def test_normalize_spec_removes_token_and_adds_security_scheme():
normalized = normalize_spec(
load_json(RAW_SPEC_PATH), load_overrides(OVERRIDES_PATH)
)
search_operation = normalized["paths"]["/api/search/v1"]["get"]
assert search_operation["x-sdk-resource"] == "search"
assert search_operation["x-sdk-method-name"] == "search_v1"
assert all(
parameter["name"] != "token" for parameter in search_operation["parameters"]
)
assert normalized["components"]["securitySchemes"]["tokenAuth"]["name"] == "token"
def test_collect_resources_matches_expected_counts():
normalized = normalize_spec(
load_json(RAW_SPEC_PATH), load_overrides(OVERRIDES_PATH)
)
resources = collect_resources(normalized)
assert len(resources) == 25
assert sum(len(resource.operations) for resource in resources) == 201
namespace_set = {resource.namespace for resource in resources}
assert {"douyin", "douyin_xingtu", "tiktok_shop", "xiaohongshu_pgy"}.issubset(
namespace_set
)
def test_diff_summary_reports_operation_changes():
old_spec = {
"paths": {
"/api/demo/v1": {
"get": {"operationId": "demoV1", "summary": "old"},
}
},
"tags": [],
}
new_spec = {
"paths": {
"/api/demo/v1": {
"get": {"operationId": "demoV1", "summary": "new"},
},
"/api/demo/v2": {
"get": {"operationId": "demoV2", "summary": "added"},
},
},
"tags": [],
}
summary = build_diff_summary(old_spec, new_spec)
assert "demoV2 [GET /api/demo/v2]" in summary
assert "demoV1 [GET /api/demo/v1]" in summary
assert "Changed operationId count: 1" in summary