Skip to content

Commit

Permalink
Merge pull request #15 from osmanhadzic/appengine-devices
Browse files Browse the repository at this point in the history
Add tests for device information retrieval
  • Loading branch information
Annopaolo authored Nov 13, 2024
2 parents 4d5608b + 1ae88e2 commit a96f387
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
111 changes: 111 additions & 0 deletions tests/app_engine/device/test_app_engine_device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# SPDX-FileCopyrightText: 2024 SECO Mind Srl
#
# SPDX-License-Identifier: Apache-2.0


import subprocess
import json


from resources import list_of_interface_names


def test_app_engine_device_list(astarte_env_vars):
astarte_url = astarte_env_vars["astarte_url"]
realm = astarte_env_vars["realm"]
jwt = astarte_env_vars["jwt"]
device_test_1 = astarte_env_vars["device_test_1"]

arg_list = [
"astartectl",
"appengine",
"devices",
"list",
"-t",
jwt,
"-u",
astarte_url,
"-r",
realm,
]
sample_data_result = subprocess.run(arg_list, capture_output=True, text=True)
assert device_test_1 in sample_data_result.stdout


def test_app_engine_device_show(astarte_env_vars):
astarte_url = astarte_env_vars["astarte_url"]
realm = astarte_env_vars["realm"]
jwt = astarte_env_vars["jwt"]
device_test_1 = astarte_env_vars["device_test_1"]

arg_list = [
"astartectl",
"appengine",
"devices",
"show",
device_test_1,
"-t",
jwt,
"-u",
astarte_url,
"-r",
realm,
]
sample_data_result = subprocess.run(arg_list, capture_output=True, text=True)

assert device_test_1 in sample_data_result.stdout

for key in list_of_interface_names:
assert key in sample_data_result.stdout


def test_app_engine_device_data_snapshot(astarte_env_vars):
astarte_url = astarte_env_vars["astarte_url"]
realm = astarte_env_vars["realm"]
jwt = astarte_env_vars["jwt"]
device_test_1 = astarte_env_vars["device_test_1"]

arg_list = [
"astartectl",
"appengine",
"devices",
"data-snapshot",
device_test_1,
"-t",
jwt,
"-u",
astarte_url,
"-r",
realm,
"-o",
"json",
]
sample_data_result = subprocess.run(arg_list, capture_output=True, text=True)

json_value = json.loads(sample_data_result.stdout)

for interface in list_of_interface_names:
assert interface in json_value


def test_app_engine_stats_device(astarte_env_vars):
astarte_url = astarte_env_vars["astarte_url"]
realm = astarte_env_vars["realm"]
jwt = astarte_env_vars["jwt"]

arg_list = [
"astartectl",
"appengine",
"stats",
"device",
"-t",
jwt,
"-u",
astarte_url,
"-r",
realm,
]

sample_data_result = subprocess.run(arg_list, capture_output=True, text=True)
except_output = "{TotalDevices:1 ConnectedDevices:0}\n"
assert sample_data_result.stdout == except_output
13 changes: 13 additions & 0 deletions tests/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,16 @@
"/a/datetimearray": "[2024-09-09T09:09:09.900Z 2024-09-10T09:09:09.900Z]",
"/a/binaryblobarray": "[aGVsbG8gd29ybGQ= d29ybGQgaGVsbG8=]",
}

list_of_interface_names = [
"test.astarte-platform.device.individual.nonparametric.Datastream",
"test.astarte-platform.device.individual.nonparametric.Properties",
"test.astarte-platform.device.individual.parametric.Datastream",
"test.astarte-platform.device.individual.parametric.Properties",
"test.astarte-platform.device.object.nonparametric.Datastream",
"test.astarte-platform.device.object.parametric.Datastream",
"test.astarte-platform.server.individual.nonparametric.Datastream",
"test.astarte-platform.server.individual.nonparametric.Properties",
"test.astarte-platform.server.individual.parametric.Datastream",
"test.astarte-platform.server.individual.parametric.Properties",
]

0 comments on commit a96f387

Please sign in to comment.