From 36643a9900bb5bc9a3b95008b93e572389a28f7b Mon Sep 17 00:00:00 2001 From: Brian M Date: Thu, 18 Jul 2024 10:22:40 -0700 Subject: [PATCH] Convert UPS tests that use the REST interface to WS --- tests/api2/test_530_ups.py | 125 +++++++++++++------------------------ 1 file changed, 44 insertions(+), 81 deletions(-) diff --git a/tests/api2/test_530_ups.py b/tests/api2/test_530_ups.py index 4c0f6fdcc209..7fd1b30e68da 100644 --- a/tests/api2/test_530_ups.py +++ b/tests/api2/test_530_ups.py @@ -2,11 +2,8 @@ # License: BSD import pytest -import os -import sys -apifolder = os.getcwd() -sys.path.append(apifolder) -from functions import GET, PUT, POST + +from middlewared.test.integration.utils import call first_ups_list = [ 'rmonitor', @@ -31,22 +28,19 @@ def test_01_get_ups_service_id(): global ups_id - results = GET('/service/?service=ups') - assert results.status_code == 200, results.text - assert results.json()[0]['state'] == 'STOPPED', results.text - assert results.json()[0]['enable'] is False, results.text - ups_id = results.json()[0]['id'] + results = call('service.query', [['service', '=', 'ups']], {'get': True}) + assert results['state'] == 'STOPPED', results + assert results['enable'] is False, results + ups_id = results['id'] def test_02_Enabling_UPS_Service_at_boot(): - results = PUT('/service/id/ups/', {'enable': True}) - assert results.status_code == 200, results.text + call('service.update', 'ups', {'enable': True}) def test_03_look_if_UPS_service_is_enable(): - results = GET(f'/service/id/{ups_id}/') - assert results.status_code == 200, results.text - assert results.json()['enable'] is True, results.text + results = call('service.query', [['service', '=', 'ups']], {'get': True}) + assert results['enable'] is True, results def test_04_Set_UPS_options(): @@ -61,38 +55,31 @@ def test_04_Set_UPS_options(): 'driver': 'usbhid-ups$PROTECT NAS', 'monpwd': 'mypassword' } - results = PUT('/ups/', payload) - assert results.status_code == 200, results.text + results = call('ups.update', payload) @pytest.mark.parametrize('data', first_ups_list) def test_05_look_at_UPS_options_output_of_(data): - assert payload[data] == results.json()[data], results.text + assert payload[data] == results[data], results.text def test_06_starting_ups_service(): - payload = { - "service": "ups", - } - results = POST('/service/start/', payload) - assert results.status_code == 200, results.text + call('service.start', 'ups') def test_07_look_UPS_service_status_is_running(): - results = GET(f'/service/id/{ups_id}/') - assert results.status_code == 200, results.text - assert results.json()['state'] == 'RUNNING', results.text + results = call('service.query', [['service', '=', 'ups']], {'get': True}) + assert results['state'] == 'RUNNING', results def test_08_get_API_reports_UPS_configuration_as_saved(): global results - results = GET('/ups/') - assert results.status_code == 200, results.text + results = call('ups.config') @pytest.mark.parametrize('data', first_ups_list) def test_09_look_API_reports_UPS_configuration_of_(data): - assert payload[data] == results.json()[data], results.text + assert payload[data] == results[data], results def test_10_change_UPS_options_while_service_is_running(): @@ -101,44 +88,36 @@ def test_10_change_UPS_options_while_service_is_running(): 'port': '65545', 'identifier': 'boo' } - results = PUT('/ups/', payload) - assert results.status_code == 200, results.text + results = call('ups.update', payload) @pytest.mark.parametrize('data', ['port', 'identifier']) def test_11_look_at_UPS_options_output_of_(data): - assert payload[data] == results.json()[data], results.text + assert payload[data] == results[data], results def test_12_get_API_reports_UPS_configuration_as_saved(): global results - results = GET('/ups/') - assert results.status_code == 200, results.text + results = call('ups.config') @pytest.mark.parametrize('data', ['port', 'identifier']) def test_13_look_API_reports_UPS_configuration_of_(data): - assert payload[data] == results.json()[data], results.text + assert payload[data] == results[data], results.text def test_14_look_if_UPS_service_status_is_still_running(): - results = GET(f'/service/id/{ups_id}/') - assert results.status_code == 200, results.text - assert results.json()['state'] == 'RUNNING', results.text + results = call('service.query', [['service', '=', 'ups']], {'get': True}) + assert results['state'] == 'RUNNING', results.text def test_15_stop_ups_service(): - payload = { - "service": "ups", - } - results = POST('/service/stop/', payload) - assert results.status_code == 200, results.text + call('service.stop', 'ups') def test_16_look_UPS_service_status_is_stopped(): - results = GET(f'/service/id/{ups_id}/') - assert results.status_code == 200, results.text - assert results.json()['state'] == 'STOPPED', results.text + results = call('service.query', [['service', '=', 'ups']], {'get': True}) + assert results['state'] == 'STOPPED', results def test_17_Change_UPS_options(): @@ -151,75 +130,59 @@ def test_17_Change_UPS_options(): 'identifier': 'foo', 'monpwd': 'secondpassword' } - results = PUT('/ups/', payload) - assert results.status_code == 200, results.text + results = call('ups.update', payload) @pytest.mark.parametrize('data', second_ups_list) def test_18_look_at_change_UPS_options_output_of_(data): - assert payload[data] == results.json()[data], results.text + assert payload[data] == results[data], results.text def test_19_starting_ups_service(): - payload = { - "service": "ups", - } - results = POST('/service/start/', payload) - assert results.status_code == 200, results.text + call('service.start', 'ups') def test_20_look_UPS_service_status_is_running(): - results = GET(f'/service/id/{ups_id}/') - assert results.status_code == 200, results.text - assert results.json()['state'] == 'RUNNING', results.text + results = call('service.query', [['service', '=', 'ups']], {'get': True}) + assert results['state'] == 'RUNNING', results def test_21_get_API_reports_UPS_configuration_as_changed(): global results - results = GET('/ups/') - assert results.status_code == 200, results.text + results = call('ups.config') @pytest.mark.parametrize('data', second_ups_list) def test_22_look_API_reports_UPS_configuration_of_(data): - assert payload[data] == results.json()[data], results.text + assert payload[data] == results[data], results.text def test_23_get_ups_driver_choice(): - results = GET('/ups/driver_choices/') - assert results.status_code == 200, results.text - assert isinstance(results.json(), dict) is True, results.text + results = call('ups.driver_choices') + assert isinstance(results, dict) is True, results global ups_dc ups_dc = results -def test_24_get_ups_driver_choice(): - results = GET('/ups/port_choices/') - assert results.status_code == 200, results.text - assert isinstance(results.json(), list) is True, results.text - assert isinstance(results.json()[0], str) is True, results.text +def test_24_get_ups_port_choice(): + results = call('ups.port_choices') + assert isinstance(results, list) is True, results + assert isinstance(results[0], str) is True, results def test_25_Disabling_UPS_Service(): - results = PUT('/service/id/ups/', {'enable': False}) - assert results.status_code == 200, results.text + call('service.update', 'ups', {'enable': False}) def test_26_Disabling_UPS_Service_at_boot(): - results = GET(f'/service/id/{ups_id}/') - assert results.status_code == 200, results.text - assert results.json()['enable'] is False, results.text + results = call('service.query', [['id', '=', ups_id]], {'get': True}) + assert results['enable'] is False, results def test_27_stop_ups_service(): - payload = { - "service": "ups", - } - results = POST('/service/stop/', payload) - assert results.status_code == 200, results.text + call('service.stop', 'ups') def test_28_look_UPS_service_status_is_stopped(): - results = GET(f'/service/id/{ups_id}/') - assert results.status_code == 200, results.text - assert results.json()['state'] == 'STOPPED', results.text + results = call('service.query', [['id', '=', ups_id]], {'get': True}) + assert results['state'] == 'STOPPED', results