-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Astarte group managment
- Add tests for creating and listing groups. - Add tests for adding, listing, and removing devices from groups. - Updated resources.py to include mygroup variable for group name. Signed-off-by: Jusuf <jusuf.avdic@secomind.com>
- Loading branch information
Showing
2 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# SPDX-FileCopyrightText: 2024 SECO Mind Srl | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
import subprocess | ||
|
||
from resources import mygroup | ||
|
||
def test_app_engine_group_create(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", | ||
"groups", | ||
"create", | ||
mygroup, | ||
device_test_1, | ||
"-t", | ||
jwt, | ||
"-u", | ||
astarte_url, | ||
"-r", | ||
realm, | ||
] | ||
|
||
sample_data_result = subprocess.run(arg_list, capture_output=True, text=True) | ||
assert sample_data_result.stdout.replace("\n", "") == "ok" | ||
|
||
def test_app_engine_group_list(astarte_env_vars): | ||
astarte_url = astarte_env_vars["astarte_url"] | ||
realm = astarte_env_vars["realm"] | ||
jwt = astarte_env_vars["jwt"] | ||
|
||
arg_list = [ | ||
"astartectl", | ||
"appengine", | ||
"groups", | ||
"list", | ||
"-t", | ||
jwt, | ||
"-u", | ||
astarte_url, | ||
"-r", | ||
realm, | ||
] | ||
|
||
sample_data_result = subprocess.run(arg_list, capture_output=True, text=True) | ||
sample_data_result.stdout = _replace_brackets_from_string(sample_data_result.stdout) | ||
assert sample_data_result.stdout in mygroup | ||
|
||
def test_app_engine_group_devices_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", | ||
"groups", | ||
"devices", | ||
"list", | ||
mygroup, | ||
"-t", | ||
jwt, | ||
"-u", | ||
astarte_url, | ||
"-r", | ||
realm, | ||
] | ||
|
||
sample_data_result = subprocess.run(arg_list, capture_output=True, text=True) | ||
sample_data_result.stdout = _replace_brackets_from_string(sample_data_result.stdout) | ||
assert sample_data_result.stdout in device_test_1 | ||
|
||
def test_app_engine_group_add_device(astarte_env_vars): | ||
astarte_url = astarte_env_vars["astarte_url"] | ||
realm = astarte_env_vars["realm"] | ||
jwt = astarte_env_vars["jwt"] | ||
device_test_2 = astarte_env_vars["device_test_2"] | ||
|
||
arg_list = [ | ||
"astartectl", | ||
"appengine", | ||
"groups", | ||
"devices", | ||
"add", | ||
mygroup, | ||
device_test_2, | ||
"-t", | ||
jwt, | ||
"-u", | ||
astarte_url, | ||
"-r", | ||
realm, | ||
] | ||
|
||
sample_data_result = subprocess.run(arg_list, capture_output=True, text=True) | ||
print(sample_data_result.stdout) | ||
assert sample_data_result.stdout.replace("\n", "") == "ok" | ||
|
||
def test_app_engine_group_remove_device(astarte_env_vars): | ||
astarte_url = astarte_env_vars["astarte_url"] | ||
realm = astarte_env_vars["realm"] | ||
jwt = astarte_env_vars["jwt"] | ||
device_test_2 = astarte_env_vars["device_test_2"] | ||
|
||
arg_list = [ | ||
"astartectl", | ||
"appengine", | ||
"groups", | ||
"devices", | ||
"remove", | ||
mygroup, | ||
device_test_2, | ||
"-t", | ||
jwt, | ||
"-u", | ||
astarte_url, | ||
"-r", | ||
realm, | ||
] | ||
|
||
sample_data_result = subprocess.run(arg_list, capture_output=True, text=True) | ||
print(sample_data_result.stdout) | ||
assert sample_data_result.stdout.replace("\n", "") == "ok" | ||
|
||
def _replace_brackets_from_string(input_string): | ||
return input_string.replace("\n", "").replace("[", "").replace("]", "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters