-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmoke_test.py
More file actions
329 lines (281 loc) · 11 KB
/
smoke_test.py
File metadata and controls
329 lines (281 loc) · 11 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/usr/bin/env python3
"""
SDK smoke tests (curl-like coverage)
Env:
DATENO_SERVER_URL default: https://api.test.dateno.io
DATENO_APIKEY required for almost all endpoints
Run:
DATENO_APIKEY=... python smoke_sdk_all.py
DATENO_SERVER_URL=http://127.0.0.1:8100 DATENO_APIKEY=... python smoke_sdk_all.py
"""
from __future__ import annotations
import os
import sys
from typing import Any, Iterable, Optional
def _env(name: str, default: Optional[str] = None) -> Optional[str]:
v = os.getenv(name)
if v is None or v == "":
return default
return v
def _pick_attr(obj: Any, candidates: Iterable[str], *, what: str) -> Any:
for name in candidates:
if hasattr(obj, name):
return getattr(obj, name)
raise AttributeError(f"Cannot find {what}. Tried: {', '.join(candidates)}")
def _call(obj: Any, method_candidates: Iterable[str], /, **kwargs) -> Any:
for name in method_candidates:
fn = getattr(obj, name, None)
if callable(fn):
return fn(**kwargs)
raise AttributeError(
f"Cannot find method on {obj.__class__.__name__}. Tried: {', '.join(method_candidates)}"
)
def _assert(cond: bool, msg: str) -> None:
if not cond:
raise AssertionError(msg)
def main() -> int:
server_url = _env("DATENO_SERVER_URL", "https://api.test.dateno.io")
apikey = _env("DATENO_APIKEY", "ovTReiGfgOjUNrMKCWYmisqxJXuTy8dL")
if not apikey:
print("ERROR: DATENO_APIKEY is required", file=sys.stderr)
return 2
# --- SDK init (apikey via query only; bearer intentionally omitted) ---
from dateno.sdk import SDK
from dateno import models
sdk = SDK(
server_url=server_url,
api_key_query=apikey,
)
print(f"Using server_url={server_url}")
# -------------------
# 1) /healthz
# -------------------
svc = _pick_attr(sdk, ["service", "service_api"], what="service api")
health = _call(svc, ["get_healthz", "healthz", "get_health"],)
_assert(isinstance(health, dict), "healthz: expected dict-like response")
_assert(health.get("status") == "ok", f"healthz: expected status=ok, got {health}")
_assert(health.get("elasticsearch") is True, f"healthz: expected elasticsearch=True, got {health}")
print("[OK] service.get_healthz")
# -------------------
# 2) /registry/catalog/{catalog_id}
# 3) /registry/search/catalogs/?q=...&limit=...&offset=...
# -------------------
catalog_api = _pick_attr(
sdk,
[
"data_catalogs_api",
"catalog_api",
"registry_api",
"catalogs_api",
],
what="catalog/registry api",
)
# --- (2) single catalog by UID
catalog_id = "cdi00001616"
cat = _call(
catalog_api,
[
"get_catalog_by_id", # preferred operation_id naming
"fetch_single_catalog", # router handler name
"get_catalog", # generic SDK naming
"get_registry_catalog", # alternative naming
],
catalog_id=catalog_id,
)
_assert(cat is not None, "registry/catalog: expected non-empty response")
print("[OK] catalog.get_catalog_by_id")
# --- (3) search catalogs
cats = _call(
catalog_api,
[
"search_catalogs", # router handler name (likely)
"list_catalogs", # alternative operation_id naming
"search_data_catalogs", # alternative SDK naming
],
q="environment",
limit=10,
offset=0,
)
# IMPORTANT: This endpoint returns DataCatalogSearchResponse: { meta, data }
data = getattr(cats, "data", None)
if data is None and isinstance(cats, dict):
data = cats.get("data")
_assert(data is not None, "registry/search/catalogs: response has no data field")
_assert(isinstance(data, list), "registry/search/catalogs: data must be a list")
print(f"[OK] catalog.search_catalogs (data={len(data)})")
# -------------------
# 4) /search/0.2/query
# 5) /search/0.1/entry/{entry_id}
# 6) POST /search/0.2/es_search
# 7) /search/0.2/list_facets
# 8) /search/0.2/get_facet?key=...
# 9) /search/0.2/similar/{entry_id}
# -------------------
search_api = _pick_attr(sdk, ["search_api", "search"], what="search api")
q = _call(
search_api,
[
"search_datasets", # your current SDK method
"query", # possible SDK naming
"search_query", # possible SDK naming
],
q="environment",
limit=1,
offset=0,
facets=True,
sort_by="_score",
)
total_val = getattr(getattr(getattr(q, "hits", None), "total", None), "value", None)
_assert(total_val is None or total_val >= 1, f"search/query: expected total>=1, got {q}")
print("[OK] search.search_datasets (/search/0.2/query)")
# pick entry_id from first hit if possible, else use your known id
entry_id = "89dab920d0ff1f03ae44885e7ff021358cb0f531cc81b61579f06b0d4ff4ee28"
try:
hits = getattr(getattr(q, "hits", None), "hits", None)
if hits and len(hits) > 0:
# Speakeasy-style: Hit(id=..., source=...)
entry_id = getattr(hits[0], "id", entry_id) or entry_id
except Exception:
pass
entry = _call(
search_api,
[
"get_dataset_by_entry_id",
"fetch_single_entry", # common naming in older drafts
"get_entry", # possible naming
"get_search_entry", # possible naming
"get_entry_by_id", # possible naming
],
entry_id=entry_id,
)
_assert(entry is not None, "search/entry: expected non-empty response")
print("[OK] search.get_entry (/search/0.1/entry/{entry_id})")
es = _call(
search_api,
[
"search_datasets_dsl",
"es_search",
"post_es_search",
"search_es",
],
limit=1,
offset=0,
facets=True,
sortby="_score",
body={ # <-- ключевой момент: единый request body
"query": {"match_all": {}},
# "post_filter": {"term": {"source.catalog_type": {"value": "Geoportal"}}}, # если нужно
},
)
es_total = getattr(getattr(getattr(es, "hits", None), "total", None), "value", None)
_assert(es_total is None or es_total >= 0, f"search/es_search: unexpected response {es}")
print("[OK] search.es_search (POST /search/0.2/es_search)")
facets = _call(
search_api,
[
"list_search_facets",
"get_facets",
],
)
_assert(facets is not None, "search/list_facets: expected non-empty response")
print("[OK] search.list_facets")
facet_key = "source.catalog_type"
facet = _call(
search_api,
[
"get_search_facet_values",
"facet",
],
key=facet_key,
)
_assert(facet is not None, "search/get_facet: expected non-empty response")
print("[OK] search.get_facet")
similar = _call(
search_api,
[
"get_similar_datasets",
"get_similar",
"get_similar_entries",
],
entry_id=entry_id,
limit=5,
)
_assert(similar is not None, "search/similar: expected non-empty response")
print("[OK] search.similar")
# -------------------
# 10) /raw/0.1/entry/{entry_id}
# -------------------
raw_api = _pick_attr(sdk, ["raw_data_access", "raw", "raw_api"], what="raw api")
raw_entry = _call(
raw_api,
[
"get_raw_entry_by_id",
"get_entry",
"fetch_entry",
"get_raw_entry",
"entry",
],
entry_id=entry_id,
)
_assert(raw_entry is not None, "raw/entry: expected non-empty response")
print("[OK] raw.get_entry")
# -------------------
# 11) /statsdb/0.1/ns
# 12) /statsdb/0.1/ns/{ns}
# 13) /statsdb/0.1/ns/{ns}/tables
# 14) /statsdb/0.1/ns/{ns}/tables/{table}
# 15) /statsdb/0.1/ns/{ns}/indicators
# 16) /statsdb/0.1/ns/{ns}/indicators/{indicator}
# 17) /statsdb/0.1/ns/{ns}/ts
# 18) /statsdb/0.1/ns/{ns}/ts/{ts}
# 19) /statsdb/0.1/list_exportable_formats
# -------------------
stats = _pick_attr(
sdk,
[
"statistics_api",
"statsdb_api",
"stats_api",
"statistics",
],
what="statsdb/statistics api",
)
ns_page = _call(stats, ["list_namespaces", "list_ns", "namespaces"], limit=10)
ns_items = getattr(ns_page, "items", None) if ns_page is not None else None
_assert(ns_items is not None and len(ns_items) >= 1, "statsdb/ns: expected >=1 namespaces")
ns_id = getattr(ns_items[0], "id", None) or "ilostat"
print("[OK] stats.list_namespaces")
ns_obj = _call(stats, ["get_namespace", "get_ns", "namespace"], ns_id=ns_id)
_assert(ns_obj is not None, "statsdb/ns/{ns}: expected namespace object")
print("[OK] stats.get_namespace")
tbl_page = _call(stats, ["list_namespace_tables", "tables"], ns_id=ns_id, limit=10)
tbl_items = getattr(tbl_page, "items", None)
_assert(tbl_items is not None and len(tbl_items) >= 1, "statsdb/tables: expected >=1 tables")
table_id = getattr(tbl_items[0], "id", None) or "CCF_XOXR_CUR_RT_A"
print("[OK] stats.list_tables")
table_obj = _call(stats, ["get_namespace_table", "table"], ns_id=ns_id, table_id=table_id)
_assert(table_obj is not None, "statsdb/table: expected table object")
print("[OK] stats.get_table")
ind_page = _call(stats, ["list_indicators", "list_ind", "indicators"], ns_id=ns_id, limit=10)
ind_items = getattr(ind_page, "items", None)
_assert(ind_items is not None and len(ind_items) >= 1, "statsdb/indicators: expected >=1 indicators")
ind_id = getattr(ind_items[0], "id", None) or "CLD_TPOP_SEX_AGE_NB"
print("[OK] stats.list_indicators")
ind_obj = _call(stats, ["get_namespace_indicator", "get_ind", "indicator"], ns_id=ns_id, ind_id=ind_id)
_assert(ind_obj is not None, "statsdb/indicator: expected indicator object")
print("[OK] stats.get_indicator")
ts_page = _call(stats, ["list_timeseries", "list_ts", "timeseries"], ns_id=ns_id, limit=10)
ts_items = getattr(ts_page, "items", None)
_assert(ts_items is not None and len(ts_items) >= 1, "statsdb/ts: expected >=1 timeseries")
ts_id = getattr(ts_items[0], "id", None) or "CCF_XOXR_CUR_RT.ABW"
print("[OK] stats.list_timeseries")
ts_obj = _call(stats, ["get_timeseries", "get_ts", "timeseries_by_id"], ns_id=ns_id, ts_id=ts_id)
_assert(ts_obj is not None, "statsdb/ts/{ts}: expected timeseries object")
print("[OK] stats.get_timeseries")
exts = _call(stats, ["list_export_formats", "exportable_formats", "list_formats"])
_assert(exts is not None, "statsdb/list_exportable_formats: expected non-empty response")
print("[OK] stats.list_exportable_formats")
print("\nALL OK")
return 0
if __name__ == "__main__":
raise SystemExit(main())