diff --git a/src/cript/nodes/core.py b/src/cript/nodes/core.py index 382c6021b..0eb0d4f0d 100644 --- a/src/cript/nodes/core.py +++ b/src/cript/nodes/core.py @@ -250,6 +250,7 @@ def get_json( is_patch: bool = False, condense_to_uuid: Dict[str, Set[str]] = { "Material": {"parent_material", "component"}, + "Experiment": {"data"}, "Inventory": {"material"}, "Ingredient": {"material"}, "Property": {"component"}, diff --git a/src/cript/nodes/util/__init__.py b/src/cript/nodes/util/__init__.py index a659de1e2..a9b4522c6 100644 --- a/src/cript/nodes/util/__init__.py +++ b/src/cript/nodes/util/__init__.py @@ -104,7 +104,7 @@ def default(self, obj): pass else: if uid in NodeEncoder.handled_ids: - return {"node": obj._json_attrs.node, "uid": uid} + return {"uid": uid} # When saving graphs, some nodes can be pre-saved. # If that happens, we want to represent them as a UUID edge only @@ -282,12 +282,12 @@ def __call__(self, node_str: Union[dict, str]) -> dict: node_dict = dict(node_str) # type: ignore # Handle UID objects. - if len(node_dict) == 2 and "uid" in node_dict and "node" in node_dict: + if len(node_dict) == 1 and "uid" in node_dict: try: return self._uid_cache[node_dict["uid"]] except KeyError: # TODO if we convince beartype to accept Proxy temporarily, enable return instead of raise - raise CRIPTDeserializationUIDError(node_dict["node"], node_dict["uid"]) + raise CRIPTDeserializationUIDError("Unknown", node_dict["uid"]) # return _UIDProxy(node_dict["uid"]) try: diff --git a/src/cript/nodes/util/material_deserialization.py b/src/cript/nodes/util/material_deserialization.py index c836ae421..2bbf5d142 100644 --- a/src/cript/nodes/util/material_deserialization.py +++ b/src/cript/nodes/util/material_deserialization.py @@ -68,7 +68,7 @@ def _deserialize_flattened_material_identifiers(json_dict: Dict) -> Dict: identifier_argument.append({identifier: json_dict[identifier]}) # delete identifiers from the API JSON response as they are added to the material node del json_dict[identifier] - if len(identifier_argument) > 0: - json_dict["identifiers"] = identifier_argument + + json_dict["identifiers"] = identifier_argument return json_dict diff --git a/tests/conftest.py b/tests/conftest.py index a1ef62777..4e6fe124c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,9 +17,23 @@ import cript + +def _get_cript_tests_env() -> bool: + """ + Gets `CRIPT_TESTS` value from env variable and converts it to boolean. + If `CRIPT_TESTS` env var does not exist then it will default it to False. + """ + try: + has_integration_tests_enabled = os.getenv("CRIPT_TESTS").title().strip() == "True" + except AttributeError: + has_integration_tests_enabled = True + + return has_integration_tests_enabled + + # flip integration tests ON or OFF with this boolean # automatically gets value env vars to run integration tests -HAS_INTEGRATION_TESTS_ENABLED: bool = os.getenv("CRIPT_TESTS").title() == "True" +HAS_INTEGRATION_TESTS_ENABLED: bool = _get_cript_tests_env() @pytest.fixture(scope="session", autouse=True) diff --git a/tests/integration_test_helper.py b/tests/integration_test_helper.py index ac84bf5b8..e3b34d902 100644 --- a/tests/integration_test_helper.py +++ b/tests/integration_test_helper.py @@ -1,5 +1,4 @@ import json -import warnings import pytest from conftest import HAS_INTEGRATION_TESTS_ENABLED @@ -96,8 +95,4 @@ def integrate_nodes_helper(cript_api: cript.API, project_node: cript.Project): print("\n\n=================== Project Node Deserialized =========================") print(my_project_from_api.get_json(sort_keys=False, condense_to_uuid={}, indent=2).json) print("==============================================================") - print("\n\n\n######################################## TEST Passed ########################################\n\n\n") - - warnings.warn("Please uncomment `integrate_nodes_helper` to test with the API") - pass diff --git a/tests/nodes/primary_nodes/test_experiment.py b/tests/nodes/primary_nodes/test_experiment.py index 5cec75474..4f6435f6f 100644 --- a/tests/nodes/primary_nodes/test_experiment.py +++ b/tests/nodes/primary_nodes/test_experiment.py @@ -150,7 +150,7 @@ def test_experiment_json(simple_process_node, simple_computation_node, simple_co ], } ], - "data": [{"node": ["Data"]}], + "data": [{}], "funding": ["National Science Foundation", "IRIS", "NIST"], "citation": [ { diff --git a/tests/nodes/primary_nodes/test_project.py b/tests/nodes/primary_nodes/test_project.py index 4e4600930..65d2e63a1 100644 --- a/tests/nodes/primary_nodes/test_project.py +++ b/tests/nodes/primary_nodes/test_project.py @@ -50,8 +50,8 @@ def test_serialize_project_to_json(complex_project_node, complex_project_dict) - expected_dict = complex_project_dict # Since we condense those to UUID we remove them from the expected dict. - expected_dict["admin"] = [{"node": ["User"]}] - expected_dict["member"] = [{"node": ["User"]}] + expected_dict["admin"] = [{}] + expected_dict["member"] = [{}] # comparing dicts instead of JSON strings because dict comparison is more accurate serialized_project: dict = json.loads(complex_project_node.get_json(condense_to_uuid={}).json) diff --git a/tests/test_node_util.py b/tests/test_node_util.py index 882961baa..38c9a0c60 100644 --- a/tests/test_node_util.py +++ b/tests/test_node_util.py @@ -54,7 +54,7 @@ def test_uid_deserialization(simple_algorithm_node, complex_parameter_node, simp "type": "value", "value": 5.0, "unit": "GPa", - "computation": [{"node": ["Computation"], "uid": "_:9ddda2c0-ff8c-4ce3-beb0-e0cafb6169ef"}], + "computation": [{"uid": "_:9ddda2c0-ff8c-4ce3-beb0-e0cafb6169ef"}], }, { "node": ["Property"], @@ -66,7 +66,6 @@ def test_uid_deserialization(simple_algorithm_node, complex_parameter_node, simp "unit": "GPa", "computation": [ { - "node": ["Computation"], "uid": "_:9ddda2c0-ff8c-4ce3-beb0-e0cafb6169ef", } ],