digitalhub 0.9.0__py3-none-any.whl → 0.9.0b1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of digitalhub might be problematic. Click here for more details.

@@ -1,58 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from digitalhub.client._base.key_builder import ClientKeyBuilder
4
-
5
-
6
- class ClientLocalKeyBuilder(ClientKeyBuilder):
7
- """
8
- Class that build the key of entities.
9
- """
10
-
11
- def base_entity_key(self, entity_id: str) -> str:
12
- """
13
- Build for base entity key.
14
-
15
- Parameters
16
- ----------
17
- entity_id : str
18
- Entity id.
19
-
20
- Returns
21
- -------
22
- str
23
- Key.
24
- """
25
- return f"store://{entity_id}"
26
-
27
- def context_entity_key(
28
- self,
29
- project: str,
30
- entity_type: str,
31
- entity_kind: str,
32
- entity_name: str,
33
- entity_id: str | None = None,
34
- ) -> str:
35
- """
36
- Build for context entity key.
37
-
38
- Parameters
39
- ----------
40
- project : str
41
- Project name.
42
- entity_type : str
43
- Entity type.
44
- entity_kind : str
45
- Entity kind.
46
- entity_name : str
47
- Entity name.
48
- entity_id : str
49
- Entity ID.
50
-
51
- Returns
52
- -------
53
- str
54
- Key.
55
- """
56
- if entity_id is None:
57
- return f"store://{project}/{entity_type}/{entity_kind}/{entity_name}"
58
- return f"store://{project}/{entity_type}/{entity_kind}/{entity_name}:{entity_id}"
@@ -1,55 +0,0 @@
1
- import os
2
- import pytest
3
- from glob import glob
4
- from pathlib import Path
5
- import json
6
- from jsonschema import validate
7
- from digitalhub.factory.factory import factory
8
-
9
- entities_path = "test/local/instances/entities"
10
- schemas_path = "test/local/instances/schemas"
11
-
12
- # Build dict: kind -> path to schema file
13
- schemas = {}
14
- for path_to_schema in glob(f"{schemas_path}/**/*.json", recursive=True):
15
- kind = Path(path_to_schema).stem
16
- schemas[kind] = path_to_schema
17
-
18
- # Build dict: name of file to validate -> full path to file
19
- entity_paths = {}
20
- for path_to_file in glob(f"{entities_path}/**/*.json", recursive=True):
21
- file_name = os.path.basename(path_to_file)
22
-
23
- # If a file in a nested directory causes a name collision, use its full path as name
24
- if file_name in entity_paths:
25
- file_name = path_to_file
26
-
27
- entity_paths[file_name] = path_to_file
28
-
29
- # Build object from JSON file using factory
30
- def build_obj(entity_file_path):
31
- with open(entity_file_path) as f:
32
- entity = json.load(f)
33
-
34
- kind = entity["kind"]
35
- spec = entity["spec"]
36
-
37
- built = factory.build_spec(kind, **spec)
38
- return built.to_dict(), kind
39
-
40
- # Validate built object against its kind's schema
41
- def is_valid(built, kind):
42
- with open(schemas[kind]) as schema_file:
43
- schema = json.load(schema_file)
44
-
45
- validate(instance=built, schema=schema)
46
- return True
47
-
48
- # Tests that each JSON file contained in the specified path can successfully be
49
- # used to generate an object through the factory, and that each generated object,
50
- # when exported to dict, validates (through jsonschema) against its kind's schema.
51
- class TestValidate:
52
- @pytest.mark.parametrize('file_name', list(entity_paths.keys()))
53
- def test_validate(self, file_name):
54
- built, kind = build_obj(f"{entity_paths[file_name]}")
55
- assert is_valid(built, kind)