aas-http-client 0.1.91__tar.gz → 0.2.0__tar.gz

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 aas-http-client might be problematic. Click here for more details.

Files changed (20) hide show
  1. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/PKG-INFO +1 -1
  2. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/aas_http_client/wrapper/sdk_wrapper.py +21 -9
  3. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/aas_http_client.egg-info/PKG-INFO +1 -1
  4. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/aas_http_client.egg-info/SOURCES.txt +1 -3
  5. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/pyproject.toml +1 -1
  6. aas_http_client-0.1.91/tests/test_client_dotnet_server.py +0 -290
  7. aas_http_client-0.1.91/tests/test_client_java_server.py +0 -263
  8. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/LICENSE +0 -0
  9. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/README.md +0 -0
  10. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/aas_http_client/__init__.py +0 -0
  11. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/aas_http_client/client.py +0 -0
  12. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/aas_http_client/core/encoder.py +0 -0
  13. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/aas_http_client/core/version_check.py +0 -0
  14. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/aas_http_client/demo/demo_process.py +0 -0
  15. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/aas_http_client/demo/logging_handler.py +0 -0
  16. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/aas_http_client/utilities/__init__.py +0 -0
  17. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/aas_http_client/utilities/model_builder.py +0 -0
  18. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/aas_http_client.egg-info/dependency_links.txt +0 -0
  19. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/aas_http_client.egg-info/top_level.txt +0 -0
  20. {aas_http_client-0.1.91 → aas_http_client-0.2.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.1.91
3
+ Version: 0.2.0
4
4
  Summary: Generic HTTP client for communicating with various types of AAS servers
5
5
  Author-email: Daniel Klein <daniel.klein@em.ag>
6
6
  License: # :em engineering methods AG Software License
@@ -6,7 +6,7 @@ from pathlib import Path
6
6
 
7
7
  import basyx.aas.adapter.json
8
8
 
9
- from basyx.aas.model import AssetAdministrationShell, Reference, Submodel
9
+ from basyx.aas.model import AssetAdministrationShell, Reference, Submodel, ModelReference
10
10
  from aas_http_client.client import AasHttpClient, _create_client
11
11
  logger = logging.getLogger(__name__)
12
12
 
@@ -37,7 +37,7 @@ class SdkWrapper():
37
37
 
38
38
  return self._client.put_shells(identifier, aas_data)
39
39
 
40
- def put_shells_submodels(self, aas_id: str, submodel_id: str, submodel: Submodel) -> bool:
40
+ def put_shells_submodels_by_id(self, aas_id: str, submodel_id: str, submodel: Submodel) -> bool:
41
41
  """Update a submodel by its ID for a specific Asset Administration Shell (AAS).
42
42
 
43
43
  :param aas_id: ID of the AAS to update the submodel for
@@ -85,11 +85,16 @@ class SdkWrapper():
85
85
  :return: AAS object or None if an error occurred
86
86
  """
87
87
  content: dict = self._client.get_shells_by_id(aas_id)
88
- return json.load(content, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
88
+ aas_dict_string = json.dumps(content)
89
+ return json.loads(aas_dict_string, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
89
90
 
90
91
  def get_shells_reference_by_id(self, aas_id: str) -> Reference | None:
91
- content: dict = self._client.get_shells_reference_by_id(aas_id)
92
- return json.load(content, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
92
+ #workaround because serialization not working
93
+ aas = self.get_shells_by_id(aas_id)
94
+ return ModelReference.from_referable(aas)
95
+
96
+ # content: dict = self._client.get_shells_reference_by_id(aas_id)
97
+ # return json.loads(content, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
93
98
 
94
99
  def get_shells_submodels_by_id(self, aas_id: str, submodel_id: str) -> Submodel | None:
95
100
  """Get a submodel by its ID for a specific Asset Administration Shell (AAS).
@@ -99,7 +104,8 @@ class SdkWrapper():
99
104
  :return: Submodel object or None if an error occurred
100
105
  """
101
106
  content: dict = self._client.get_shells_submodels_by_id(aas_id, submodel_id)
102
- return json.load(content, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
107
+ sm_dict_string = json.dumps(content)
108
+ return json.loads(sm_dict_string, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
103
109
 
104
110
  def delete_shells_by_id(self, aas_id: str) -> bool:
105
111
  """Get an Asset Administration Shell (AAS) by its ID from the REST API.
@@ -176,8 +182,9 @@ class SdkWrapper():
176
182
  if not isinstance(content, dict):
177
183
  logger.error(f"Invalid submodel data: {content}")
178
184
  return None
179
- #
180
- return json.loads(content, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
185
+
186
+ sm_dict_string = json.dumps(content)
187
+ return json.loads(sm_dict_string, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
181
188
 
182
189
  def patch_submodel_by_id(self, submodel_id: str, submodel: Submodel):
183
190
  sm_dict_string = json.dumps(submodel, cls=basyx.aas.adapter.json.AASToJsonEncoder)
@@ -248,5 +255,10 @@ def create_wrapper_by_config(config_file: Path, password: str = "") -> AasHttpCl
248
255
  logger.debug(f"Server config file '{config_file}' found.")
249
256
 
250
257
  wrapper = SdkWrapper()
251
- wrapper._client = _create_client(config_string, password)
258
+ client = _create_client(config_string, password)
259
+
260
+ if not client:
261
+ return None
262
+
263
+ wrapper._client = _create_client(config_string, password)
252
264
  return wrapper
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.1.91
3
+ Version: 0.2.0
4
4
  Summary: Generic HTTP client for communicating with various types of AAS servers
5
5
  Author-email: Daniel Klein <daniel.klein@em.ag>
6
6
  License: # :em engineering methods AG Software License
@@ -13,6 +13,4 @@ aas_http_client/demo/demo_process.py
13
13
  aas_http_client/demo/logging_handler.py
14
14
  aas_http_client/utilities/__init__.py
15
15
  aas_http_client/utilities/model_builder.py
16
- aas_http_client/wrapper/sdk_wrapper.py
17
- tests/test_client_dotnet_server.py
18
- tests/test_client_java_server.py
16
+ aas_http_client/wrapper/sdk_wrapper.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "aas-http-client"
7
- version = "0.1.91"
7
+ version = "0.2.00"
8
8
  description = "Generic HTTP client for communicating with various types of AAS servers"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -1,290 +0,0 @@
1
- import pytest
2
- from pathlib import Path
3
- from aas_http_client.client import create_client_by_config, AasHttpClient
4
- from basyx.aas.model import AssetAdministrationShell, Submodel, MultiLanguageTextType
5
- import aas_http_client.utilities.model_builder as model_builder
6
- import json
7
- import basyx.aas.adapter.json
8
-
9
- @pytest.fixture(scope="module")
10
- def client() -> AasHttpClient:
11
- try:
12
- file = Path("./tests/server_configs/test_dotnet_server_config.json").resolve()
13
-
14
- if not file.exists():
15
- raise FileNotFoundError(f"Configuration file {file} does not exist.")
16
-
17
- client = create_client_by_config(file, password="")
18
- except Exception as e:
19
- raise RuntimeError("Unable to connect to server.")
20
-
21
- shells = client.get_shells()
22
- if shells is None:
23
- raise RuntimeError("No shells found on server. Please check the server configuration.")
24
-
25
- for shell in shells.get("result", []):
26
- id = shell.get("id", "")
27
- client.delete_shells_by_id(id)
28
-
29
- submodels = client.get_submodels()
30
- if submodels is None:
31
- raise RuntimeError("No submodels found on server. Please check the server configuration.")
32
-
33
- for submodel in submodels.get("result", []):
34
- id = submodel.get("id", "")
35
- client.delete_submodels_by_id(id)
36
-
37
- return client
38
-
39
- @pytest.fixture(scope="module")
40
- def shared_sm() -> Submodel:
41
- # create a Submodel
42
- return model_builder.create_base_submodel("sm_http_client_unit_tests", "")
43
-
44
- @pytest.fixture(scope="module")
45
- def shared_aas(client: AasHttpClient, shared_sm: Submodel) -> AssetAdministrationShell:
46
- # create an AAS
47
- aas = model_builder.create_base_ass(id_short="aas_http_client_unit_tests", namespace="")
48
-
49
- # add Submodel to AAS
50
- model_builder.add_submodel_to_aas(aas, shared_sm)
51
-
52
- return aas
53
-
54
- def test_001_connect(client: AasHttpClient):
55
- assert client is not None
56
-
57
- def test_002_get_shells(client: AasHttpClient):
58
- result = client.get_shells()
59
- assert result is not None
60
- shells = result.get("result", [])
61
- assert len(shells) == 0
62
-
63
- def test_003_post_shells(client: AasHttpClient, shared_aas: AssetAdministrationShell):
64
- aas_data_string = json.dumps(shared_aas, cls=basyx.aas.adapter.json.AASToJsonEncoder)
65
- aas_data = json.loads(aas_data_string)
66
- result = client.post_shells(aas_data)
67
-
68
- assert result is not None
69
- result_id_short = result.get("idShort", "")
70
- assert result_id_short == shared_aas.id_short
71
-
72
- get_result = client.get_shells()
73
- assert get_result is not None
74
- shells = get_result.get("result", [])
75
- assert len(shells) == 1
76
- assert shells[0].get("idShort", "") == shared_aas.id_short
77
-
78
- def test_004a_get_shell_by_id(client: AasHttpClient, shared_aas: AssetAdministrationShell):
79
- result = client.get_shells_by_id(shared_aas.id)
80
-
81
- assert result is not None
82
- assert result.get("idShort", "") == shared_aas.id_short
83
-
84
- def test_004b_get_shell_by_id_not_found(client: AasHttpClient):
85
- result = client.get_shells_by_id("non_existent_id")
86
-
87
- assert result is None
88
-
89
- def test_005a_put_shells(client: AasHttpClient, shared_aas: AssetAdministrationShell):
90
- aas = AssetAdministrationShell(id_=shared_aas.asset_information.global_asset_id, asset_information=shared_aas.asset_information)
91
- aas.id_short = shared_aas.id_short
92
-
93
- description_text = "Put description for unit tests"
94
- aas.description = MultiLanguageTextType({"en": description_text})
95
- aas.submodel = shared_aas.submodel # Keep existing submodels
96
-
97
- aas_data_string = json.dumps(aas, cls=basyx.aas.adapter.json.AASToJsonEncoder)
98
- aas_data = json.loads(aas_data_string)
99
-
100
- result = client.put_shells(shared_aas.id, aas_data)
101
-
102
- assert result
103
-
104
- get_result = client.get_shells_by_id(shared_aas.id)
105
-
106
- assert get_result is not None
107
- assert get_result.get("idShort", "") == shared_aas.id_short
108
- assert get_result.get("id", "") == shared_aas.id
109
- # description must have changed
110
- assert get_result.get("description", {})[0].get("text", "") == description_text
111
- assert get_result.get("description", {})[0].get("text", "") != shared_aas.description.get("en", "")
112
- # submodels must be retained
113
- assert len(get_result.get("submodels", [])) == len(shared_aas.submodel)
114
-
115
- # The display name must be empty
116
- # currently not working in dotnet
117
- # assert len(get_result.get("displayName", {})) == 0
118
-
119
- def test_005b_put_shells_with_id(client: AasHttpClient, shared_aas: AssetAdministrationShell):
120
- # put with other ID
121
- id_short = "put_short_id"
122
- asset_info = model_builder.create_base_asset_information(id_short)
123
- aas = AssetAdministrationShell(id_=asset_info.global_asset_id, asset_information=asset_info)
124
- aas.id_short = id_short
125
-
126
- description_text = {"en": "Updated description for unit tests"}
127
- aas.description = MultiLanguageTextType(description_text)
128
-
129
- aas_data_string = json.dumps(shared_aas, cls=basyx.aas.adapter.json.AASToJsonEncoder)
130
- aas_data = json.loads(aas_data_string)
131
-
132
- aas_data["id"] = "updated_id" # Ensure the id is included in the update
133
-
134
- result = client.put_shells(shared_aas.id, aas_data)
135
-
136
- assert not result
137
-
138
- def test_006_get_shells_reference_by_id(client: AasHttpClient, shared_aas: AssetAdministrationShell):
139
- result = client.get_shells_reference_by_id(shared_aas.id)
140
-
141
- assert result
142
- keys = result.get("keys", [])
143
- assert len(keys) == 1
144
- assert keys[0].get("value", "") == shared_aas.id
145
-
146
- def test_007_get_shells_submodels_by_id_not_posted(client: AasHttpClient, shared_aas: AssetAdministrationShell, shared_sm: Submodel):
147
- result = client.get_shells_submodels_by_id(shared_aas.id, shared_sm.id)
148
-
149
- assert result is None
150
-
151
- def test_008_get_submodels(client: AasHttpClient):
152
- result = client.get_submodels()
153
- assert result
154
- submodels = result.get("result", [])
155
- assert len(submodels) == 0
156
-
157
- def test_009_post_submodels(client: AasHttpClient, shared_sm: Submodel):
158
- sm_data_string = json.dumps(shared_sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
159
- sm_data = json.loads(sm_data_string)
160
-
161
- result = client.post_submodels(sm_data)
162
-
163
- assert result is not None
164
- result_id_short = result.get("idShort", "")
165
- assert result_id_short == shared_sm.id_short
166
-
167
- get_result = client.get_submodels()
168
- assert get_result is not None
169
- submodels = get_result.get("result", [])
170
- assert len(submodels) == 1
171
- assert submodels[0].get("idShort", "") == shared_sm.id_short
172
-
173
- def test_010_get_shells_submodels_by_id(client: AasHttpClient, shared_aas: AssetAdministrationShell, shared_sm: Submodel):
174
- result = client.get_shells_submodels_by_id(shared_aas.id, shared_sm.id)
175
-
176
- assert result is not None
177
- result_id_short = result.get("idShort", "")
178
- assert result_id_short == shared_sm.id_short
179
-
180
- def test_011a_get_submodels_by_id(client: AasHttpClient, shared_sm: Submodel):
181
- result = client.get_submodels_by_id(shared_sm.id)
182
-
183
- assert result is not None
184
- result_id_short = result.get("idShort", "")
185
- assert result_id_short == shared_sm.id_short
186
-
187
- def test_011b_get_submodels_by_id_not_found(client: AasHttpClient):
188
- result = client.get_submodels_by_id("non_existent_id")
189
-
190
- assert result is None
191
-
192
- def test_012_patch_submodel_by_id(client: AasHttpClient, shared_sm: Submodel):
193
- sm = Submodel(shared_sm.id_short)
194
- sm.id_short = shared_sm.id_short
195
-
196
- description_text = "Patched description for unit tests"
197
- sm.description = MultiLanguageTextType({"en": description_text})
198
-
199
- sm_data_string = json.dumps(sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
200
- sm_data = json.loads(sm_data_string)
201
-
202
- result = client.patch_submodel_by_id(shared_sm.id, sm_data)
203
-
204
- assert result
205
-
206
- get_result = client.get_submodels_by_id(shared_sm.id)
207
- assert get_result is not None
208
- assert get_result.get("idShort", "") == shared_sm.id_short
209
- assert get_result.get("id", "") == shared_sm.id
210
- # Only the description may change in patch.
211
- assert get_result.get("description", {})[0].get("text", "") == description_text
212
- assert get_result.get("description", {})[0].get("text", "") != shared_sm.description.get("en", "")
213
- # The display name must remain the same.
214
- assert get_result.get("displayName", {})[0].get("text", "") == shared_sm.display_name.get("en", "")
215
-
216
- def test_013_put_shells_submodels_by_id(client: AasHttpClient, shared_aas: AssetAdministrationShell, shared_sm: Submodel):
217
- sm = Submodel(shared_sm.id_short)
218
- sm.id_short = shared_sm.id_short
219
-
220
- description_text = "Put via shell description for unit tests"
221
- sm.description = MultiLanguageTextType({"en": description_text})
222
-
223
- sm_data_string = json.dumps(sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
224
- sm_data = json.loads(sm_data_string)
225
-
226
- result = client.put_shells_submodels_by_id(shared_aas.id, shared_sm.id, sm_data)
227
-
228
- assert result
229
-
230
- get_result = client.get_shells_submodels_by_id(shared_aas.id, shared_sm.id)
231
- assert get_result is not None
232
- assert get_result.get("idShort", "") == shared_sm.id_short
233
- assert get_result.get("id", "") == shared_sm.id
234
- # description must have changed
235
- assert get_result.get("description", {})[0].get("text", "") == description_text
236
- assert get_result.get("description", {})[0].get("text", "") != shared_sm.description.get("en", "")
237
- assert len(get_result.get("displayName", {})) == 0
238
-
239
- # restore to its original state
240
- sm_data_string = json.dumps(shared_sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
241
- sm_data = json.loads(sm_data_string)
242
- client.put_shells_submodels_by_id(shared_aas.id, shared_sm.id, sm_data) # Restore original submodel
243
-
244
- def test_014_put_submodels_by_id(client: AasHttpClient, shared_sm: Submodel):
245
- sm = Submodel(shared_sm.id_short)
246
- sm.id_short = shared_sm.id_short
247
-
248
- description_text = "Put description for unit tests"
249
- sm.description = MultiLanguageTextType({"en": description_text})
250
-
251
- sm_data_string = json.dumps(sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
252
- sm_data = json.loads(sm_data_string)
253
-
254
- result = client.put_submodels_by_id(shared_sm.id, sm_data)
255
-
256
- assert result
257
-
258
- get_result = client.get_submodels_by_id(shared_sm.id)
259
- assert get_result is not None
260
- assert get_result.get("idShort", "") == shared_sm.id_short
261
- assert get_result.get("id", "") == shared_sm.id
262
- # description must have changed
263
- assert get_result.get("description", {})[0].get("text", "") == description_text
264
- assert get_result.get("description", {})[0].get("text", "") != shared_sm.description.get("en", "")
265
- assert len(get_result.get("displayName", {})) == 0
266
-
267
- # restore to its original state
268
- sm_data_string = json.dumps(shared_sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
269
- sm_data = json.loads(sm_data_string)
270
- client.put_submodels_by_id(shared_sm.id, sm_data) # Restore original submodel
271
-
272
- def test_098_delete_shells_by_id(client: AasHttpClient, shared_aas: AssetAdministrationShell):
273
- result = client.delete_shells_by_id(shared_aas.id)
274
-
275
- assert result
276
-
277
- get_result = client.get_shells()
278
- assert get_result is not None
279
- shells = get_result.get("result", [])
280
- assert len(shells) == 0
281
-
282
- def test_099_delete_submodel_by_id(client: AasHttpClient, shared_sm: Submodel):
283
- result = client.delete_submodels_by_id(shared_sm.id)
284
-
285
- assert result
286
-
287
- get_result = client.get_submodels()
288
- assert get_result is not None
289
- submodels = get_result.get("result", [])
290
- assert len(submodels) == 0
@@ -1,263 +0,0 @@
1
- import pytest
2
- from pathlib import Path
3
- from aas_http_client.client import create_client_by_config, AasHttpClient
4
- from basyx.aas.model import AssetAdministrationShell, Submodel, MultiLanguageTextType
5
- import aas_http_client.utilities.model_builder as model_builder
6
- import json
7
- import basyx.aas.adapter.json
8
-
9
- @pytest.fixture(scope="module")
10
- def client() -> AasHttpClient:
11
- try:
12
- file = Path("./tests/server_configs/test_java_server_config.json").resolve()
13
-
14
- if not file.exists():
15
- raise FileNotFoundError(f"Configuration file {file} does not exist.")
16
-
17
- client = create_client_by_config(file, password="")
18
- except Exception as e:
19
- raise RuntimeError("Unable to connect to server.")
20
-
21
- shells = client.get_shells()
22
- if shells is None:
23
- raise RuntimeError("No shells found on server. Please check the server configuration.")
24
-
25
- for shell in shells.get("result", []):
26
- id = shell.get("id", "")
27
- client.delete_shells_by_id(id)
28
-
29
- submodels = client.get_submodels()
30
- if submodels is None:
31
- raise RuntimeError("No submodels found on server. Please check the server configuration.")
32
-
33
- for submodel in submodels.get("result", []):
34
- id = submodel.get("id", "")
35
- client.delete_submodels_by_id(id)
36
-
37
- return client
38
-
39
- @pytest.fixture(scope="module")
40
- def shared_sm() -> Submodel:
41
- # create a Submodel
42
- return model_builder.create_base_submodel("sm_http_client_unit_tests", "")
43
-
44
- @pytest.fixture(scope="module")
45
- def shared_aas(client: AasHttpClient, shared_sm: Submodel) -> AssetAdministrationShell:
46
- # create an AAS
47
- aas = model_builder.create_base_ass(id_short="aas_http_client_unit_tests", namespace="")
48
-
49
- # add Submodel to AAS
50
- model_builder.add_submodel_to_aas(aas, shared_sm)
51
-
52
- return aas
53
-
54
- def test_001_connect(client: AasHttpClient):
55
- assert client is not None
56
-
57
- def test_002_get_shells(client: AasHttpClient):
58
- result = client.get_shells()
59
- assert result is not None
60
- shells = result.get("result", [])
61
- assert len(shells) == 0
62
-
63
- def test_003_post_shells(client: AasHttpClient, shared_aas: AssetAdministrationShell):
64
- aas_data_string = json.dumps(shared_aas, cls=basyx.aas.adapter.json.AASToJsonEncoder)
65
- aas_data = json.loads(aas_data_string)
66
- result = client.post_shells(aas_data)
67
-
68
- assert result is not None
69
- result_id_short = result.get("idShort", "")
70
- assert result_id_short == shared_aas.id_short
71
-
72
- get_result = client.get_shells()
73
- assert get_result is not None
74
- shells = get_result.get("result", [])
75
- assert len(shells) == 1
76
- assert shells[0].get("idShort", "") == shared_aas.id_short
77
-
78
- def test_004a_get_shell_by_id(client: AasHttpClient, shared_aas: AssetAdministrationShell):
79
- result = client.get_shells_by_id(shared_aas.id)
80
-
81
- assert result is not None
82
- assert result.get("idShort", "") == shared_aas.id_short
83
-
84
- def test_004b_get_shell_by_id_not_found(client: AasHttpClient):
85
- result = client.get_shells_by_id("non_existent_id")
86
-
87
- assert result is None
88
-
89
- def test_005a_put_shells(client: AasHttpClient, shared_aas: AssetAdministrationShell):
90
- aas = AssetAdministrationShell(id_=shared_aas.asset_information.global_asset_id, asset_information=shared_aas.asset_information)
91
- aas.id_short = shared_aas.id_short
92
-
93
- description_text = "Put description for unit tests"
94
- aas.description = MultiLanguageTextType({"en": description_text})
95
- aas.submodel = shared_aas.submodel # Keep existing submodels
96
-
97
- aas_data_string = json.dumps(aas, cls=basyx.aas.adapter.json.AASToJsonEncoder)
98
- aas_data = json.loads(aas_data_string)
99
-
100
- result = client.put_shells(shared_aas.id, aas_data)
101
-
102
- assert result
103
-
104
- get_result = client.get_shells_by_id(shared_aas.id)
105
-
106
- assert get_result is not None
107
- assert get_result.get("idShort", "") == shared_aas.id_short
108
- assert get_result.get("id", "") == shared_aas.id
109
- # description must have changed
110
- assert get_result.get("description", {})[0].get("text", "") == description_text
111
- assert get_result.get("description", {})[0].get("text", "") != shared_aas.description.get("en", "")
112
- # submodels must be retained
113
- assert len(get_result.get("submodels", [])) == len(shared_aas.submodel)
114
- # The display name must be empty
115
- assert len(get_result.get("displayName", {})) == 0
116
-
117
- def test_005b_put_shells_with_id(client: AasHttpClient, shared_aas: AssetAdministrationShell):
118
- # put with other ID
119
- id_short = "put_short_id"
120
- asset_info = model_builder.create_base_asset_information(id_short)
121
- aas = AssetAdministrationShell(id_=asset_info.global_asset_id, asset_information=asset_info)
122
- aas.id_short = id_short
123
-
124
- description_text = {"en": "Updated description for unit tests"}
125
- aas.description = MultiLanguageTextType(description_text)
126
-
127
- aas_data_string = json.dumps(shared_aas, cls=basyx.aas.adapter.json.AASToJsonEncoder)
128
- aas_data = json.loads(aas_data_string)
129
-
130
- aas_data["id"] = "updated_id" # Ensure the id is included in the update
131
-
132
- result = client.put_shells(shared_aas.id, aas_data)
133
-
134
- assert not result
135
-
136
- def test_006_get_shells_reference_by_id(client: AasHttpClient, shared_aas: AssetAdministrationShell):
137
- result = client.get_shells_reference_by_id(shared_aas.id)
138
-
139
- # Basyx java server do not provide this endpoint
140
- assert not result
141
-
142
- def test_007_get_shells_submodels_by_id_not_posted(client: AasHttpClient, shared_aas: AssetAdministrationShell, shared_sm: Submodel):
143
- result = client.get_shells_submodels_by_id(shared_aas.id, shared_sm.id)
144
-
145
- assert result is None
146
-
147
- def test_008_get_submodels(client: AasHttpClient):
148
- result = client.get_submodels()
149
-
150
- assert result
151
- submodels = result.get("result", [])
152
- assert len(submodels) == 0
153
-
154
- def test_009_post_submodels(client: AasHttpClient, shared_sm: Submodel):
155
- sm_data_string = json.dumps(shared_sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
156
- sm_data = json.loads(sm_data_string)
157
-
158
- result = client.post_submodels(sm_data)
159
-
160
- assert result is not None
161
- result_id_short = result.get("idShort", "")
162
- assert result_id_short == shared_sm.id_short
163
-
164
- get_result = client.get_submodels()
165
- assert get_result is not None
166
- submodels = get_result.get("result", [])
167
- assert len(submodels) == 1
168
- assert submodels[0].get("idShort", "") == shared_sm.id_short
169
-
170
- def test_010_get_shells_submodels_by_id(client: AasHttpClient, shared_aas: AssetAdministrationShell, shared_sm: Submodel):
171
- result = client.get_shells_submodels_by_id(shared_aas.id, shared_sm.id)
172
-
173
- # Basyx java server do not provide this endpoint
174
- assert result is None
175
-
176
- def test_011a_get_submodels_by_id(client: AasHttpClient, shared_sm: Submodel):
177
- result = client.get_submodels_by_id(shared_sm.id)
178
-
179
- assert result is not None
180
- result_id_short = result.get("idShort", "")
181
- assert result_id_short == shared_sm.id_short
182
-
183
- def test_011b_get_submodels_by_id_not_found(client: AasHttpClient):
184
- result = client.get_submodels_by_id("non_existent_id")
185
-
186
- assert result is None
187
-
188
- def test_012_patch_submodel_by_id(client: AasHttpClient, shared_sm: Submodel):
189
- sm = Submodel(shared_sm.id_short)
190
- sm.id_short = shared_sm.id_short
191
-
192
- description_text = "Patched description for unit tests"
193
- sm.description = MultiLanguageTextType({"en": description_text})
194
-
195
- sm_data_string = json.dumps(sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
196
- sm_data = json.loads(sm_data_string)
197
-
198
- result = client.patch_submodel_by_id(shared_sm.id, sm_data)
199
-
200
- # Basyx java server do not provide this endpoint
201
- assert not result
202
-
203
- def test_013_put_shells_submodels_by_id(client: AasHttpClient, shared_aas: AssetAdministrationShell, shared_sm: Submodel):
204
- sm = Submodel(shared_sm.id_short)
205
- sm.id_short = shared_sm.id_short
206
-
207
- description_text = "Put via shell description for unit tests"
208
- sm.description = MultiLanguageTextType({"en": description_text})
209
-
210
- sm_data_string = json.dumps(sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
211
- sm_data = json.loads(sm_data_string)
212
-
213
- result = client.put_shells_submodels_by_id(shared_aas.id, shared_sm.id, sm_data)
214
-
215
- assert not result
216
-
217
- def test_014_put_submodels_by_id(client: AasHttpClient, shared_sm: Submodel):
218
- sm = Submodel(shared_sm.id_short)
219
- sm.id_short = shared_sm.id_short
220
-
221
- description_text = "Put description for unit tests"
222
- sm.description = MultiLanguageTextType({"en": description_text})
223
-
224
- sm_data_string = json.dumps(sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
225
- sm_data = json.loads(sm_data_string)
226
-
227
- result = client.put_submodels_by_id(shared_sm.id, sm_data)
228
-
229
- assert result
230
-
231
- get_result = client.get_submodels_by_id(shared_sm.id)
232
- assert get_result is not None
233
- assert get_result.get("idShort", "") == shared_sm.id_short
234
- assert get_result.get("id", "") == shared_sm.id
235
- # description must have changed
236
- assert get_result.get("description", {})[0].get("text", "") == description_text
237
- assert get_result.get("description", {})[0].get("text", "") != shared_sm.description.get("en", "")
238
- assert len(get_result.get("displayName", {})) == 0
239
-
240
- # restore to its original state
241
- sm_data_string = json.dumps(shared_sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
242
- sm_data = json.loads(sm_data_string)
243
- client.put_submodels_by_id(shared_sm.id, sm_data) # Restore original submodel
244
-
245
- def test_098_delete_shells_by_id(client: AasHttpClient, shared_aas: AssetAdministrationShell):
246
- result = client.delete_shells_by_id(shared_aas.id)
247
-
248
- assert result
249
-
250
- get_result = client.get_shells()
251
- assert get_result is not None
252
- shells = get_result.get("result", [])
253
- assert len(shells) == 0
254
-
255
- def test_099_delete_submodel_by_id(client: AasHttpClient, shared_sm: Submodel):
256
- result = client.delete_submodels_by_id(shared_sm.id)
257
-
258
- assert result
259
-
260
- get_result = client.get_submodels()
261
- assert get_result is not None
262
- submodels = get_result.get("result", [])
263
- assert len(submodels) == 0