From 68ebb11685f7a96232485aa32f3fa2576b80ee4c Mon Sep 17 00:00:00 2001 From: caleb Date: Fri, 6 Sep 2024 13:19:32 -0400 Subject: [PATCH 1/3] remove REST from test_360 (and rename) --- tests/api2/test_360_pool_scrub.py | 77 --------------------------- tests/api2/test_pool_scrub.py | 86 +++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 77 deletions(-) delete mode 100644 tests/api2/test_360_pool_scrub.py create mode 100644 tests/api2/test_pool_scrub.py diff --git a/tests/api2/test_360_pool_scrub.py b/tests/api2/test_360_pool_scrub.py deleted file mode 100644 index 5127536062374..0000000000000 --- a/tests/api2/test_360_pool_scrub.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python3 - -import pytest -import sys -import os -from pytest_dependency import depends -apifolder = os.getcwd() -sys.path.append(apifolder) -from functions import GET, PUT, POST, DELETE -from auto_config import pool_name - - -def test_01_create_scrub_for_same_pool(request): - global pool_id - pool_id = GET(f"/pool/?name={pool_name}").json()[0]["id"] - result = POST("/pool/scrub/", { - "pool": pool_id, - "threshold": 1, - "description": "", - "schedule": { - "minute": "00", - "hour": "00", - "dom": "1", - "month": "1", - "dow": "1", - }, - "enabled": True, - }) - assert result.status_code == 422, result.text - text = "A scrub with this pool already exists" - assert result.json()["pool_scrub_create.pool"][0]["message"] == text, result.text - - -def test_02_get_pool_name_scrub_id(request): - global scrub_id - result = GET(f"/pool/scrub/?pool_name={pool_name}") - assert result.status_code == 200, result.text - scrub_id = result.json()[0]['id'] - - -def test_03_update_scrub(request): - result = PUT(f"/pool/scrub/id/{scrub_id}/", { - "pool": pool_id, - "threshold": 2, - "description": "", - "schedule": { - "minute": "00", - "hour": "00", - "dom": "1", - "month": "1", - "dow": "1", - }, - "enabled": True, - }) - assert result.status_code == 200, result.text - - -def test_04_delete_scrub(request): - result = DELETE(f"/pool/scrub/id/{scrub_id}/") - assert result.status_code == 200, result.text - - -def test_05_create_scrub(request): - result = POST("/pool/scrub/", { - "pool": pool_id, - "threshold": 1, - "description": "", - "schedule": { - "minute": "00", - "hour": "00", - "dom": "1", - "month": "1", - "dow": "1", - }, - "enabled": True, - }) - assert result.status_code == 200, result.text diff --git a/tests/api2/test_pool_scrub.py b/tests/api2/test_pool_scrub.py new file mode 100644 index 0000000000000..7281d120252d2 --- /dev/null +++ b/tests/api2/test_pool_scrub.py @@ -0,0 +1,86 @@ +import errno + +import pytest + +from auto_config import pool_name +from middlewared.service_exception import ValidationError, ValidationErrors +from middlewared.test.integration.utils.client import call + + +@pytest.fixture(scope="module") +def scrub_info(): + for i in call("pool.scrub.query", [["name", "=", pool_name]]): + return i + else: + # by default, on pool creation a scrub task is created + assert False, f"Failed to find scrub job for {pool_name!r}" + + +def test_create_duplicate_scrub_fails(scrub_info): + with pytest.raises(ValidationErrors) as ve: + call( + "pool.scrub.create", + { + "pool": scrub_info["pool"], + "threshold": 1, + "description": "", + "schedule": { + "minute": "00", + "hour": "00", + "dom": "1", + "month": "1", + "dow": "1", + }, + "enabled": True, + }, + ) + assert ve.value.errors == [ + ValidationError( + "pool_scrub_create.pool", + "A scrub with this pool already exists", + errno.EINVAL, + ) + ] + + +def test_update_scrub(scrub_info): + assert call( + "pool.scrub.update", + scrub_info["id"], + { + "threshold": 2, + "description": "", + "schedule": { + "minute": "00", + "hour": "00", + "dom": "1", + "month": "1", + "dow": "1", + }, + "enabled": True, + }, + ) + + +def test_delete_scrub(scrub_info): + call("pool.scrub.delete", scrub_info["id"]) + assert call("pool.scrub.query", [["name", "=", pool_name]]) == [] + + +def test_create_scrub(scrub_info): + assert call( + "pool.scrub.create", + { + "pool": scrub_info["pool"], + "threshold": 1, + "description": "", + "schedule": { + "minute": "00", + "hour": "00", + "dom": "1", + "month": "1", + "dow": "1", + }, + "enabled": True, + }, + ) From b7372d4465f8e44a96a5ecfacc8aeae735ecfe43 Mon Sep 17 00:00:00 2001 From: caleb Date: Fri, 6 Sep 2024 13:43:06 -0400 Subject: [PATCH 2/3] fix import --- tests/api2/test_pool_scrub.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/api2/test_pool_scrub.py b/tests/api2/test_pool_scrub.py index 7281d120252d2..e1519b9d36247 100644 --- a/tests/api2/test_pool_scrub.py +++ b/tests/api2/test_pool_scrub.py @@ -4,7 +4,7 @@ from auto_config import pool_name from middlewared.service_exception import ValidationError, ValidationErrors -from middlewared.test.integration.utils.client import call +from middlewared.test.integration.utils import call @pytest.fixture(scope="module") From b0abe3d23e53db4c018478c58420dfd9ace0e61b Mon Sep 17 00:00:00 2001 From: caleb Date: Fri, 6 Sep 2024 13:52:54 -0400 Subject: [PATCH 3/3] fix query filter --- tests/api2/test_pool_scrub.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/api2/test_pool_scrub.py b/tests/api2/test_pool_scrub.py index e1519b9d36247..ce5650dfea4dc 100644 --- a/tests/api2/test_pool_scrub.py +++ b/tests/api2/test_pool_scrub.py @@ -9,7 +9,7 @@ @pytest.fixture(scope="module") def scrub_info(): - for i in call("pool.scrub.query", [["name", "=", pool_name]]): + for i in call("pool.scrub.query", [["pool_name", "=", pool_name]]): return i else: # by default, on pool creation a scrub task is created @@ -64,7 +64,7 @@ def test_update_scrub(scrub_info): def test_delete_scrub(scrub_info): call("pool.scrub.delete", scrub_info["id"]) - assert call("pool.scrub.query", [["name", "=", pool_name]]) == [] + assert call("pool.scrub.query", [["pool_name", "=", pool_name]]) == [] def test_create_scrub(scrub_info):