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