|
14 | 14 | # License for the specific language governing permissions and limitations |
15 | 15 | # under the License. |
16 | 16 |
|
| 17 | +import os |
17 | 18 | import pytest |
18 | 19 | import requests |
19 | 20 | import yaml |
20 | 21 |
|
21 | 22 | from genesis_core.elements.dm.validate import ( |
22 | 23 | validate_manifest, |
23 | 24 | dump_full_manifest_schema, |
| 25 | + build_full_schema, |
24 | 26 | ) |
| 27 | +from genesis_core.common import exceptions |
| 28 | +from genesis_core.common.utils import PROJECT_PATH |
25 | 29 |
|
26 | 30 | REPO_URL = "https://repository.genesis-core.tech/genesis-elements" |
27 | 31 |
|
@@ -49,41 +53,29 @@ def test_validate_manifests( |
49 | 53 | validate_manifest(manifest, base_manifest_schema) |
50 | 54 | validate_manifest(manifest, full_manifest_schema) |
51 | 55 |
|
| 56 | + @pytest.mark.parametrize( |
| 57 | + "invalid_manifest", |
| 58 | + [ |
| 59 | + "invalid_exports.yaml", |
| 60 | + "invalid_imports.yaml", |
| 61 | + "invalid_resource.yaml", |
| 62 | + ], |
| 63 | + ) |
| 64 | + def test_validate_error( |
| 65 | + self, invalid_manifest, base_manifest_schema, full_manifest_schema |
| 66 | + ): |
| 67 | + with open( |
| 68 | + os.path.join( |
| 69 | + PROJECT_PATH, "genesis", "manifests", "examples", invalid_manifest |
| 70 | + ), |
| 71 | + "r", |
| 72 | + ) as f: |
| 73 | + manifest = yaml.safe_load(f) |
| 74 | + with pytest.raises(exceptions.OpenApiValidateException): |
| 75 | + validate_manifest(manifest, base_manifest_schema) |
| 76 | + validate_manifest(manifest, full_manifest_schema) |
| 77 | + |
52 | 78 | @pytest.mark.skip(reason="for manual running") |
53 | 79 | def test_build_full_schema(self, base_manifest_schema, user_api_spec): |
54 | | - path_schema = [] |
55 | | - for path, path_obj in user_api_spec["paths"].items(): |
56 | | - path_parts = path.split("/") |
57 | | - if len(path_parts) > 5: |
58 | | - continue |
59 | | - post_path = path_obj.get("post") |
60 | | - if post_path: |
61 | | - operation_id = post_path.get("operationId") |
62 | | - if operation_id and operation_id.startswith("Create_v1"): |
63 | | - schema_ref = post_path["requestBody"]["content"][ |
64 | | - "application/json" |
65 | | - ]["schema"] |
66 | | - model_name = schema_ref["$ref"].split("/")[-1] |
67 | | - api_part_1 = path_parts[2] |
68 | | - api_part_2 = path_parts[3] |
69 | | - model = user_api_spec["components"]["schemas"][model_name] |
70 | | - resource = f"$core.{api_part_1}.{api_part_2}" |
71 | | - path_schema.append( |
72 | | - { |
73 | | - "path": path, |
74 | | - "schema": schema_ref, |
75 | | - "resource": resource, |
76 | | - "model_name": model_name, |
77 | | - "model": model, |
78 | | - } |
79 | | - ) |
80 | | - base_manifest_schema["components"]["schemas"][model_name] = model |
81 | | - base_manifest_schema["properties"]["resources"]["properties"][ |
82 | | - resource |
83 | | - ] = { |
84 | | - "type": "object", |
85 | | - "additionalProperties": schema_ref, |
86 | | - } |
87 | | - |
88 | | - assert path_schema |
89 | | - dump_full_manifest_schema(base_manifest_schema) |
| 80 | + full_schema = build_full_schema(base_manifest_schema, user_api_spec) |
| 81 | + dump_full_manifest_schema(full_schema) |
0 commit comments