Skip to content

Commit

Permalink
Merge pull request #23 from osmanhadzic/add-housekeeping-test
Browse files Browse the repository at this point in the history
Add housekeeping test
  • Loading branch information
Annopaolo authored Nov 26, 2024
2 parents 0b458dd + 4c6037a commit e6a698b
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/astarte-ctl-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ jobs:
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"
HOUSEKEEPING_TOKEN=$(astartectl utils gen-jwt housekeeping)
echo "E2E_HOUSEKEEPING_JWT=$HOUSEKEEPING_TOKEN" >> $GITHUB_ENV
- name: Setup python
uses: actions/setup-python@v2
Expand Down
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pytest -v ./tests/utils
pytest -v ./tests/app_engine
pytest -v ./tests/realm_management
pytest -v ./tests/pairing_agent
pytest -v ./tests/housekeeping
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ def astarte_env_vars():
astarte_url = os.environ.get("E2E_API_URL")
realm = os.environ.get("E2E_REALM")
jwt = os.environ.get("E2E_JWT")
housekeeping_jwt = os.environ.get("E2E_HOUSEKEEPING_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 and device_test_1 and device_test_2
astarte_url and realm and jwt and device_test_1 and device_test_2 and housekeeping_jwt
), "Environment variables for Astarte setup are not properly configured."

return {
Expand All @@ -27,4 +28,5 @@ def astarte_env_vars():
"jwt": jwt,
"device_test_1": device_test_1,
"device_test_2": device_test_2,
"housekeeping_jwt": housekeeping_jwt,
}
83 changes: 83 additions & 0 deletions tests/housekeeping/test_housekeeping_realm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# SPDX-FileCopyrightText: 2024 SECO Mind Srl
#
# SPDX-License-Identifier: Apache-2.0

import subprocess
import os


def test_housekeeping_realm_list(astarte_env_vars):
astarte_url = astarte_env_vars["astarte_url"]
realm = astarte_env_vars["realm"]
housekeeping_jwt = astarte_env_vars["housekeeping_jwt"]

arg_list = [
"astartectl",
"housekeeping",
"realms",
"list",
"-u",
astarte_url,
"-t",
housekeeping_jwt,
]
realm_list_result = subprocess.run(arg_list, capture_output=True, text=True)
realm_list = _replace_brackets_from_string(realm_list_result.stdout)
assert realm in realm_list


def test_housekeeping_realm_create(astarte_env_vars):
astarte_url = astarte_env_vars["astarte_url"]
housekeeping_jwt = astarte_env_vars["housekeeping_jwt"]

new_realm = "newrealm"

ark_key_create = ["astartectl", "utils", "gen-keypair", new_realm]

subprocess.run(ark_key_create, capture_output=True, text=True)

new_private_key = f"{new_realm}_public.pem"

private_key_dir = os.path.realpath(new_private_key)

arg_create = [
"astartectl",
"housekeeping",
"realms",
"create",
new_realm,
"-u",
astarte_url,
"--realm-public-key",
private_key_dir,
"-t",
housekeeping_jwt,
"-y",
]
realm_create_result = subprocess.run(arg_create, capture_output=True, text=True)
assert f"Realm {new_realm} created successfully!\n" in realm_create_result.stdout


def test_housekeeping_realm_show(astarte_env_vars):
astarte_url = astarte_env_vars["astarte_url"]
realm = astarte_env_vars["realm"]
jwt_token = astarte_env_vars["housekeeping_jwt"]

arg_show = [
"astartectl",
"housekeeping",
"realms",
"show",
realm,
"-t",
jwt_token,
"-u",
astarte_url,
]
realm_show_result = subprocess.run(arg_show, capture_output=True, text=True)

assert f"Name:{realm}" in realm_show_result.stdout


def _replace_brackets_from_string(string):
return string.replace("[", "").replace("]", "").replace("\n", "")
2 changes: 1 addition & 1 deletion tests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ profile = "black"
line-length = 88

[tool.setuptools]
packages = ["app_engine", "realm_management", "utils", "pairing_agent"]
packages = ["app_engine", "realm_management", "utils", "pairing_agent", "housekeeping"]

0 comments on commit e6a698b

Please sign in to comment.