Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for device attributes #16

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 7 additions & 0 deletions tests/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Loading