Skip to content

Commit

Permalink
NAS-130927 / 25.04 / Remove REST calls in test_070_alertservice (#14413)
Browse files Browse the repository at this point in the history
  • Loading branch information
aiden3c authored Sep 4, 2024
1 parent fe61e0c commit 205ce8d
Showing 1 changed file with 18 additions and 70 deletions.
88 changes: 18 additions & 70 deletions tests/api2/test_070_alertservice.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
#!/usr/bin/env python3

import pytest
import os
import sys
apifolder = os.getcwd()
sys.path.append(apifolder)
from functions import GET, POST, PUT, DELETE

from middlewared.test.integration.utils import call

def test_01_get_alertservice():
results = GET("/alertservice/")
assert results.status_code == 200, results.text
assert isinstance(results.json(), list), results.text

def test_alert_gets():
call("alertservice.query")
call("alertservice.list_types")

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_alertservice():
data = ["name", "type", "attributes", "level", "enabled"]

def test_03_create_an_alertservice():
global alertservice_id, payload, results
# create
payload = {
"name": "Critical Email Test",
"type": "Mail",
Expand All @@ -32,31 +21,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

results = call("alertservice.create", payload)
for key in data:
assert results[key] == payload[key]

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
alertservice_id = results['id']


@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


def test_07_change_config_to_alertservice_id():
global alertservice_id, payload, results
# update
payload = {
"name": "Warning Email Test",
"type": "Mail",
Expand All @@ -66,33 +37,10 @@ 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


def test_11_delete_alertservice():
results = DELETE(f"/alertservice/id/{alertservice_id}")
assert results.status_code == 200, results.text

results = call(f"alertservice.update", alertservice_id, payload)
for key in data:
assert results[key] == payload[key]

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]]) == []

0 comments on commit 205ce8d

Please sign in to comment.