|
|
@@ -0,0 +1,78 @@
|
|
|
+import re
|
|
|
+from pathlib import Path
|
|
|
+
|
|
|
+
|
|
|
+ROOT = Path(__file__).resolve().parents[1]
|
|
|
+ROUTES = ROOT / "frontend/src/router/routes.js"
|
|
|
+CATALOG = ROOT / "frontend/src/views/dataService/dataProduct/index.vue"
|
|
|
+GOVERNANCE = ROOT / "frontend/src/views/dataService/productGovernance/index.vue"
|
|
|
+
|
|
|
+
|
|
|
+def _route_block(source: str, *, indent: int, name: str) -> str:
|
|
|
+ start_token = "\n" + " " * indent + "{\n"
|
|
|
+ name_token = " " * (indent + 2) + f"name: '{name}'"
|
|
|
+ assert source.count(name_token) == 1, f"route {name!r} must be unique"
|
|
|
+
|
|
|
+ name_at = source.index(name_token)
|
|
|
+ start = source.rfind(start_token, 0, name_at)
|
|
|
+ if start >= 0:
|
|
|
+ start += 1
|
|
|
+ elif source.startswith(start_token[1:]):
|
|
|
+ start = 0
|
|
|
+
|
|
|
+ terminators = [
|
|
|
+ "\n" + " " * indent + "},",
|
|
|
+ "\n" + " " * indent + "}",
|
|
|
+ ]
|
|
|
+ ends = [(source.find(token, name_at), token) for token in terminators]
|
|
|
+ valid_ends = [(end, token) for end, token in ends if end >= 0]
|
|
|
+ assert start >= 0 and valid_ends, f"route {name!r} block boundaries not found"
|
|
|
+ end, end_token = min(valid_ends)
|
|
|
+ return source[start : end + len(end_token)]
|
|
|
+
|
|
|
+
|
|
|
+def _assert_exact_line(block: str, *, indent: int, field: str, value: str) -> None:
|
|
|
+ expected = " " * indent + f"{field}: {value}"
|
|
|
+ assert re.search(rf"(?m)^{re.escape(expected)},?$", block), (
|
|
|
+ f"missing exact line: {expected}"
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def test_data_service_product_routes_use_clear_names_and_stable_identity():
|
|
|
+ routes = ROUTES.read_text(encoding="utf-8")
|
|
|
+ catalog = _route_block(routes, indent=8, name="dataProduct")
|
|
|
+ governance = _route_block(routes, indent=8, name="productGovernance")
|
|
|
+
|
|
|
+ for field in ("title", "label"):
|
|
|
+ _assert_exact_line(catalog, indent=10, field=field, value="'数据产品目录'")
|
|
|
+ _assert_exact_line(
|
|
|
+ governance, indent=10, field=field, value="'产品治理与运营'"
|
|
|
+ )
|
|
|
+
|
|
|
+ for field, value in (
|
|
|
+ ("path", "'/dataService/dataProduct'"),
|
|
|
+ ("component", "'dataService/dataProduct'"),
|
|
|
+ ("name", "'dataProduct'"),
|
|
|
+ ):
|
|
|
+ _assert_exact_line(catalog, indent=10, field=field, value=value)
|
|
|
+
|
|
|
+ for field, value in (
|
|
|
+ ("path", "'/dataService/productGovernance'"),
|
|
|
+ ("component", "'dataService/productGovernance'"),
|
|
|
+ ("name", "'productGovernance'"),
|
|
|
+ ):
|
|
|
+ _assert_exact_line(governance, indent=10, field=field, value=value)
|
|
|
+
|
|
|
+ assert "permissions: ['data-products:read']" in governance
|
|
|
+ assert '"title":"数据产品目录"' in catalog
|
|
|
+ assert '"title":"产品治理与运营"' in governance
|
|
|
+
|
|
|
+
|
|
|
+def test_data_service_product_pages_match_navigation_names():
|
|
|
+ catalog = CATALOG.read_text(encoding="utf-8")
|
|
|
+ governance = GOVERNANCE.read_text(encoding="utf-8")
|
|
|
+
|
|
|
+ assert re.search(r"<h1[^>]*>数据产品目录</h1>", catalog)
|
|
|
+ assert "查看和使用数据工厂产出的数据产品" in catalog
|
|
|
+ assert re.search(r"<h1[^>]*>产品治理与运营</h1>", governance)
|
|
|
+ assert "围绕责任人、申请审批、数据合同、产品合格证和用户反馈" in governance
|