aas-http-client 0.4.1__tar.gz → 0.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of aas-http-client might be problematic. Click here for more details.

Files changed (22) hide show
  1. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/PKG-INFO +1 -1
  2. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client/client.py +26 -0
  3. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client/wrapper/sdk_wrapper.py +15 -1
  4. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client.egg-info/PKG-INFO +1 -1
  5. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/pyproject.toml +1 -1
  6. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/tests/test_client.py +54 -0
  7. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/LICENSE +0 -0
  8. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/README.md +0 -0
  9. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client/__init__.py +0 -0
  10. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client/core/encoder.py +0 -0
  11. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client/core/version_check.py +0 -0
  12. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client/demo/demo_process.py +0 -0
  13. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client/demo/logging_handler.py +0 -0
  14. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client/utilities/__init__.py +0 -0
  15. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client/utilities/model_builder.py +0 -0
  16. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client/utilities/sdk_tools.py +0 -0
  17. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client.egg-info/SOURCES.txt +0 -0
  18. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client.egg-info/dependency_links.txt +0 -0
  19. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client.egg-info/requires.txt +0 -0
  20. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/aas_http_client.egg-info/top_level.txt +0 -0
  21. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/setup.cfg +0 -0
  22. {aas_http_client-0.4.1 → aas_http_client-0.4.2}/tests/test_wrapper.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.4.1
3
+ Version: 0.4.2
4
4
  Summary: Generic python HTTP client for communication with various types of AAS servers
5
5
  Author-email: Daniel Klein <daniel.klein@em.ag>
6
6
  License: # :em engineering methods AG Software License
@@ -510,6 +510,32 @@ class AasHttpClient(BaseModel):
510
510
  content = response.content.decode("utf-8")
511
511
  return json.loads(content)
512
512
 
513
+ def post_submodel_element_by_path_submodel_repo(self, submodel_id: str, submodel_element_path: str, submodel_element_data: dict) -> dict | None:
514
+ """Creates a new submodel element at a specified path within submodel elements hierarchy.
515
+
516
+ :param submodel_id: Encoded ID of the Submodel to create elements for
517
+ :param submodel_element_path: Path within the Submodel elements hierarchy
518
+ :param submodel_element_data: Data for the new Submodel element
519
+ :return: Submodel element data or None if an error occurred
520
+ """
521
+ decoded_submodel_id: str = decode_base_64(submodel_id)
522
+ url = f"{self.base_url}/submodels/{decoded_submodel_id}/submodel-elements/{submodel_element_path}"
523
+
524
+ try:
525
+ response = self._session.post(url, headers=HEADERS, json=submodel_element_data, timeout=self.time_out)
526
+ logger.debug(f"Call REST API url '{response.url}'")
527
+
528
+ if response.status_code != STATUS_CODE_201:
529
+ log_response_errors(response)
530
+ return None
531
+
532
+ except requests.exceptions.RequestException as e:
533
+ logger.error(f"Error call REST API: {e}")
534
+ return None
535
+
536
+ content = response.content.decode("utf-8")
537
+ return json.loads(content)
538
+
513
539
  def get_submodel_element_by_path_submodel_repo(self, submodel_id: str, submodel_element_path: str) -> dict | None:
514
540
  """Returns a specific submodel element from the Submodel at a specified path.
515
541
 
@@ -257,7 +257,7 @@ class SdkWrapper:
257
257
  return submodel_elements
258
258
 
259
259
  def post_submodel_element_submodel_repo(self, submodel_id: str, submodel_element: model.SubmodelElement) -> model.SubmodelElement | None:
260
- """Creates a new submodel element. !!!Serialization to model.SubmodelElements currently not possible.
260
+ """Creates a new submodel element.
261
261
 
262
262
  :param submodel_id: Encoded ID of the submodel to create elements for
263
263
  :param submodel_element: Submodel element to create
@@ -267,6 +267,20 @@ class SdkWrapper:
267
267
  content: dict = self._client.post_submodel_element_submodel_repo(submodel_id, sme_data)
268
268
  return _to_object(content)
269
269
 
270
+ def post_submodel_element_by_path_submodel_repo(
271
+ self, submodel_id: str, submodel_element_path: str, submodel_element: model.SubmodelElement
272
+ ) -> model.SubmodelElement | None:
273
+ """Creates a new submodel element at a specified path within submodel elements hierarchy.
274
+
275
+ :param submodel_id: Encoded ID of the submodel to create elements for
276
+ :param submodel_element_path: Path within the Submodel elements hierarchy
277
+ :param submodel_element: The new Submodel element
278
+ :return: Submodel element object or None if an error occurred
279
+ """
280
+ sme_data = _to_dict(submodel_element)
281
+ content: dict = self._client.post_submodel_element_by_path_submodel_repo(submodel_id, submodel_element_path, sme_data)
282
+ return _to_object(content)
283
+
270
284
  def get_submodel_element_by_path_submodel_repo(self, submodel_id: str, submodel_element_path: str) -> model.SubmodelElement | None:
271
285
  """Returns a specific submodel element from the Submodel at a specified path.
