From ba2e6ffaee1961a20eecf540d09f2b1e4df7c536 Mon Sep 17 00:00:00 2001 From: Aiden <53726630+aiden3c@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:16:00 -0400 Subject: [PATCH] NAS-130907 / 25.04 / Removed REST from test_150_cronjob (#14399) --- tests/api2/test_150_cronjob.py | 71 ---------------------------------- tests/api2/test_cronjob.py | 40 +++++++++++++++++++ 2 files changed, 40 insertions(+), 71 deletions(-) delete mode 100644 tests/api2/test_150_cronjob.py create mode 100644 tests/api2/test_cronjob.py diff --git a/tests/api2/test_150_cronjob.py b/tests/api2/test_150_cronjob.py deleted file mode 100644 index 1bfaafda92993..0000000000000 --- a/tests/api2/test_150_cronjob.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python3 -# License: BSD - -import sys -import os -import pytest -from time import sleep -from pytest_dependency import depends -apifolder = os.getcwd() -sys.path.append(apifolder) -from functions import POST, PUT, SSH_TEST, GET, DELETE -from auto_config import user, password - -TESTFILE = '/tmp/.testFileCreatedViaCronjob' - - -@pytest.fixture(scope='module') -def cronjob_dict(): - return {} - - -def test_01_Creating_new_cron_job_which_will_run_every_minute(cronjob_dict): - results = POST('/cronjob/', { - 'user': 'root', - 'command': f'touch "{TESTFILE}"', - 'schedule': {'minute': '*/1'} - }) - assert results.status_code == 200, results.text - cronjob_dict.update(results.json()) - assert isinstance(cronjob_dict['id'], int) is True - - -def test_02_Checking_to_see_if_cronjob_was_created_and_enabled(cronjob_dict): - id = cronjob_dict['id'] - results = GET(f'/cronjob?id={id}') - assert results.json()[0]['enabled'] is True - - -def test_03_Wait_a_minute(): - sleep(65) - - -def test_04_Updating_cronjob_status_to_disabled_updating_command(cronjob_dict): - id = cronjob_dict['id'] - results = PUT(f'/cronjob/id/{id}/', { - 'enabled': False - }) - assert results.status_code == 200, results.text - - -def test_05_Checking_that_API_reports_the_cronjob_as_updated(cronjob_dict): - id = cronjob_dict['id'] - results = GET(f'/cronjob?id={id}') - assert results.json()[0]['enabled'] is False - - -def test_06_Deleting_test_file_created_by_cronjob(request): - results = SSH_TEST(f'rm "{TESTFILE}"', user, password) - assert results['result'] is True, results['output'] - - -def test_07_Deleting_cron_job_which_will_run_every_minute(cronjob_dict): - id = cronjob_dict['id'] - results = DELETE(f'/cronjob/id/{id}/', None) - assert results.status_code == 200, results.text - - -def test_08_Check_that_the_API_reports_the_cronjob_as_deleted(cronjob_dict): - id = cronjob_dict['id'] - results = GET(f'/cronjob?id={id}') - assert results.json() == [], results.text diff --git a/tests/api2/test_cronjob.py b/tests/api2/test_cronjob.py new file mode 100644 index 0000000000000..89c145fad0543 --- /dev/null +++ b/tests/api2/test_cronjob.py @@ -0,0 +1,40 @@ +from time import sleep + +import pytest + +from middlewared.test.integration.utils import call, ssh + +TESTFILE = '/tmp/.testFileCreatedViaCronjob' + + +def test_create_check_update_verify_cron_job(): + cronjob_dict = {} + + # create job + results = call("cronjob.create", { + 'user': 'root', + 'command': f'touch "{TESTFILE}"', + 'schedule': {'minute': '*/1'} + }) + cronjob_dict.update(results) + + # verify job creation + id = cronjob_dict['id'] + results = call('cronjob.query', [['id', '=', id]], {"get": True}) + assert results['enabled'] is True + + # wait so job can run + sleep(65) + + # disable job + id = cronjob_dict['id'] + call('cronjob.update', id, {'enabled': False}) + + # remove test file + results = ssh(f'rm "{TESTFILE}"', complete_response=True) + assert results['result'] is True, results['output'] + + # delete job + call('cronjob.delete', cronjob_dict['id']) + results = call('cronjob.query', [['id', '=', id]], {"get": True}) + assert results.json() == []