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

NAS-130927 / 25.04 / Remove REST calls in test_070_alertservice #14413

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Changes from all 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
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]]) == []
Loading