From 37cd119ac5886c950770008ca02023c2bb525d72 Mon Sep 17 00:00:00 2001 From: Osman Hadzic Date: Thu, 14 Nov 2024 16:53:34 +0100 Subject: [PATCH] Add tests for device attributes - Add tests for setting, listing, and removing device attributes. - Update resources.py to include device attributes Signed-off-by: Osman Hadzic --- .../test_app_engine_device_attributes.py | 89 +++++++++++++++++++ tests/resources.py | 7 ++ 2 files changed, 96 insertions(+) create mode 100644 tests/app_engine/device/app_engine_device_aliases_attributes/test_app_engine_device_attributes.py diff --git a/tests/app_engine/device/app_engine_device_aliases_attributes/test_app_engine_device_attributes.py b/tests/app_engine/device/app_engine_device_aliases_attributes/test_app_engine_device_attributes.py new file mode 100644 index 0000000..04a9cb5 --- /dev/null +++ b/tests/app_engine/device/app_engine_device_aliases_attributes/test_app_engine_device_attributes.py @@ -0,0 +1,89 @@ +# SPDX-FileCopyrightText: 2024 SECO Mind Srl +# +# SPDX-License-Identifier: Apache-2.0 + +import subprocess + +from resources import list_of_attributes + + +def test_app_engine_device_attributes_set(astarte_env_vars): + device_id = astarte_env_vars["device_test_1"] + astarte_url = astarte_env_vars["astarte_url"] + realm = astarte_env_vars["realm"] + jwt = astarte_env_vars["jwt"] + + for attribute in list_of_attributes: + arg_list = [ + "astartectl", + "appengine", + "devices", + "attributes", + "set", + device_id, + list_of_attributes[attribute], + "-t", + jwt, + "-u", + astarte_url, + "-r", + realm, + ] + attributes_add_result = subprocess.run(arg_list, capture_output=True, text=True) + assert attributes_add_result.stdout.replace("\n", "") == "ok" + + +def test_app_engine_device_atributes_list(astarte_env_vars): + device_id = astarte_env_vars["device_test_1"] + astarte_url = astarte_env_vars["astarte_url"] + realm = astarte_env_vars["realm"] + jwt = astarte_env_vars["jwt"] + + arg_list = [ + "astartectl", + "appengine", + "devices", + "attributes", + "list", + device_id, + "-t", + jwt, + "-u", + astarte_url, + "-r", + realm, + ] + attributes_result = subprocess.run(arg_list, capture_output=True, text=True) + attributes_result = ( + attributes_result.stdout.replace("map[", "").replace("]", "").replace("\n", "") + ) + + for attribute in list_of_attributes: + assert attribute in attributes_result + + +def test_app_engine_device_attributes_remove(astarte_env_vars): + device_id = astarte_env_vars["device_test_1"] + astarte_url = astarte_env_vars["astarte_url"] + realm = astarte_env_vars["realm"] + jwt = astarte_env_vars["jwt"] + + for attribute in list_of_attributes: + print(attribute) + arg_list = [ + "astartectl", + "appengine", + "devices", + "attributes", + "remove", + device_id, + attribute, + "-t", + jwt, + "-u", + astarte_url, + "-r", + realm, + ] + attributes_delete_result = subprocess.run(arg_list, capture_output=True, text=True) + assert attributes_delete_result.stdout.replace("\n", "") == "ok" diff --git a/tests/resources.py b/tests/resources.py index e4cbb05..1191ac5 100644 --- a/tests/resources.py +++ b/tests/resources.py @@ -228,3 +228,10 @@ "test.astarte-platform.server.individual.parametric.Datastream", "test.astarte-platform.server.individual.parametric.Properties", ] + +list_of_attributes = { + "test_attribute1": "test_attribute1=attribute1", + "test_attribute2": "test_attribute2=attribute2", + "test_attribute3": "test_attribute3=attribute3", + "test_attribute4": "test_attribute4=attribute4", +}