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..ce5650dfea4dc --- /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 import call + + +@pytest.fixture(scope="module") +def scrub_info(): + for i in call("pool.scrub.query", [["pool_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", [["pool_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, + }, + )