From 388538e1c4f47629d517442e46f8c2652f771b44 Mon Sep 17 00:00:00 2001 From: Aiden Baker Date: Wed, 4 Sep 2024 09:55:52 -0400 Subject: [PATCH 1/2] Updated test --- tests/api2/test_070_alertservice.py | 83 ++++++----------------------- 1 file changed, 15 insertions(+), 68 deletions(-) diff --git a/tests/api2/test_070_alertservice.py b/tests/api2/test_070_alertservice.py index b4cfe2941b6a3..0846d687a7a1f 100644 --- a/tests/api2/test_070_alertservice.py +++ b/tests/api2/test_070_alertservice.py @@ -1,28 +1,14 @@ -#!/usr/bin/env python3 - import pytest -import os -import sys -apifolder = os.getcwd() -sys.path.append(apifolder) -from functions import GET, POST, PUT, DELETE - -def test_01_get_alertservice(): - results = GET("/alertservice/") - assert results.status_code == 200, results.text - assert isinstance(results.json(), list), results.text +from middlewared.test.integration.utils import call -def test_02_get_alertservice_list_types(): - results = GET("/alertservice/list_types/") - assert results.status_code == 200, results.text - assert isinstance(results.json(), list), results.text - assert results.json(), results.text +def test_alert_gets(): + call("alertservice.query") + call("alertservice.list_types") def test_03_create_an_alertservice(): - global alertservice_id, payload, results payload = { "name": "Critical Email Test", "type": "Mail", @@ -32,31 +18,13 @@ def test_03_create_an_alertservice(): "level": "CRITICAL", "enabled": True } - results = POST("/alertservice/", payload) - assert results.status_code == 200, results.text - assert isinstance(results.json(), dict), results.text - alertservice_id = results.json()['id'] - - -@pytest.mark.parametrize('data', ["name", "type", "attributes", "level", "enabled"]) -def test_04_verify_the_alertservice_creation_results(data): - assert results.json()[data] == payload[data], results.text - - -def test_05_get_alertservice_with_id(): - global results - results = GET(f"/alertservice/id/{alertservice_id}") - assert results.status_code == 200, results.text - assert isinstance(results.json(), dict), results.text - - -@pytest.mark.parametrize('data', ["name", "type", "attributes", "level", "enabled"]) -def test_06_verify_the_id_alertservice_results(data): - assert results.json()[data] == payload[data], results.text + results = call("alertservice.create", payload) + alertservice_id = results['id'] + data = ["name", "type", "attributes", "level", "enabled"] + for key in data: + assert results[key] == payload[key] -def test_07_change_config_to_alertservice_id(): - global alertservice_id, payload, results payload = { "name": "Warning Email Test", "type": "Mail", @@ -66,33 +34,12 @@ def test_07_change_config_to_alertservice_id(): "level": "WARNING", "enabled": False } - results = PUT(f"/alertservice/id/{alertservice_id}", payload) - assert results.status_code == 200, results.text - assert isinstance(results.json(), dict), results.text - - -@pytest.mark.parametrize('data', ["name", "type", "attributes", "level", "enabled"]) -def test_08_verify_the_alertservice_changes_results(data): - assert results.json()[data] == payload[data], results.text - - -def test_09_get_alertservice_changes_with_id(): - global results - results = GET(f"/alertservice/id/{alertservice_id}") - assert results.status_code == 200, results.text - assert isinstance(results.json(), dict), results.text - - -@pytest.mark.parametrize('data', ["name", "type", "attributes", "level", "enabled"]) -def test_10_verify_the_id_alertservice_changes_results(data): - assert results.json()[data] == payload[data], results.text - + results = call(f"alertservice.update", alertservice_id, payload) -def test_11_delete_alertservice(): - results = DELETE(f"/alertservice/id/{alertservice_id}") - assert results.status_code == 200, results.text + for key in data: + assert results[key] == payload[key], results.text -def test_12_verify_alertservice_is_delete(): - results = GET(f"/alertservice/id/{alertservice_id}") - assert results.status_code == 404, results.text + # delete + call("alertservice.delete", alertservice_id) + assert call("alertservice.query", [["id", "=", alertservice_id]]) == [] From 42d7f35f7f8d431512cfa5b0f79f41d86084f7b3 Mon Sep 17 00:00:00 2001 From: Aiden Baker Date: Wed, 4 Sep 2024 09:57:49 -0400 Subject: [PATCH 2/2] Small fix --- tests/api2/test_070_alertservice.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/api2/test_070_alertservice.py b/tests/api2/test_070_alertservice.py index 0846d687a7a1f..867c1618065fd 100644 --- a/tests/api2/test_070_alertservice.py +++ b/tests/api2/test_070_alertservice.py @@ -8,7 +8,10 @@ def test_alert_gets(): call("alertservice.list_types") -def test_03_create_an_alertservice(): +def test_alertservice(): + data = ["name", "type", "attributes", "level", "enabled"] + + # create payload = { "name": "Critical Email Test", "type": "Mail", @@ -19,12 +22,12 @@ def test_03_create_an_alertservice(): "enabled": True } results = call("alertservice.create", payload) - alertservice_id = results['id'] - - data = ["name", "type", "attributes", "level", "enabled"] for key in data: assert results[key] == payload[key] + alertservice_id = results['id'] + + # update payload = { "name": "Warning Email Test", "type": "Mail", @@ -35,10 +38,8 @@ def test_03_create_an_alertservice(): "enabled": False } results = call(f"alertservice.update", alertservice_id, payload) - for key in data: - assert results[key] == payload[key], results.text - + assert results[key] == payload[key] # delete call("alertservice.delete", alertservice_id)