AAS HTTP Client Documentation
Loading...
Searching...
No Matches
test_sdk_tools.py
Go to the documentation of this file.
1from basyx.aas import model
2from aas_http_client.utilities import encoder
3import aas_http_client.utilities.model_builder as model_builder
5import pytest
6
7SM_ID = "fluid40/sm_sdk_tools_unit_tests"
8SHELL_ID = "fluid40/aas_sdk_tools_unit_tests"
9
10@pytest.fixture(scope="module")
11def shared_sm() -> model.Submodel:
12 # create a Submodel
13 return model_builder.create_base_submodel(identifier=SM_ID, id_short="sm_http_client_unit_tests", display_name="Submodel HTTP Client Unit Tests", description="This is a sample Submodel created for unit testing of the AAS HTTP Client.")
14
15@pytest.fixture(scope="module")
16def shared_sm_temp() -> model.Submodel:
17 # create a Submodel
18 return model_builder.create_base_submodel(identifier=f"{SM_ID}_temp", id_short="sm_http_client_unit_tests", display_name="Submodel HTTP Client Unit Tests", description="This is a sample Submodel created for unit testing of the AAS HTTP Client.")
19
20@pytest.fixture(scope="module")
21def shared_aas() -> model.AssetAdministrationShell:
22 # create an AAS
23 aas = model_builder.create_base_aas(identifier=SHELL_ID, id_short="aas_http_client_unit_tests", global_asset_identifier=SHELL_ID, display_name="AAS HTTP Client Unit Tests", description="This is a sample AAS created for unit testing of the AAS HTTP Client.")
24 return aas
25
26def test_001a_add_sm_to_shell(shared_aas: model.AssetAdministrationShell, shared_sm: model.Submodel):
27 assert len(shared_aas.submodel) == 0
28
29 result = sdk_tools.add_submodel_to_aas(shared_aas, shared_sm)
30 assert result is True
31 assert len(shared_aas.submodel) == 1
32
33 assert shared_sm.id in sdk_tools.get_submodel_ids(shared_aas)
34
35
36def test_001b_add_sm_to_shell(shared_aas: model.AssetAdministrationShell, shared_sm: model.Submodel):
37 assert len(shared_aas.submodel) == 1
38
39 result = sdk_tools.add_submodel_to_aas(shared_aas, shared_sm)
40 assert result is False
41 assert len(shared_aas.submodel) == 1
42
43def test_002a_remove_sm_from_shell(shared_aas: model.AssetAdministrationShell, shared_sm_temp: model.Submodel):
44 assert len(shared_aas.submodel) == 1
45
46 result = sdk_tools.remove_submodel_from_aas(shared_aas, shared_sm_temp)
47 assert result is False
48 assert len(shared_aas.submodel) == 1
49
50def test_002b_remove_sm_from_shell(shared_aas: model.AssetAdministrationShell, shared_sm: model.Submodel):
51 assert len(shared_aas.submodel) == 1
52
53 result = sdk_tools.remove_submodel_from_aas(shared_aas, shared_sm)
54 assert result is True
55 assert len(shared_aas.submodel) == 0
model.Submodel shared_sm()
model.Submodel shared_sm_temp()
test_001a_add_sm_to_shell(model.AssetAdministrationShell shared_aas, model.Submodel shared_sm)
test_001b_add_sm_to_shell(model.AssetAdministrationShell shared_aas, model.Submodel shared_sm)
test_002a_remove_sm_from_shell(model.AssetAdministrationShell shared_aas, model.Submodel shared_sm_temp)
model.AssetAdministrationShell shared_aas()
test_002b_remove_sm_from_shell(model.AssetAdministrationShell shared_aas, model.Submodel shared_sm)