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

Tests for Astarte group management #18

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions .github/workflows/astarte-ctl-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ jobs:
TOKEN=$(astartectl utils gen-jwt all-realm-apis)
echo "E2E_JWT=$TOKEN" >> $GITHUB_ENV
echo "E2E_DEVICE_TEST_1=ogmcilZpRDeDWwuNfJr0yA" >> $GITHUB_ENV
DEVICE_TEST_2=$(astartectl utils device-id generate-random)
echo "E2E_DEVICE_TEST_2=$DEVICE_TEST_2" >> $GITHUB_ENV
astartectl pairing agent register --compact-output -- "$DEVICE_TEST_2"

- name: Setup python
uses: actions/setup-python@v2
Expand Down
140 changes: 140 additions & 0 deletions tests/app_engine/device/test_app_engine_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# 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("]", "")
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ def astarte_env_vars():
realm = os.environ.get("E2E_REALM")
jwt = os.environ.get("E2E_JWT")
device_test_1 = os.environ.get("E2E_DEVICE_TEST_1")
device_test_2 = os.environ.get("E2E_DEVICE_TEST_2")

assert (
astarte_url and realm and jwt
astarte_url and realm and jwt and device_test_1 and device_test_2
), "Environment variables for Astarte setup are not properly configured."

return {
"astarte_url": astarte_url,
"realm": realm,
"jwt": jwt,
"device_test_1": device_test_1,
"device_test_2": device_test_2,
}
2 changes: 2 additions & 0 deletions tests/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,5 @@
"test_attribute3": "test_attribute3=attribute3",
"test_attribute4": "test_attribute4=attribute4",
}

mygroup = "test_group"
Loading