AAS HTTP Client Documentation
Loading...
Searching...
No Matches
test_client.py
Go to the documentation of this file.
1from multiprocessing.sharedctypes import Value
2import pytest
3from pathlib import Path
4from aas_http_client.classes.client.aas_client import create_by_config, AasHttpClient, create_by_dict, create_by_url
5from basyx.aas import model
6import aas_http_client.utilities.model_builder as model_builder
8import json
9import basyx.aas.adapter.json
10from urllib.parse import urlparse
11import logging
12from aas_http_client.demo.logging_handler import initialize_logging
13from aas_http_client.utilities import encoder
14import random
15import json
16
17logger = logging.getLogger(__name__)
18
19JAVA_SERVER_PORTS = [8075]
20PYTHON_SERVER_PORTS = [5080, 80]
21DOTNET_SERVER_PORTS = [5043]
22
23AIMC_SM_ID = "https://fluid40.de/ids/sm/7644_4034_2556_2369"
24SM_ID = "fluid40/sm_http_client_unit_tests"
25SHELL_ID = "fluid40/aas_http_client_unit_tests"
26
27# "./tests/server_configs/test_go_server_config.json",
28# "./tests/server_configs/test_python_server_config.json"
29CONFIG_FILES = [
30 "./tests/server_configs/test_java_server_config.json",
31 "./tests/server_configs/test_java_server_alias_config.json",
32 "./tests/server_configs/test_dotnet_server_config.json",
33]
34
35# CONFIG_FILES = [
36# "./tests/server_configs/test_dotnet_server_config_local.yml",
37# ]
38
39@pytest.fixture(params=CONFIG_FILES, scope="module")
40def client(request) -> AasHttpClient:
41 try:
42 initialize_logging()
43 file = Path(request.param).resolve()
44
45 if not file.exists():
46 raise FileNotFoundError(f"Configuration file {file} does not exist.")
47
48 client = create_by_config(file)
49
50 if client is None:
51 raise RuntimeError("Failed to create client from configuration file.")
52
53 # Randomly set encoded_ids to True or False for testing both scenarios
54 rand = random.randint(0, 10)
55 if (rand % 2) == 0:
56 client.encoded_ids = True
57
58 except Exception as e:
59 raise RuntimeError("Unable to connect to server.")
60
61
62 if client.shells is None:
63 pytest.skip("Shells API is not available in this client")
64
65 shells = client.shells.get_all_asset_administration_shells()
66 if shells is None:
67 raise RuntimeError("No shells found on server. Please check the server configuration.")
68
69 return client
70
71@pytest.fixture(scope="module")
72def shared_sme_string() -> model.Property:
73 # create a Submodel
74 return model_builder.create_base_submodel_element_property("sme_property_string", model.datatypes.String, "Sample String Value", description="This is a sample string property for unit testing.", display_name="Sample String Property")
75
76@pytest.fixture(scope="module")
77def shared_sme_bool() -> model.Property:
78 # create a Submodel
79 return model_builder.create_base_submodel_element_property("sme_property_bool", model.datatypes.Boolean, True, description="This is a sample boolean property for unit testing.", display_name="Sample Boolean Property")
80
81@pytest.fixture(scope="module")
82def shared_sme_int() -> model.Property:
83 # create a Submodel
84 return model_builder.create_base_submodel_element_property("sme_property_int", model.datatypes.Integer, 262, description="This is a sample integer property for unit testing.", display_name="Sample Integer Property")
85
86@pytest.fixture(scope="module")
87def shared_sme_float() -> model.Property:
88 # create a Submodel
89 return model_builder.create_base_submodel_element_property("sme_property_float", model.datatypes.Float, 262.3, description="This is a sample float property for unit testing.", display_name="Sample Float Property")
90
91@pytest.fixture(scope="module")
92def shared_sme_collection() -> model.SubmodelElementCollection:
93 # create a Submodel
94 values: list[model.SubmodelElement] = []
95 values.append(model_builder.create_base_submodel_element_property("coll_element_1", model.datatypes.Integer, 262, description="This is a sample integer property for unit testing.", display_name="Sample Integer Property"))
96 values.append(model_builder.create_base_submodel_element_property("coll_element_2", model.datatypes.String, "262", description="This is a sample string property for unit testing.", display_name="Sample String Property"))
97 values.append(model_builder.create_base_submodel_element_property("coll_element_3", model.datatypes.Float, 262.3, description="This is a sample float property for unit testing.", display_name="Sample Float Property"))
98
99 return model_builder.create_base_submodel_element_collection("sme_property_collection", values, description="This is a sample collection property for unit testing.", display_name="Sample Collection Property")
100
101@pytest.fixture(scope="module")
102def shared_sm() -> model.Submodel:
103 # create a Submodel
104 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.")
105
106@pytest.fixture(scope="module")
107def shared_aas(shared_sm: model.Submodel) -> model.AssetAdministrationShell:
108 # create an AAS
109 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.")
110
111 # add Submodel to AAS
112 sdk_tools.add_submodel_to_aas(aas, shared_sm)
113
114 return aas
115
116def test_000a_create_client_by_url(client: AasHttpClient):
117 base_url: str = client.base_url
118 new_client = create_by_url(base_url=base_url)
119 assert new_client is not None
120
121def test_000b_create_client_by_dict(client: AasHttpClient):
122 base_url: str = client.base_url
123
124 config_dict: dict = {
125 "BaseUrl": base_url
126 }
127
128 new_client = create_by_dict(configuration=config_dict)
129 assert new_client is not None
130
131def test_001a_connect(client: AasHttpClient):
132 assert client is not None
133
135 if client.shells is None:
136 pytest.skip("Shells API is not available in this client")
137
138 result = client.shells.get_all_asset_administration_shells()
139 assert result is not None
140 shells = result.get("result", [])
141
142 for shell in shells:
143 shell_id = shell.get("id", "")
144
145 if client.encoded_ids:
146 shell_id = encoder.encode_base_64(shell_id)
147
148 if shell_id:
149 delete_result = client.shells.delete_asset_administration_shell_by_id(shell_id)
150 assert delete_result
151
152 shells_result = client.shells.get_all_asset_administration_shells()
153
154 if shells_result is None:
155 raise RuntimeError("Failed to retrieve shells after deletion.")
156
157 shells = shells_result.get("result", [])
158 assert len(shells) == 0
159
160def test_001c_delete_all_submodels(client: AasHttpClient):
161 if client.submodels is None:
162 pytest.skip("Submodels API is not available in this client")
163
164 result = client.submodels.get_all_submodels()
165 assert result is not None
166 submodels = result.get("result", [])
167
168 for submodel in submodels:
169 submodel_id = submodel.get("id", "")
170
171 if client.encoded_ids:
172 submodel_id = encoder.encode_base_64(submodel_id)
173
174 if submodel_id:
175 delete_result = client.submodels.delete_submodel_by_id(submodel_id)
176 assert delete_result
177
178 submodels_result = client.submodels.get_all_submodels()
179
180 if submodels_result is None:
181 raise RuntimeError("Failed to retrieve submodels after deletion.")
182
183 submodels = submodels_result.get("result", [])
184 assert len(submodels) == 0
185
187 if client.shells is None:
188 pytest.skip("Shells API is not available in this client")
189
190 result = client.shells.get_all_asset_administration_shells()
191 assert result is not None
192 shells = result.get("result", [])
193 assert len(shells) == 0
194
195def test_003_post_asset_administration_shell(client: AasHttpClient, shared_aas: model.AssetAdministrationShell):
196 if client.shells is None:
197 pytest.skip("Shells API is not available in this client")
198
199 aas_data_string = json.dumps(shared_aas, cls=basyx.aas.adapter.json.AASToJsonEncoder)
200 aas_data = json.loads(aas_data_string)
201 result = client.shells.post_asset_administration_shell(aas_data)
202
203 assert result is not None
204 assert result.get("idShort", "") == shared_aas.id_short
205 assert result.get("id", "") == SHELL_ID
206
207 get_result = client.shells.get_all_asset_administration_shells()
208 assert get_result is not None
209 shells = get_result.get("result", [])
210 assert len(shells) == 1
211 assert shells[0].get("idShort", "") == shared_aas.id_short
212 assert shells[0].get("id", "") == SHELL_ID
213 submodels = shells[0].get("submodels", [])
214 assert len(submodels) == 1
215 submodel: dict = submodels[0]
216 assert len(submodel.get("keys", [])) == 1
217 assert submodel.get("keys", [])[0].get("value", "") == SM_ID
218
219def test_004a_get_asset_administration_shell_by_id(client: AasHttpClient, shared_aas: model.AssetAdministrationShell):
220 if client.shells is None:
221 pytest.skip("Shells API is not available in this client")
222
223 shell_id = SHELL_ID
224
225 if client.encoded_ids:
226 shell_id = encoder.encode_base_64(SHELL_ID)
227
228 result = client.shells.get_asset_administration_shell_by_id(shell_id)
229
230 assert result is not None
231 assert result.get("idShort", "") == shared_aas.id_short
232 assert result.get("id", "") == SHELL_ID
233
235 if client.shells is None:
236 pytest.skip("Shells API is not available in this client")
237
238 result = client.shells.get_asset_administration_shell_by_id("non_existent_id")
239
240 assert result is None
241
242def test_005a_put_asset_administration_shell_by_id(client: AasHttpClient, shared_aas: model.AssetAdministrationShell):
243 if client.shells is None:
244 pytest.skip("Shells API is not available in this client")
245
246 assert shared_aas.asset_information is not None
247 assert shared_aas.asset_information.global_asset_id is not None
248
249 aas = model.AssetAdministrationShell(id_=shared_aas.asset_information.global_asset_id, asset_information=shared_aas.asset_information)
250 aas.id_short = shared_aas.id_short
251
252 description_text = "Put description for unit tests"
253 aas.description = model.MultiLanguageTextType({"en": description_text})
254 aas.submodel = shared_aas.submodel # Keep existing submodels
255
256 aas_data_string = json.dumps(aas, cls=basyx.aas.adapter.json.AASToJsonEncoder)
257 aas_data = json.loads(aas_data_string)
258
259 shell_id = SHELL_ID
260
261 if client.encoded_ids:
262 shell_id = encoder.encode_base_64(SHELL_ID)
263
264 result = client.shells.put_asset_administration_shell_by_id(shell_id, aas_data)
265 assert result
266
267 get_result = client.shells.get_asset_administration_shell_by_id(shell_id)
268 assert get_result
269 assert get_result.get("idShort", "") == shared_aas.id_short
270 assert get_result.get("id", "") == SHELL_ID
271 # description must have changed
272 assert get_result.get("description", {})[0].get("text", "") == description_text
273 assert shared_aas.description is not None
274 assert get_result.get("description", {})[0].get("text", "") != shared_aas.description.get("en", "")
275 # submodels must be retained
276 assert len(get_result.get("submodels", [])) == len(shared_aas.submodel)
277
278 # The display name must be empty
279 # NOTE: currently not working in dotnet
280 # assert len(get_result.get("displayName", {})) == 0
281
282 # restore to its original state
283 sm_data_string = json.dumps(shared_aas, cls=basyx.aas.adapter.json.AASToJsonEncoder)
284 sm_data = json.loads(sm_data_string)
285 client.shells.put_asset_administration_shell_by_id(shell_id, sm_data) # Restore original submodel
286
287def test_005b_put_asset_administration_shell_by_id(client: AasHttpClient, shared_aas: model.AssetAdministrationShell):
288 if client.shells is None:
289 pytest.skip("Shells API is not available in this client")
290
291 # put with other ID
292 id_short = "put_short_id"
293 identifier = f"fluid40/{id_short}"
294 asset_info = model_builder.create_base_asset_information(identifier)
295 assert asset_info.global_asset_id == identifier
296
297 aas = model.AssetAdministrationShell(id_=asset_info.global_asset_id, asset_information=asset_info)
298 aas.id_short = id_short
299
300 description_text = {"en": "Updated description for unit tests"}
301 aas.description = model.MultiLanguageTextType(description_text)
302
303 aas_data_string = json.dumps(aas, cls=basyx.aas.adapter.json.AASToJsonEncoder)
304 aas_data = json.loads(aas_data_string)
305
306 shell_id = SHELL_ID
307
308 if client.encoded_ids:
309 shell_id = encoder.encode_base_64(SHELL_ID)
310
311 parsed = urlparse(client.base_url)
312 if parsed.port in PYTHON_SERVER_PORTS:
313 # NOTE: Python server crashes by this test
314 result = False
315 else:
316 result = client.shells.put_asset_administration_shell_by_id(shell_id, aas_data)
317
318 assert not result
319
320 get_result = client.shells.get_asset_administration_shell_by_id(shell_id)
321 assert get_result is not None
322 assert get_result.get("description", {})[0].get("text", "") != description_text
323 assert shared_aas.description is not None
324 assert get_result.get("description", {})[0].get("text", "") == shared_aas.description.get("en", "")
325
327 if client.shells is None:
328 pytest.skip("Shells API is not available in this client")
329
330 shell_id = SHELL_ID
331
332 if client.encoded_ids:
333 shell_id = encoder.encode_base_64(SHELL_ID)
334
335 result = client.shells.get_asset_administration_shell_by_id_reference_aas_repository(shell_id)
336
337 parsed = urlparse(client.base_url)
338 if parsed.port in JAVA_SERVER_PORTS:
339 # NOTE: Basyx java server do not provide this endpoint
340 assert result is None
341 else:
342 assert result is not None
343 keys = result.get("keys", [])
344 assert len(keys) == 1
345 assert keys[0].get("value", "") == SHELL_ID
346
348 if client.shells is None:
349 pytest.skip("Shells API is not available in this client")
350
351 shell_id = SHELL_ID
352 sm_id = SM_ID
353
354 if client.encoded_ids:
355 shell_id = encoder.encode_base_64(SHELL_ID)
356 sm_id = encoder.encode_base_64(SM_ID)
357
358 result = client.shells.get_submodel_by_id_aas_repository(shell_id, sm_id)
359
360 assert result is None
361
362def test_008_get_all_submodels(client: AasHttpClient):
363 if client.submodels is None:
364 pytest.skip("Submodel API is not available in this client")
365
366 result = client.submodels.get_all_submodels()
367 assert result is not None
368 submodels = result.get("result", [])
369 assert len(submodels) == 0
370
371def test_009a_post_submodel(client: AasHttpClient, shared_sm: model.Submodel):
372 if client.submodels is None:
373 pytest.skip("Submodel API is not available in this client")
374
375 sm_data_string = json.dumps(shared_sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
376 sm_data = json.loads(sm_data_string)
377
378 result = client.submodels.post_submodel(sm_data)
379
380 assert result is not None
381 result_id_short = result.get("idShort", "")
382 assert result_id_short == shared_sm.id_short
383
384 get_result = client.submodels.get_all_submodels()
385 assert get_result is not None
386 submodels = get_result.get("result", [])
387 assert len(submodels) == 1
388 assert submodels[0].get("idShort", "") == shared_sm.id_short
389
390def test_009b_post_submodel(client: AasHttpClient):
391 if client.submodels is None:
392 pytest.skip("Submodel API is not available in this client")
393
394 sm_template_file = Path(f"./tests/test_data/aimc.json").resolve()
395
396 with Path.open(sm_template_file, "r", encoding="utf-8") as f:
397 sm_data = json.load(f)
398
399 result = client.submodels.post_submodel(sm_data)
400
401 assert result is not None
402 result_id = result.get("id", "")
403 assert result_id == AIMC_SM_ID
404
405 get_result = client.submodels.get_all_submodels()
406 assert get_result is not None
407 submodels = get_result.get("result", [])
408 assert len(submodels) == 2
409
410def test_010_get_submodel_by_id_aas_repository(client: AasHttpClient, shared_sm: model.Submodel):
411 if client.shells is None:
412 pytest.skip("Shells API is not available in this client")
413
414 shell_id = SHELL_ID
415 sm_id = SM_ID
416
417 if client.encoded_ids:
418 shell_id = encoder.encode_base_64(SHELL_ID)
419 sm_id = encoder.encode_base_64(SM_ID)
420
421 result = client.shells.get_submodel_by_id_aas_repository(shell_id, sm_id)
422
423 parsed = urlparse(client.base_url)
424 if parsed.port in JAVA_SERVER_PORTS:
425 # NOTE: Basyx java server do not provide this endpoint
426 assert result is None
427 else:
428 assert result is not None
429 result_id_short = result.get("idShort", "")
430 assert result_id_short == shared_sm.id_short
431
432def test_011a_get_submodel_by_id(client: AasHttpClient, shared_sm: model.Submodel):
433 if client.submodels is None:
434 pytest.skip("Submodel API is not available in this client")
435
436 sm_id = SM_ID
437
438 if client.encoded_ids:
439 sm_id = encoder.encode_base_64(SM_ID)
440
441 result = client.submodels.get_submodel_by_id(sm_id)
442
443 assert result is not None
444 result_id_short = result.get("idShort", "")
445 assert result_id_short == shared_sm.id_short
446
447def test_011b_get_submodel_by_id(client: AasHttpClient):
448 if client.submodels is None:
449 pytest.skip("Submodel API is not available in this client")
450
451 result = client.submodels.get_submodel_by_id("non_existent_id")
452
453 assert result is None
454
455def test_011c_get_submodel_by_id(client: AasHttpClient):
456 if client.submodels is None:
457 pytest.skip("Submodel API is not available in this client")
458
459 sm_id = AIMC_SM_ID
460
461 if client.encoded_ids:
462 sm_id = encoder.encode_base_64(AIMC_SM_ID)
463
464 result = client.submodels.get_submodel_by_id(sm_id)
465
466 assert result is not None
467 result_id = result.get("id", "")
468 assert result_id == AIMC_SM_ID
469
470def test_011d_get_submodel_by_id(client: AasHttpClient):
471 if client.submodels is None:
472 pytest.skip("Submodel API is not available in this client")
473
474 sm_id = AIMC_SM_ID
475
476 if client.encoded_ids:
477 sm_id = encoder.encode_base_64(AIMC_SM_ID)
478
479 result = client.submodels.get_submodel_by_id(sm_id, level="core")
480
481 assert result is not None
482 result_id = result.get("id", "")
483 assert result_id == AIMC_SM_ID
484 #assert "submodelElements" not in result
485
486def test_012_patch_submodel_by_id(client: AasHttpClient, shared_sm: model.Submodel):
487 if client.submodels is None:
488 pytest.skip("Submodel API is not available in this client")
489
490 sm = model.Submodel(shared_sm.id)
491 sm.id_short = shared_sm.id_short
492
493 description_text = "Patched description for unit tests"
494 sm.description = model.MultiLanguageTextType({"en": description_text})
495
496 sm_data_string = json.dumps(sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
497 sm_data = json.loads(sm_data_string)
498
499 sm_id = SM_ID
500
501 if client.encoded_ids:
502 sm_id = encoder.encode_base_64(SM_ID)
503
504 result = client.submodels.patch_submodel_by_id(sm_id, sm_data)
505
506 parsed = urlparse(client.base_url)
507 if parsed.port in JAVA_SERVER_PORTS or parsed.port in PYTHON_SERVER_PORTS:
508 # NOTE: Basyx java and python server do not provide this endpoint
509 assert not result
510 else:
511 assert result is True
512
513 get_result = client.submodels.get_submodel_by_id(sm_id)
514 assert get_result is not None
515 assert get_result.get("idShort", "") == shared_sm.id_short
516 assert get_result.get("id", "") == SM_ID
517 # Only the description may change in patch.
518 assert get_result.get("description", {})[0].get("text", "") == description_text
519 assert shared_sm.description is not None
520 assert shared_sm.display_name is not None
521 assert get_result.get("description", {})[0].get("text", "") != shared_sm.description.get("en", "")
522 # The display name must remain the same.
523 assert get_result.get("displayName", {})[0].get("text", "") == shared_sm.display_name.get("en", "")
524
525def test_013_put_submodel_by_id_aas_repository(client: AasHttpClient, shared_sm: model.Submodel):
526 if client.shells is None:
527 pytest.skip("Shells API is not available in this client")
528
529 sm = model.Submodel(SM_ID)
530 sm.id_short = shared_sm.id_short
531
532 description_text = "Put via shell description for unit tests"
533 sm.description = model.MultiLanguageTextType({"en": description_text})
534
535 sm_data_string = json.dumps(sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
536 sm_data = json.loads(sm_data_string)
537
538 shell_id = SHELL_ID
539 sm_id = SM_ID
540
541 if client.encoded_ids:
542 shell_id = encoder.encode_base_64(SHELL_ID)
543 sm_id = encoder.encode_base_64(SM_ID)
544
545 result = client.shells.put_submodel_by_id_aas_repository(shell_id, sm_id, sm_data)
546
547 parsed = urlparse(client.base_url)
548 if parsed.port in JAVA_SERVER_PORTS:
549 # NOTE: Basyx java server do not provide this endpoint
550 assert not result
551 else:
552 assert result
553
554 get_result = client.shells.get_submodel_by_id_aas_repository(shell_id, sm_id)
555 assert get_result is not None
556 assert get_result.get("idShort", "") == shared_sm.id_short
557 assert get_result.get("id", "") == SM_ID
558 # description must have changed
559 assert get_result.get("description", {})[0].get("text", "") == description_text
560 assert shared_sm.description is not None
561 assert get_result.get("description", {})[0].get("text", "") != shared_sm.description.get("en", "")
562 assert len(get_result.get("displayName", {})) == 0
563
564 # restore to its original state
565 sm_data_string = json.dumps(shared_sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
566 sm_data = json.loads(sm_data_string)
567 client.shells.put_submodel_by_id_aas_repository(shell_id, sm_id, sm_data) # Restore original submodel
568
569def test_014_put_submodels_by_id(client: AasHttpClient, shared_sm: model.Submodel):
570 if client.submodels is None:
571 pytest.skip("Submodels API is not available in this client")
572
573 sm = model.Submodel(SM_ID)
574 sm.id_short = shared_sm.id_short
575
576 description_text = "Put description for unit tests"
577 sm.description = model.MultiLanguageTextType({"en": description_text})
578
579 sm_data_string = json.dumps(sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
580 sm_data = json.loads(sm_data_string)
581
582 sm_id = SM_ID
583
584 if client.encoded_ids:
585 sm_id = encoder.encode_base_64(SM_ID)
586
587 result = client.submodels.put_submodels_by_id(sm_id, sm_data)
588
589 assert result is True
590
591 get_result = client.submodels.get_submodel_by_id(sm_id)
592 assert get_result is not None
593 assert get_result.get("idShort", "") == shared_sm.id_short
594 assert get_result.get("id", "") == SM_ID
595 # description must have changed
596 assert get_result.get("description", {})[0].get("text", "") == description_text
597 assert shared_sm.description is not None
598 assert get_result.get("description", {})[0].get("text", "") != shared_sm.description.get("en", "")
599 assert len(get_result.get("displayName", {})) == 0
600
601 # restore to its original state
602 sm_data_string = json.dumps(shared_sm, cls=basyx.aas.adapter.json.AASToJsonEncoder)
603 sm_data = json.loads(sm_data_string)
604 client.submodels.put_submodels_by_id(SM_ID, sm_data) # Restore original submodel
605
606def test_015_get_all_submodel_elements_submodel_repository(client: AasHttpClient, shared_sm: model.Submodel):
607 if client.submodels is None:
608 pytest.skip("Submodels API is not available in this client")
609
610 sm_id = SM_ID
611
612 if client.encoded_ids:
613 sm_id = encoder.encode_base_64(SM_ID)
614
615 submodel_elements = client.submodels.get_all_submodel_elements_submodel_repository(sm_id)
616
617 assert submodel_elements is not None
618 assert len(submodel_elements.get("result", [])) == 0
619
620def test_016a_post_submodel_element_submodel_repo(client: AasHttpClient, shared_sme_string: model.Property):
621 if client.submodels is None:
622 pytest.skip("Submodels API is not available in this client")
623
624 sme_data_string = json.dumps(shared_sme_string, cls=basyx.aas.adapter.json.AASToJsonEncoder)
625 sme_data = json.loads(sme_data_string)
626
627 sm_id = SM_ID
628
629 if client.encoded_ids:
630 sm_id = encoder.encode_base_64(SM_ID)
631
632 result = client.submodels.post_submodel_element_submodel_repo(sm_id, sme_data)
633
634 assert result is not None
635 assert result.get("idShort", "") == shared_sme_string.id_short
636 assert shared_sme_string.description is not None
637 assert shared_sme_string.display_name is not None
638 assert result.get("description", {})[0].get("text", "") == shared_sme_string.description.get("en", "")
639 assert result.get("displayName", {})[0].get("text", "") == shared_sme_string.display_name.get("en", "")
640 assert result.get("value", "") == shared_sme_string.value
641
642 get_result = client.submodels.get_all_submodel_elements_submodel_repository(sm_id)
643 assert get_result is not None
644
645 assert len(get_result.get("result", [])) == 1
646
647def test_016b_post_submodel_element_submodel_repo(client: AasHttpClient, shared_sme_bool: model.Property):
648 if client.submodels is None:
649 pytest.skip("Submodels API is not available in this client")
650
651 sme_data_string = json.dumps(shared_sme_bool, cls=basyx.aas.adapter.json.AASToJsonEncoder)
652 sme_data = json.loads(sme_data_string)
653
654 sm_id = SM_ID
655
656 if client.encoded_ids:
657 sm_id = encoder.encode_base_64(SM_ID)
658
659 result = client.submodels.post_submodel_element_submodel_repo(sm_id, sme_data)
660
661 assert result is not None
662 assert result.get("idShort", "") == shared_sme_bool.id_short
663 assert shared_sme_bool.description is not None
664 assert shared_sme_bool.display_name is not None
665 assert result.get("description", {})[0].get("text", "") == shared_sme_bool.description.get("en", "")
666 assert result.get("displayName", {})[0].get("text", "") == shared_sme_bool.display_name.get("en", "")
667 assert json.loads(result.get("value", "").lower()) == shared_sme_bool.value
668
669 get_result = client.submodels.get_all_submodel_elements_submodel_repository(sm_id)
670 assert get_result is not None
671
672 assert len(get_result.get("result", [])) == 2
673
674def test_016c_post_submodel_element_submodel_repo(client: AasHttpClient, shared_sme_int: model.Property):
675 if client.submodels is None:
676 pytest.skip("Submodels API is not available in this client")
677
678 sme_data_string = json.dumps(shared_sme_int, cls=basyx.aas.adapter.json.AASToJsonEncoder)
679 sme_data = json.loads(sme_data_string)
680
681 sm_id = SM_ID
682
683 if client.encoded_ids:
684 sm_id = encoder.encode_base_64(SM_ID)
685
686 result = client.submodels.post_submodel_element_submodel_repo(sm_id, sme_data)
687
688 assert result is not None
689 assert result.get("idShort", "") == shared_sme_int.id_short
690 assert shared_sme_int.description is not None
691 assert shared_sme_int.display_name is not None
692 assert result.get("description", {})[0].get("text", "") == shared_sme_int.description.get("en", "")
693 assert result.get("displayName", {})[0].get("text", "") == shared_sme_int.display_name.get("en", "")
694 assert int(result.get("value", "")) == shared_sme_int.value
695
696 get_result = client.submodels.get_all_submodel_elements_submodel_repository(sm_id)
697 assert get_result is not None
698
699 assert len(get_result.get("result", [])) == 3
700
701def test_016d_post_submodel_element_submodel_repo(client: AasHttpClient, shared_sme_float: model.Property):
702 if client.submodels is None:
703 pytest.skip("Submodels API is not available in this client")
704
705 sme_data_string = json.dumps(shared_sme_float, cls=basyx.aas.adapter.json.AASToJsonEncoder)
706 sme_data = json.loads(sme_data_string)
707
708 sm_id = SM_ID
709
710 if client.encoded_ids:
711 sm_id = encoder.encode_base_64(SM_ID)
712
713 result = client.submodels.post_submodel_element_submodel_repo(sm_id, sme_data)
714
715 assert result is not None
716 assert result.get("idShort", "") == shared_sme_float.id_short
717 assert shared_sme_float.description is not None
718 assert shared_sme_float.display_name is not None
719 assert result.get("description", {})[0].get("text", "") == shared_sme_float.description.get("en", "")
720 assert result.get("displayName", {})[0].get("text", "") == shared_sme_float.display_name.get("en", "")
721 assert float(result.get("value", "")) == shared_sme_float.value
722
723 get_result = client.submodels.get_all_submodel_elements_submodel_repository(sm_id)
724 assert get_result is not None
725
726 assert len(get_result.get("result", [])) == 4
727
728def test_017a_get_submodel_element_by_path_submodel_repo(client: AasHttpClient, shared_sme_string: model.Property):
729 if client.submodels is None:
730 pytest.skip("Submodels API is not available in this client")
731
732 sm_id = SM_ID
733
734 if client.encoded_ids:
735 sm_id = encoder.encode_base_64(SM_ID)
736
737 result = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_string.id_short)
738
739 assert result is not None
740 assert result.get("idShort", "") == shared_sme_string.id_short
741 assert shared_sme_string.description is not None
742 assert shared_sme_string.display_name is not None
743 assert result.get("description", {})[0].get("text", "") == shared_sme_string.description.get("en", "")
744 assert result.get("displayName", {})[0].get("text", "") == shared_sme_string.display_name.get("en", "")
745 assert result.get("value", "") == shared_sme_string.value
746
747def test_017b_get_submodel_element_by_path_submodel_repo(client: AasHttpClient, shared_sme_bool: model.Property):
748 if client.submodels is None:
749 pytest.skip("Submodels API is not available in this client")
750
751 sm_id = SM_ID
752
753 if client.encoded_ids:
754 sm_id = encoder.encode_base_64(SM_ID)
755
756 result = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_bool.id_short)
757
758 assert result is not None
759 assert result.get("idShort", "") == shared_sme_bool.id_short
760 assert shared_sme_bool.description is not None
761 assert shared_sme_bool.display_name is not None
762 assert result.get("description", {})[0].get("text", "") == shared_sme_bool.description.get("en", "")
763 assert result.get("displayName", {})[0].get("text", "") == shared_sme_bool.display_name.get("en", "")
764 assert json.loads(result.get("value", "").lower()) == shared_sme_bool.value
765
766def test_017c_get_submodel_element_by_path_submodel_repo(client: AasHttpClient, shared_sme_int: model.Property):
767 if client.submodels is None:
768 pytest.skip("Submodels API is not available in this client")
769
770 sm_id = SM_ID
771
772 if client.encoded_ids:
773 sm_id = encoder.encode_base_64(SM_ID)
774
775 result = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_int.id_short)
776
777 assert result is not None
778 assert result.get("idShort", "") == shared_sme_int.id_short
779 assert shared_sme_int.description is not None
780 assert shared_sme_int.display_name is not None
781 assert result.get("description", {})[0].get("text", "") == shared_sme_int.description.get("en", "")
782 assert result.get("displayName", {})[0].get("text", "") == shared_sme_int.display_name.get("en", "")
783 assert int(result.get("value", "")) == shared_sme_int.value
784
785def test_017d_get_submodel_element_by_path_submodel_repo(client: AasHttpClient, shared_sme_float: model.Property):
786 if client.submodels is None:
787 pytest.skip("Submodels API is not available in this client")
788
789 sm_id = SM_ID
790
791 if client.encoded_ids:
792 sm_id = encoder.encode_base_64(SM_ID)
793
794 result = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_float.id_short)
795
796 assert result is not None
797 assert result.get("idShort", "") == shared_sme_float.id_short
798 assert shared_sme_float.description is not None
799 assert shared_sme_float.display_name is not None
800 assert result.get("description", {})[0].get("text", "") == shared_sme_float.description.get("en", "")
801 assert result.get("displayName", {})[0].get("text", "") == shared_sme_float.display_name.get("en", "")
802 assert float(result.get("value", "")) == shared_sme_float.value
803
804def test_018a_patch_submodel_element_by_path_value_only_submodel_repo(client: AasHttpClient, shared_sme_string: model.Property):
805 if client.submodels is None:
806 pytest.skip("Submodels API is not available in this client")
807
808 new_value = "Patched String Value"
809
810 sm_id = SM_ID
811
812 if client.encoded_ids:
813 sm_id = encoder.encode_base_64(SM_ID)
814
815 submodel_element = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_string.id_short)
816 assert submodel_element is not None
817
818 old_value = submodel_element.get("value", "")
819
820 result = client.submodels.patch_submodel_element_by_path_value_only_submodel_repo(sm_id, shared_sme_string.id_short, new_value)
821
822 parsed = urlparse(client.base_url)
823 if parsed.port in PYTHON_SERVER_PORTS:
824 # NOTE: python server do not provide this endpoint
825 assert result is False
826 else:
827 assert result is True
828
829 get_result = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_string.id_short)
830
831 assert get_result is not None
832 assert get_result.get("idShort", "") == shared_sme_string.id_short
833 assert get_result.get("value", "") == new_value
834 assert shared_sme_string.description is not None
835 assert shared_sme_string.display_name is not None
836 assert get_result.get("description", {})[0].get("text", "") == shared_sme_string.description.get("en", "")
837 assert get_result.get("displayName", {})[0].get("text", "") == shared_sme_string.display_name.get("en", "")
838 assert get_result.get("value", "") != old_value
839
840def test_018b_patch_submodel_element_by_path_value_only_submodel_repo(client: AasHttpClient, shared_sme_bool: model.Property):
841 if client.submodels is None:
842 pytest.skip("Submodels API is not available in this client")
843
844 new_value = "false"
845
846 sm_id = SM_ID
847
848 if client.encoded_ids:
849 sm_id = encoder.encode_base_64(SM_ID)
850
851 submodel_element = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_bool.id_short)
852 assert submodel_element is not None
853
854 old_value = submodel_element.get("value", "")
855
856 result = client.submodels.patch_submodel_element_by_path_value_only_submodel_repo(sm_id, shared_sme_bool.id_short, new_value)
857
858 parsed = urlparse(client.base_url)
859 if parsed.port in PYTHON_SERVER_PORTS:
860 # NOTE: python server do not provide this endpoint
861 assert result is False
862 else:
863 assert result is True
864
865 get_result = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_bool.id_short)
866
867 assert get_result is not None
868 assert get_result.get("idShort", "") == shared_sme_bool.id_short
869 assert json.loads(get_result.get("value", "").lower()) == json.loads(new_value)
870 assert shared_sme_bool.description is not None
871 assert shared_sme_bool.display_name is not None
872 assert get_result.get("description", {})[0].get("text", "") == shared_sme_bool.description.get("en", "")
873 assert get_result.get("displayName", {})[0].get("text", "") == shared_sme_bool.display_name.get("en", "")
874 assert get_result.get("value", "").lower() != old_value.lower()
875
876def test_018c_patch_submodel_element_by_path_value_only_submodel_repo(client: AasHttpClient, shared_sme_int: model.Property):
877 if client.submodels is None:
878 pytest.skip("Submodels API is not available in this client")
879
880 new_value = "263"
881
882 sm_id = SM_ID
883
884 if client.encoded_ids:
885 sm_id = encoder.encode_base_64(SM_ID)
886
887 submodel_element = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_int.id_short)
888 assert submodel_element is not None
889
890 old_value = submodel_element.get("value", "")
891
892 result = client.submodels.patch_submodel_element_by_path_value_only_submodel_repo(sm_id, shared_sme_int.id_short, new_value)
893
894 parsed = urlparse(client.base_url)
895 if parsed.port in PYTHON_SERVER_PORTS:
896 # NOTE: python server do not provide this endpoint
897 assert result is False
898 else:
899 assert result is True
900
901 get_result = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_int.id_short)
902
903 assert get_result is not None
904 assert get_result.get("idShort", "") == shared_sme_int.id_short
905 assert int(get_result.get("value", "")) == int(new_value)
906 assert shared_sme_int.description is not None
907 assert shared_sme_int.display_name is not None
908 assert get_result.get("description", {})[0].get("text", "") == shared_sme_int.description.get("en", "")
909 assert get_result.get("displayName", {})[0].get("text", "") == shared_sme_int.display_name.get("en", "")
910 assert int(get_result.get("value", "")) != int(old_value)
911
912def test_018d_patch_submodel_element_by_path_value_only_submodel_repo(client: AasHttpClient, shared_sme_float: model.Property):
913 if client.submodels is None:
914 pytest.skip("Submodels API is not available in this client")
915
916 new_value = "262.1"
917
918 sm_id = SM_ID
919
920 if client.encoded_ids:
921 sm_id = encoder.encode_base_64(SM_ID)
922
923 submodel_element = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_float.id_short)
924 assert submodel_element is not None
925
926 old_value = submodel_element.get("value", "")
927
928 result = client.submodels.patch_submodel_element_by_path_value_only_submodel_repo(sm_id, shared_sme_float.id_short, new_value)
929
930 parsed = urlparse(client.base_url)
931 if parsed.port in PYTHON_SERVER_PORTS:
932 # NOTE: python server do not provide this endpoint
933 assert result is False
934 else:
935 assert result is True
936
937 get_result = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_float.id_short)
938
939 assert get_result is not None
940 assert get_result.get("idShort", "") == shared_sme_float.id_short
941 assert float(get_result.get("value", "")) == float(new_value)
942 assert shared_sme_float.description is not None
943 assert shared_sme_float.display_name is not None
944 assert get_result.get("description", {})[0].get("text", "") == shared_sme_float.description.get("en", "")
945 assert get_result.get("displayName", {})[0].get("text", "") == shared_sme_float.display_name.get("en", "")
946 assert float(get_result.get("value", "")) != float(old_value)
947
949 if client.submodels is None:
950 pytest.skip("Submodels API is not available in this client")
951
952 submodel_element_list = model.SubmodelElementList(id_short="sme_list_1", type_value_list_element=model.Property, value_type_list_element=model.datatypes.String)
953 submodel_element_list_dict = sdk_tools.convert_to_dict(submodel_element_list)
954 assert submodel_element_list_dict is not None
955
956 sm_id = SM_ID
957
958 if client.encoded_ids:
959 sm_id = encoder.encode_base_64(SM_ID)
960
961 post_list_element_result = client.submodels.post_submodel_element_submodel_repo(sm_id, submodel_element_list_dict)
962
963 assert post_list_element_result is not None
964
965 property = model_builder.create_base_submodel_element_property(None, model.datatypes.String, "Value in List")
966 property_dict = sdk_tools.convert_to_dict(property)
967 assert property_dict is not None
968 assert "idShort" not in property_dict
969
970 result = client.submodels.post_submodel_element_by_path_submodel_repo(sm_id, submodel_element_list.id_short, property_dict)
971
972 assert result is not None
973 assert "idShort" not in result # idShort was deleted
974
975 submodel = client.submodels.get_submodel_by_id(sm_id)
976
977 assert submodel is not None
978 elements = submodel.get("submodelElements", [])
979 assert len(elements) == 5 # 4 previous properties + 1 list
980 assert elements[4].get("idShort", "") == submodel_element_list.id_short
981 list_elements = elements[4].get("value", [])
982 assert len(list_elements) == 1
983 assert list_elements[0].get("idShort", "") == ""
984 assert list_elements[0].get("value", "") == property.value
985
986
988 if client.submodels is None:
989 pytest.skip("Submodels API is not available in this client")
990
991 submodel_element_collection = model.SubmodelElementCollection(id_short="sme_collection_1")
992 submodel_element_collection_dict = sdk_tools.convert_to_dict(submodel_element_collection)
993 assert submodel_element_collection_dict is not None
994
995 sm_id = SM_ID
996
997 if client.encoded_ids:
998 sm_id = encoder.encode_base_64(SM_ID)
999
1000 first_result = client.submodels.post_submodel_element_submodel_repo(sm_id, submodel_element_collection_dict)
1001
1002 assert first_result is not None
1003
1004 property = model_builder.create_base_submodel_element_property("sme_property_in_collection", model.datatypes.String, "Value in List")
1005 property_dict = sdk_tools.convert_to_dict(property)
1006 assert property_dict is not None
1007
1008 result = client.submodels.post_submodel_element_by_path_submodel_repo(sm_id, submodel_element_collection.id_short, property_dict)
1009
1010 assert result is not None
1011 assert result["idShort"] == property.id_short
1012
1013 submodel = client.submodels.get_submodel_by_id(sm_id)
1014
1015 assert submodel is not None
1016 elements = submodel.get("submodelElements", [])
1017 assert len(elements) == 6
1018 assert elements[5].get("idShort", "") == submodel_element_collection.id_short
1019 list_elements = elements[5].get("value", [])
1020 assert len(list_elements) == 1
1021 assert list_elements[0].get("idShort", "") == property.id_short
1022 assert list_elements[0].get("value", "") == property.value
1023
1024 base_url: str = client.base_url
1025 new_client = create_by_url(base_url=base_url)
1026 assert new_client is not None
1027 assert new_client.submodels is not None
1028
1029 sm = new_client.submodels.get_submodel_by_id(AIMC_SM_ID)
1030 assert sm is None
1031
1032 decoded_id = encoder.encode_base_64(AIMC_SM_ID)
1033 decoded_sm = new_client.submodels.get_submodel_by_id(decoded_id)
1034 assert decoded_sm is not None
1035 assert decoded_sm.get("id", "") == AIMC_SM_ID
1036
1037def test_020b_encoded_ids(client: AasHttpClient):
1038 base_url: str = client.base_url
1039 new_client = create_by_url(base_url=base_url)
1040 assert new_client is not None
1041 assert new_client.shells is not None
1042
1043 sm = new_client.shells.get_asset_administration_shell_by_id(SHELL_ID)
1044 assert sm is None
1045
1046 decoded_id = encoder.encode_base_64(SHELL_ID)
1047 decoded_sm = new_client.shells.get_asset_administration_shell_by_id(decoded_id)
1048 assert decoded_sm is not None
1049 assert decoded_sm.get("id", "") == SHELL_ID
1050
1052 if client.experimental is None:
1053 pytest.skip("Experimental API is not available in this client")
1054
1055 if client.submodels is None:
1056 pytest.skip("Submodels API is not available in this client")
1057
1058 parsed = urlparse(client.base_url)
1059 if parsed.port in JAVA_SERVER_PORTS or parsed.port in PYTHON_SERVER_PORTS:
1060 # NOTE: python server implementation differs
1061 # NOTE: Basyx java server do not provide this endpoint
1062 return
1063
1064 sm_id = SM_ID
1065
1066 if client.encoded_ids:
1067 sm_id = encoder.encode_base_64(SM_ID)
1068
1069 file_sme = model.File("file_sme", content_type="application/pdf")
1070 file_post_result = client.submodels.post_submodel_element_submodel_repo(sm_id, sdk_tools.convert_to_dict(file_sme))
1071 assert file_post_result is not None
1072
1073 filename = "https.pdf"
1074 file = Path(f"./tests/test_data/{filename}").resolve()
1075 result = client.experimental.post_file_by_path_submodel_repo(sm_id, file_sme.id_short, file)
1076 assert result is True
1077
1078 result_sme = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, file_sme.id_short)
1079
1080 assert result_sme is not None
1081 assert result_sme.get("idShort", "") == file_sme.id_short
1082 assert result_sme.get("contentType", "") == file_sme.content_type
1083 assert "value" in result_sme
1084 assert result_sme.get("value", "") == f"/{filename}"
1085
1087 if client.experimental is None:
1088 pytest.skip("Experimental API is not available in this client")
1089
1090 parsed = urlparse(client.base_url)
1091 if parsed.port in JAVA_SERVER_PORTS or parsed.port in PYTHON_SERVER_PORTS:
1092 # NOTE: python server implementation differs
1093 # NOTE: Basyx java server do not provide this endpoint
1094 return
1095
1096 sm_id = SM_ID
1097
1098 if client.encoded_ids:
1099 sm_id = encoder.encode_base_64(SM_ID)
1100
1101 result = client.experimental.get_file_by_path_submodel_repo(sm_id, "file_sme")
1102 assert result is not None
1103 assert len(result) > 0
1104 assert result.startswith(b"%PDF-1.7")
1105
1107 if client.experimental is None:
1108 pytest.skip("Experimental API is not available in this client")
1109
1110 if client.submodels is None:
1111 pytest.skip("Submodels API is not available in this client")
1112
1113 parsed = urlparse(client.base_url)
1114 if parsed.port in JAVA_SERVER_PORTS or parsed.port in PYTHON_SERVER_PORTS:
1115 # NOTE: python server implementation differs
1116 # NOTE: Basyx java server do not provide this endpoint
1117 return
1118
1119 sm_id = SM_ID
1120
1121 if client.encoded_ids:
1122 sm_id = encoder.encode_base_64(SM_ID)
1123
1124 filename = "aimc.json"
1125 file = Path(f"./tests/test_data/{filename}").resolve()
1126 result = client.experimental.put_file_by_path_submodel_repo(sm_id, "file_sme", file)
1127 assert result is True
1128
1129 get_result = client.experimental.get_file_by_path_submodel_repo(sm_id, "file_sme")
1130 assert get_result is not None
1131 assert len(get_result) > 0
1132 assert get_result.startswith(b"{\n")
1133
1134 result_sme = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, "file_sme")
1135 assert result_sme is not None
1136 assert "value" in result_sme
1137 assert result_sme.get("value", "") == f"/{filename}"
1138
1140 if client.experimental is None:
1141 pytest.skip("Experimental API is not available in this client")
1142
1143 if client.submodels is None:
1144 pytest.skip("Submodels API is not available in this client")
1145
1146 parsed = urlparse(client.base_url)
1147 if parsed.port in JAVA_SERVER_PORTS or parsed.port in PYTHON_SERVER_PORTS:
1148 # NOTE: python server do not provide this endpoint
1149 return
1150
1151 sm_id = SM_ID
1152
1153 if client.encoded_ids:
1154 sm_id = encoder.encode_base_64(SM_ID)
1155
1156 result = client.experimental.delete_file_by_path_submodel_repo(sm_id, "file_sme")
1157 assert result is True
1158
1159 get_result = client.experimental.get_file_by_path_submodel_repo(sm_id, "file_sme")
1160 assert get_result is None
1161
1162 result_sme = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, "file_sme")
1163 assert result_sme is not None
1164 assert "value" in result_sme
1165 assert result_sme.get("value", "") == None
1166
1167def test_025_get_thumbnail_aas_repository(client: AasHttpClient):
1168 if client.shells is None:
1169 pytest.skip("Shells API is not available in this client")
1170
1171 parsed = urlparse(client.base_url)
1172 if parsed.port in PYTHON_SERVER_PORTS:
1173 # NOTE: python server implementation differs
1174 return
1175
1176 shell_id = SHELL_ID
1177
1178 if client.encoded_ids:
1179 shell_id = encoder.encode_base_64(SHELL_ID)
1180
1181 result = client.shells.get_thumbnail_aas_repository(shell_id)
1182 assert result is None
1183
1184
1185
1186def test_026_put_thumbnail_aas_repository(client: AasHttpClient):
1187 if client.shells is None:
1188 pytest.skip("Shells API is not available in this client")
1189
1190 parsed = urlparse(client.base_url)
1191 if parsed.port in PYTHON_SERVER_PORTS:
1192 # NOTE: python server implementation differs
1193 return
1194
1195 shell_id = SHELL_ID
1196
1197 if client.encoded_ids:
1198 shell_id = encoder.encode_base_64(SHELL_ID)
1199
1200 filename = "Pen_Machine.png"
1201 file = Path(f"./tests/test_data/{filename}").resolve()
1202
1203 result = client.shells.put_thumbnail_aas_repository(shell_id, file.name, file)
1204 assert result is True
1205
1206def test_027_get_thumbnail_aas_repository(client: AasHttpClient):
1207 if client.shells is None:
1208 pytest.skip("Shells API is not available in this client")
1209
1210 parsed = urlparse(client.base_url)
1211 if parsed.port in PYTHON_SERVER_PORTS:
1212 # NOTE: python server implementation differs
1213 return
1214
1215 shell_id = SHELL_ID
1216
1217 if client.encoded_ids:
1218 shell_id = encoder.encode_base_64(SHELL_ID)
1219
1220 result = client.shells.get_thumbnail_aas_repository(shell_id)
1221 assert result is not None
1222 assert len(result) > 0
1223 assert result.startswith(b"\x89PNG\r\n\x1a\n")
1224
1226 if client.shells is None:
1227 pytest.skip("Shells API is not available in this client")
1228
1229 parsed = urlparse(client.base_url)
1230 if parsed.port in PYTHON_SERVER_PORTS:
1231 # NOTE: python server do not provide this endpoint
1232 return
1233
1234 shell_id = SHELL_ID
1235
1236 if client.encoded_ids:
1237 shell_id = encoder.encode_base_64(SHELL_ID)
1238
1239 result = client.shells.delete_thumbnail_aas_repository(shell_id)
1240 assert result is True
1241
1242 get_result = client.shells.get_thumbnail_aas_repository(shell_id)
1243 assert get_result is None
1244
1246 if client.shells is None:
1247 pytest.skip("Shells API is not available in this client")
1248
1249 parsed = urlparse(client.base_url)
1250 if parsed.port in PYTHON_SERVER_PORTS:
1251 # NOTE: python server implementation differs
1252 return
1253
1254 shell_id = SHELL_ID
1255
1256 if client.encoded_ids:
1257 shell_id = encoder.encode_base_64(SHELL_ID)
1258
1259 filename = "Pen_Machine.png"
1260 file = Path(f"./tests/test_data/{filename}").resolve()
1261
1262 with file.open("rb") as f:
1263 file_octet_stream = f.read()
1264
1265 result = client.shells.put_thumbnail_aas_repository_stream(shell_id, file.name, file_octet_stream, "image/png")
1266 assert result is True
1267
1268 get_result = client.shells.get_thumbnail_aas_repository(shell_id)
1269 assert get_result is not None
1270 assert len(get_result) > 0
1271 assert get_result.startswith(b"\x89PNG\r\n\x1a\n")
1272
1273 delete_result = client.shells.delete_thumbnail_aas_repository(shell_id)
1274 assert delete_result is True
1275
1276 get_result = client.shells.get_thumbnail_aas_repository(shell_id)
1277 assert get_result is None
1278
1280 if client.shells is None:
1281 pytest.skip("Shells API is not available in this client")
1282
1283 shell_id = SHELL_ID
1284
1285 if client.encoded_ids:
1286 shell_id = encoder.encode_base_64(SHELL_ID)
1287
1288 result = client.shells.get_all_submodel_references_aas_repository(shell_id)
1289 assert result is not None
1290 references = result.get("result", [])
1291 assert len(references) == 1
1292
1294 if client.shells is None:
1295 pytest.skip("Shells API is not available in this client")
1296
1297 shell_id = SHELL_ID
1298
1299 if client.encoded_ids:
1300 shell_id = encoder.encode_base_64(SHELL_ID)
1301
1302 id = "temp_sm_id"
1303 id_short = "TempSM"
1304 temp_sml_ref = model.ModelReference.from_referable(model_builder.create_base_submodel(identifier=id, id_short=id_short))
1305
1306 result = client.shells.post_submodel_reference_aas_repository(shell_id, sdk_tools.convert_to_dict(temp_sml_ref))
1307
1308 assert result is not None
1309 assert len(result.get("keys", [])) > 0
1310 key: dict = result.get("keys", [])[0]
1311 assert key.get("value", "") == id
1312 assert key.get("type", "") == "Submodel"
1313
1314 check_result = client.shells.get_all_submodel_references_aas_repository(shell_id)
1315 assert check_result is not None
1316 check_references = check_result.get("result", [])
1317 assert len(check_references) == 2
1318
1320 if client.shells is None:
1321 pytest.skip("Submodels API is not available in this client")
1322
1323 shell_id = SHELL_ID
1324 sm_id = "temp_sm_id"
1325
1326 if client.encoded_ids:
1327 shell_id = encoder.encode_base_64(SHELL_ID)
1328 sm_id = encoder.encode_base_64(sm_id)
1329
1330 result = client.shells.delete_submodel_reference_by_id_aas_repository(shell_id, sm_id)
1331
1332 assert result is True
1333
1334 get_result = client.shells.get_all_submodel_references_aas_repository(shell_id)
1335 assert get_result is not None
1336 references = get_result.get("result", [])
1337 assert len(references) == 1
1338
1339def test_032_put_submodel_element_by_path_submodel_repo(client: AasHttpClient, shared_sme_string: model.Property):
1340 if client.submodels is None:
1341 pytest.skip("Submodels API is not available in this client")
1342
1343 sm_id = SM_ID
1344
1345 if client.encoded_ids:
1346 sm_id = encoder.encode_base_64(SM_ID)
1347
1348 get_result = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_string.id_short)
1349 assert get_result is not None
1350 old_value = get_result.get("value", "")
1351
1352 new_value = "New Value via PUT"
1353
1354 sme_data_string = json.dumps(shared_sme_string, cls=basyx.aas.adapter.json.AASToJsonEncoder)
1355 sme_data = json.loads(sme_data_string)
1356 sme_data["value"] = new_value
1357
1358 result = client.submodels.put_submodel_element_by_path_submodel_repo(sm_id, shared_sme_string.id_short, sme_data)
1359
1360 assert result is True
1361
1362 get_result = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_string.id_short)
1363
1364 assert get_result is not None
1365 assert get_result.get("idShort", "") == shared_sme_string.id_short
1366 assert get_result.get("value", "") == new_value
1367 assert get_result.get("value", "") != old_value
1368 assert shared_sme_string.description is not None
1369 assert shared_sme_string.display_name is not None
1370 assert get_result.get("description", {})[0].get("text", "") == shared_sme_string.description.get("en", "")
1371 assert get_result.get("displayName", {})[0].get("text", "") == shared_sme_string.display_name.get("en", "")
1372
1373 # restore original value
1374 sme_data["value"] = "Sample String Value"
1375 result = client.submodels.put_submodel_element_by_path_submodel_repo(sm_id, shared_sme_string.id_short, sme_data)
1376
1377def test_033a_get_submodel_element_by_path_value_only_submodel_repo(client: AasHttpClient, shared_sme_string: model.Property):
1378 if client.submodels is None:
1379 pytest.skip("Submodels API is not available in this client")
1380
1381 sm_id = SM_ID
1382
1383 if client.encoded_ids:
1384 sm_id = encoder.encode_base_64(SM_ID)
1385
1386 value = client.submodels.get_submodel_element_by_path_value_only_submodel_repo(sm_id, shared_sme_string.id_short)
1387
1388 parsed = urlparse(client.base_url)
1389 if parsed.port in PYTHON_SERVER_PORTS:
1390 # NOTE: python server do not provide this endpoint
1391 assert value is None
1392 return
1393
1394 assert value is not None
1395
1396 sm_data = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_string.id_short)
1397 assert sm_data is not None
1398 assert value == sm_data.get("value", "")
1399
1400def test_033b_get_submodel_element_by_path_value_only_submodel_repo(client: AasHttpClient, shared_sme_int: model.Property):
1401 if client.submodels is None:
1402 pytest.skip("Submodels API is not available in this client")
1403
1404 sm_id = SM_ID
1405
1406 if client.encoded_ids:
1407 sm_id = encoder.encode_base_64(SM_ID)
1408
1409 value = client.submodels.get_submodel_element_by_path_value_only_submodel_repo(sm_id, shared_sme_int.id_short)
1410
1411 parsed = urlparse(client.base_url)
1412 if parsed.port in PYTHON_SERVER_PORTS:
1413 # NOTE: python server do not provide this endpoint
1414 assert value is None
1415 return
1416
1417 assert value is not None
1418
1419 sm_data = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_int.id_short)
1420 assert sm_data is not None
1421 assert int(value) == int(sm_data.get("value", ""))
1422
1423def test_033c_get_submodel_element_by_path_value_only_submodel_repo(client: AasHttpClient, shared_sme_float: model.Property):
1424 if client.submodels is None:
1425 pytest.skip("Submodels API is not available in this client")
1426
1427 sm_id = SM_ID
1428
1429 if client.encoded_ids:
1430 sm_id = encoder.encode_base_64(SM_ID)
1431
1432 value = client.submodels.get_submodel_element_by_path_value_only_submodel_repo(sm_id, shared_sme_float.id_short)
1433
1434 parsed = urlparse(client.base_url)
1435 if parsed.port in PYTHON_SERVER_PORTS:
1436 # NOTE: python server do not provide this endpoint
1437 assert value is None
1438 return
1439
1440 assert value is not None
1441
1442 sm_data = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_float.id_short)
1443 assert sm_data is not None
1444 assert float(value) == float(sm_data.get("value", ""))
1445
1446def test_033d_get_submodel_element_by_path_value_only_submodel_repo(client: AasHttpClient, shared_sme_bool: model.Property):
1447 if client.submodels is None:
1448 pytest.skip("Submodels API is not available in this client")
1449
1450 sm_id = SM_ID
1451
1452 if client.encoded_ids:
1453 sm_id = encoder.encode_base_64(SM_ID)
1454
1455 value = client.submodels.get_submodel_element_by_path_value_only_submodel_repo(sm_id, shared_sme_bool.id_short)
1456
1457 parsed = urlparse(client.base_url)
1458 if parsed.port in PYTHON_SERVER_PORTS:
1459 # NOTE: python server do not provide this endpoint
1460 assert value is None
1461 return
1462
1463 assert value is not None
1464
1465 sm_data = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_bool.id_short)
1466 assert sm_data is not None
1467 #assert bool(value) == bool(sm_data.get("value", ""))
1468
1469# def test_033e_get_submodel_element_by_path_value_only_submodel_repo(client: AasHttpClient, shared_sme_collection: model.SubmodelElementCollection):
1470# if client.submodels is None:
1471# pytest.skip("Submodels API is not available in this client")
1472
1473# post_result = client.submodels.post_submodel_element_submodel_repo(SM_ID, sdk_tools.convert_to_dict(shared_sme_collection))
1474# assert post_result is not None
1475
1476# sm_id = SM_ID
1477
1478# if client.encoded_ids:
1479# sm_id = encoder.encode_base_64(SM_ID)
1480
1481# value = client.submodels.get_submodel_element_by_path_value_only_submodel_repo(sm_id, shared_sme_collection.id_short)
1482
1483# parsed = urlparse(client.base_url)
1484# if parsed.port in PYTHON_SERVER_PORTS:
1485# # NOTE: python server do not provide this endpoint
1486# assert value is None
1487# return
1488
1489# assert value is not None
1490
1491# sm_data = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_collection.id_short)
1492# assert sm_data is not None
1493# assert value == sm_data.get("value", "")
1494# assert bool(value) == bool(sm_data.get("value", ""))
1495
1496def test_034_get_submodel_by_id_value_only(client: AasHttpClient, shared_sm: model.Submodel):
1497 if client.submodels is None:
1498 pytest.skip("Submodels API is not available in this client")
1499
1500 sm_id = SM_ID
1501
1502 if client.encoded_ids:
1503 sm_id = encoder.encode_base_64(SM_ID)
1504
1505 response = client.submodels.get_submodel_by_id_value_only(sm_id)
1506
1507 parsed = urlparse(client.base_url)
1508 if parsed.port in PYTHON_SERVER_PORTS:
1509 # NOTE: python server do not provide this endpoint
1510 assert response is None
1511 return
1512 elif parsed.port in DOTNET_SERVER_PORTS:
1513 assert response is not None
1514 value = response[shared_sm.id_short]
1515 else:
1516 assert response is not None
1517 value = response
1518
1519 assert value is not None
1520 assert len(value) > 5
1521 assert "sme_property_int" in value
1522 assert int(value["sme_property_int"]) == 263
1523 assert "sme_property_string" in value
1524 assert value["sme_property_string"] == "Sample String Value"
1525 assert "sme_property_float" in value
1526 assert float(value["sme_property_float"]) == 262.1
1527
1528def test_035_patch_submodel_by_id_value_only(client: AasHttpClient, shared_sm: model.Submodel, shared_sme_string: model.Property, shared_sme_int: model.Property, shared_sme_float: model.Property):
1529 if client.submodels is None:
1530 pytest.skip("Submodels API is not available in this client")
1531
1532 sm_id = SM_ID
1533
1534 if client.encoded_ids:
1535 sm_id = encoder.encode_base_64(SM_ID)
1536
1537 value_dict = {
1538 shared_sme_string.id_short: shared_sme_string.value,
1539 shared_sme_int.id_short: str(shared_sme_int.value),
1540 shared_sme_float.id_short: str(shared_sme_float.value)
1541 }
1542
1543 # patch_dict = {shared_sm.id: value_dict}
1544
1545 patch_dict = value_dict
1546
1547 parsed = urlparse(client.base_url)
1548 if parsed.port in PYTHON_SERVER_PORTS:
1549 # NOTE: python server do not provide this endpoint
1550 return
1551
1552 if parsed.port in JAVA_SERVER_PORTS:
1553 # NOTE: java server endpoint seems to work not correctly
1554 return
1555
1556 elif parsed.port in DOTNET_SERVER_PORTS:
1557 patch_dict = value_dict
1558
1559 result = client.submodels.patch_submodel_by_id_value_only(sm_id, patch_dict)
1560
1561 assert result is True
1562
1563 string_prop_dict = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_string.id_short)
1564 int_prop_dict = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_int.id_short)
1565 float_prop_dict = client.submodels.get_submodel_element_by_path_submodel_repo(sm_id, shared_sme_float.id_short)
1566
1567 assert string_prop_dict is not None
1568 assert int_prop_dict is not None
1569 assert float_prop_dict is not None
1570
1571 assert string_prop_dict.get("value", "") == shared_sme_string.value
1572 assert int(int_prop_dict.get("value", "")) == int(shared_sme_int.value)
1573 assert float(float_prop_dict.get("value", "")) == float(shared_sme_float.value)
1574
1575
1576def test_036_get_submodel_by_id_metadata(client: AasHttpClient, shared_sm: model.Submodel):
1577 if client.submodels is None:
1578 pytest.skip("Submodels API is not available in this client")
1579
1580 sm_id = SM_ID
1581
1582 if client.encoded_ids:
1583 sm_id = encoder.encode_base_64(SM_ID)
1584
1585 metadata = client.submodels.get_submodel_by_id_metadata(sm_id)
1586 assert metadata is not None
1587
1588 submodel = client.submodels.get_submodel_by_id(sm_id)
1589 assert submodel is not None
1590
1591 assert metadata.get("id", "") == submodel.get("id", "")
1592 assert metadata.get("idShort", "") == submodel.get("idShort", "")
1593 assert metadata.get("description", {})[0].get("text", "") == submodel.get("description", {})[0].get("text", "")
1594 if "displayName" in submodel and submodel.get("displayName", []):
1595 assert metadata.get("displayName", {})[0].get("text", "") == submodel.get("displayName", {})[0].get("text", "")
1596 assert "submodelElements" not in metadata
1597
1599 if client.shells is None:
1600 pytest.skip("Shells API is not available in this client")
1601
1602 shell_id = SHELL_ID
1603
1604 if client.encoded_ids:
1605 shell_id = encoder.encode_base_64(SHELL_ID)
1606
1607 result = client.shells.delete_asset_administration_shell_by_id(shell_id)
1608
1609 assert result is True
1610
1611 get_result = client.shells.get_all_asset_administration_shells()
1612 assert get_result is not None
1613 shells = get_result.get("result", [])
1614 assert len(shells) == 0
1615
1616def test_099a_delete_submodel_by_id(client: AasHttpClient):
1617 if client.submodels is None:
1618 pytest.skip("Submodels API is not available in this client")
1619
1620 sm_id = SM_ID
1621
1622 if client.encoded_ids:
1623 sm_id = encoder.encode_base_64(SM_ID)
1624
1625 result = client.submodels.delete_submodel_by_id(sm_id)
1626
1627 assert result is True
1628
1629 get_result = client.submodels.get_all_submodels()
1630 assert get_result is not None
1631 submodels = get_result.get("result", [])
1632 assert len(submodels) == 1
1633
1634def test_099b_delete_submodel_by_id(client: AasHttpClient):
1635 if client.submodels is None:
1636 pytest.skip("Submodels API is not available in this client")
1637
1638 sm_id = AIMC_SM_ID
1639
1640 if client.encoded_ids:
1641 sm_id = encoder.encode_base_64(AIMC_SM_ID)
1642
1643 result = client.submodels.delete_submodel_by_id(sm_id)
1644
1645 assert result is True
1646
1647 get_result = client.submodels.get_all_submodels()
1648 assert get_result is not None
1649 submodels = get_result.get("result", [])
1650 assert len(submodels) == 0
test_099b_delete_submodel_by_id(AasHttpClient client)
model.SubmodelElementCollection shared_sme_collection()
test_032_put_submodel_element_by_path_submodel_repo(AasHttpClient client, model.Property shared_sme_string)
test_018b_patch_submodel_element_by_path_value_only_submodel_repo(AasHttpClient client, model.Property shared_sme_bool)
model.Property shared_sme_float()
test_028a_put_thumbnail_aas_repository_stream(AasHttpClient client)
test_013_put_submodel_by_id_aas_repository(AasHttpClient client, model.Submodel shared_sm)
test_033b_get_submodel_element_by_path_value_only_submodel_repo(AasHttpClient client, model.Property shared_sme_int)
test_018a_patch_submodel_element_by_path_value_only_submodel_repo(AasHttpClient client, model.Property shared_sme_string)
test_018d_patch_submodel_element_by_path_value_only_submodel_repo(AasHttpClient client, model.Property shared_sme_float)
test_016b_post_submodel_element_submodel_repo(AasHttpClient client, model.Property shared_sme_bool)
test_005a_put_asset_administration_shell_by_id(AasHttpClient client, model.AssetAdministrationShell shared_aas)
test_033d_get_submodel_element_by_path_value_only_submodel_repo(AasHttpClient client, model.Property shared_sme_bool)
test_000b_create_client_by_dict(AasHttpClient client)
model.Submodel shared_sm()
test_029_get_all_submodel_references_aas_repository(AasHttpClient client)
test_026_put_thumbnail_aas_repository(AasHttpClient client)
test_014_put_submodels_by_id(AasHttpClient client, model.Submodel shared_sm)
test_036_get_submodel_by_id_metadata(AasHttpClient client, model.Submodel shared_sm)
test_000a_create_client_by_url(AasHttpClient client)
test_011a_get_submodel_by_id(AasHttpClient client, model.Submodel shared_sm)
test_017d_get_submodel_element_by_path_submodel_repo(AasHttpClient client, model.Property shared_sme_float)
test_021_post_file_by_path_submodel_repo(AasHttpClient client)
test_019b_post_submodel_element_by_path_submodel_repo(AasHttpClient client)
test_007_get_submodel_by_id_aas_repository(AasHttpClient client)
test_016c_post_submodel_element_submodel_repo(AasHttpClient client, model.Property shared_sme_int)
model.AssetAdministrationShell shared_aas(model.Submodel shared_sm)
test_009a_post_submodel(AasHttpClient client, model.Submodel shared_sm)
test_033a_get_submodel_element_by_path_value_only_submodel_repo(AasHttpClient client, model.Property shared_sme_string)
model.Property shared_sme_string()
test_010_get_submodel_by_id_aas_repository(AasHttpClient client, model.Submodel shared_sm)
test_098_delete_asset_administration_shell_by_id(AasHttpClient client)
test_027_get_thumbnail_aas_repository(AasHttpClient client)
test_009b_post_submodel(AasHttpClient client)
test_002_get_all_asset_administration_shells(AasHttpClient client)
test_011d_get_submodel_by_id(AasHttpClient client)
test_024_delete_file_content_by_path_submodel_repo(AasHttpClient client)
test_015_get_all_submodel_elements_submodel_repository(AasHttpClient client, model.Submodel shared_sm)
test_011c_get_submodel_by_id(AasHttpClient client)
test_012_patch_submodel_by_id(AasHttpClient client, model.Submodel shared_sm)
test_001a_connect(AasHttpClient client)
test_017a_get_submodel_element_by_path_submodel_repo(AasHttpClient client, model.Property shared_sme_string)
test_001c_delete_all_submodels(AasHttpClient client)
test_017c_get_submodel_element_by_path_submodel_repo(AasHttpClient client, model.Property shared_sme_int)
model.Property shared_sme_int()
test_016a_post_submodel_element_submodel_repo(AasHttpClient client, model.Property shared_sme_string)
test_099a_delete_submodel_by_id(AasHttpClient client)
test_005b_put_asset_administration_shell_by_id(AasHttpClient client, model.AssetAdministrationShell shared_aas)
model.Property shared_sme_bool()
test_001b_delete_all_asset_administration_shells(AasHttpClient client)
test_006_get_asset_administration_shell_by_id_reference_aas_repository(AasHttpClient client)
test_031_delete_submodel_reference_by_id_aas_repository(AasHttpClient client)
test_030_post_submodel_reference_aas_repository(AasHttpClient client)
test_004b_get_asset_administration_shell_by_id(AasHttpClient client)
test_035_patch_submodel_by_id_value_only(AasHttpClient client, model.Submodel shared_sm, model.Property shared_sme_string, model.Property shared_sme_int, model.Property shared_sme_float)
test_022_get_file_content_by_path_submodel_repo(AasHttpClient client)
test_018c_patch_submodel_element_by_path_value_only_submodel_repo(AasHttpClient client, model.Property shared_sme_int)
test_025_get_thumbnail_aas_repository(AasHttpClient client)
test_008_get_all_submodels(AasHttpClient client)
test_011b_get_submodel_by_id(AasHttpClient client)
test_017b_get_submodel_element_by_path_submodel_repo(AasHttpClient client, model.Property shared_sme_bool)
test_003_post_asset_administration_shell(AasHttpClient client, model.AssetAdministrationShell shared_aas)
test_019a_post_submodel_element_by_path_submodel_repo(AasHttpClient client)
test_023_put_file_content_by_path_submodel_repo(AasHttpClient client)
test_004a_get_asset_administration_shell_by_id(AasHttpClient client, model.AssetAdministrationShell shared_aas)
test_028_delete_thumbnail_aas_repository(AasHttpClient client)
test_020b_encoded_ids(AasHttpClient client)
test_033c_get_submodel_element_by_path_value_only_submodel_repo(AasHttpClient client, model.Property shared_sme_float)
test_016d_post_submodel_element_submodel_repo(AasHttpClient client, model.Property shared_sme_float)
test_034_get_submodel_by_id_value_only(AasHttpClient client, model.Submodel shared_sm)