272
286
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.4.1
3
+ Version: 0.4.2
4
4
  Summary: Generic python HTTP client for communication with various types of AAS servers
5
5
  Author-email: Daniel Klein <daniel.klein@em.ag>
6
6
  License: # :em engineering methods AG Software License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "aas-http-client"
7
- version = "0.4.1"
7
+ version = "0.4.2"
8
8
  description = "Generic python HTTP client for communication with various types of AAS servers"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -555,6 +555,60 @@ def test_018d_patch_submodel_element_by_path_value_only_submodel_repo(client: Aa
555
555
  assert get_result.get("description", {})[0].get("text", "") == shared_sme_float.description.get("en", "")
556
556
  assert get_result.get("displayName", {})[0].get("text", "") == shared_sme_float.display_name.get("en", "")
557
557
 
558
+ def test_019a_post_submodel_element_by_path_submodel_repo(client: AasHttpClient, shared_sm: model.Submodel):
559
+ submodel_element_list = model.SubmodelElementList(id_short="sme_list_1", type_value_list_element=model.Property, value_type_list_element=model.datatypes.String)
560
+ submodel_element_list_dict = sdk_tools.convert_to_dict(submodel_element_list)
561
+ first_result = client.post_submodel_element_submodel_repo(shared_sm.id, submodel_element_list_dict)
562
+
563
+ assert first_result is not None
564
+
565
+ property = model_builder.create_base_submodel_element_property("sme_property_in_list", model.datatypes.String, "Value in List")
566
+ property_dict = sdk_tools.convert_to_dict(property)
567
+ del property_dict["idShort"]
568
+
569
+ result = client.post_submodel_element_by_path_submodel_repo(shared_sm.id, submodel_element_list.id_short, property_dict)
570
+
571
+ assert result is not None
572
+ assert "idShort" not in result # idShort was deleted
573
+
574
+ submodel = client.get_submodel_by_id(shared_sm.id)
575
+
576
+ assert submodel is not None
577
+ elements = submodel.get("submodelElements", [])
578
+ assert len(elements) == 5 # 4 previous properties + 1 list
579
+ assert elements[4].get("idShort", "") == submodel_element_list.id_short
580
+ list_elements = elements[4].get("value", [])
581
+ assert len(list_elements) == 1
582
+ assert list_elements[0].get("idShort", "") == ""
583
+ assert list_elements[0].get("value", "") == property.value
584
+
585
+
586
+ def test_019b_post_submodel_element_by_path_submodel_repo(client: AasHttpClient, shared_sm: model.Submodel):
587
+ submodel_element_collection = model.SubmodelElementCollection(id_short="sme_collection_1")
588
+ submodel_element_collection_dict = sdk_tools.convert_to_dict(submodel_element_collection)
589
+ first_result = client.post_submodel_element_submodel_repo(shared_sm.id, submodel_element_collection_dict)
590
+
591
+ assert first_result is not None
592
+
593
+ property = model_builder.create_base_submodel_element_property("sme_property_in_collection", model.datatypes.String, "Value in List")
594
+ property_dict = sdk_tools.convert_to_dict(property)
595
+
596
+ result = client.post_submodel_element_by_path_submodel_repo(shared_sm.id, submodel_element_collection.id_short, property_dict)
597
+
598
+ assert result is not None
599
+ assert result["idShort"] == property.id_short
600
+
601
+ submodel = client.get_submodel_by_id(shared_sm.id)
602
+
603
+ assert submodel is not None
604
+ elements = submodel.get("submodelElements", [])
605
+ assert len(elements) == 6
606
+ assert elements[5].get("idShort", "") == submodel_element_collection.id_short
607
+ list_elements = elements[5].get("value", [])
608
+ assert len(list_elements) == 1
609
+ assert list_elements[0].get("idShort", "") == property.id_short
610
+ assert list_elements[0].get("value", "") == property.value
611
+
558
612
  def test_098_delete_asset_administration_shell_by_id(client: AasHttpClient, shared_aas: model.AssetAdministrationShell):
559
613
  result = client.delete_asset_administration_shell_by_id(shared_aas.id)
560
614
 
File without changes