mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-07-18 09:54:55 +00:00
test: fix remaining tests broken by task system redesign
Update all tests that created PaperlessTask objects with old field names to use PaperlessTaskFactory and new field names (task_type, trigger_source, status, result_message). Use apply_async instead of delay where mocked. Drop TestCheckSanityTaskRecording — tests PaperlessTask creation that was intentionally removed from check_sanity(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
61bfe25e17
commit
a6c93b7703
@@ -29,29 +29,24 @@ ACCEPT_V9 = "application/json; version=9"
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def superuser(db) -> User:
|
||||
return User.objects.create_superuser(username="admin", password="admin")
|
||||
def regular_user(django_user_model: User) -> User:
|
||||
return django_user_model.objects.create_user(username="regular", password="regular")
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def regular_user(db) -> User:
|
||||
return User.objects.create_user(username="regular", password="regular")
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def admin_client(superuser: User) -> APIClient:
|
||||
def admin_client(admin_user: User) -> APIClient:
|
||||
"""Authenticated admin client sending v10 Accept header."""
|
||||
client = APIClient()
|
||||
client.force_authenticate(user=superuser)
|
||||
client.force_authenticate(user=admin_user)
|
||||
client.credentials(HTTP_ACCEPT=ACCEPT_V10)
|
||||
return client
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def v9_client(superuser: User) -> APIClient:
|
||||
def v9_client(admin_user: User) -> APIClient:
|
||||
"""Authenticated admin client sending v9 Accept header."""
|
||||
client = APIClient()
|
||||
client.force_authenticate(user=superuser)
|
||||
client.force_authenticate(user=admin_user)
|
||||
client.credentials(HTTP_ACCEPT=ACCEPT_V9)
|
||||
return client
|
||||
|
||||
@@ -65,11 +60,6 @@ def user_client(regular_user: User) -> APIClient:
|
||||
return client
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TestGetTasksV10
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.django_db()
|
||||
class TestGetTasksV10:
|
||||
def test_list_returns_tasks(self, admin_client: APIClient) -> None:
|
||||
@@ -202,7 +192,7 @@ class TestGetTasksV10:
|
||||
|
||||
def test_list_is_owner_aware(
|
||||
self,
|
||||
superuser: User,
|
||||
admin_user: User,
|
||||
regular_user: User,
|
||||
) -> None:
|
||||
"""The task list only shows tasks the user owns or that are unowned."""
|
||||
@@ -214,7 +204,7 @@ class TestGetTasksV10:
|
||||
client.force_authenticate(user=regular_user)
|
||||
client.credentials(HTTP_ACCEPT=ACCEPT_V10)
|
||||
|
||||
PaperlessTaskFactory(owner=superuser)
|
||||
PaperlessTaskFactory(owner=admin_user)
|
||||
shared_task = PaperlessTaskFactory()
|
||||
own_task = PaperlessTaskFactory(owner=regular_user)
|
||||
|
||||
@@ -227,11 +217,6 @@ class TestGetTasksV10:
|
||||
assert own_task.task_id in returned_task_ids
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TestGetTasksV9
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.django_db()
|
||||
class TestGetTasksV9:
|
||||
def test_task_name_equals_task_type_value(self, v9_client: APIClient) -> None:
|
||||
@@ -363,11 +348,6 @@ class TestGetTasksV9:
|
||||
assert response.data[0]["type"] == "SCHEDULED_TASK"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TestAcknowledge
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.django_db()
|
||||
class TestAcknowledge:
|
||||
def test_returns_count(self, admin_client: APIClient) -> None:
|
||||
@@ -430,11 +410,6 @@ class TestAcknowledge:
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TestAcknowledgeAll
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.django_db()
|
||||
class TestAcknowledgeAll:
|
||||
def test_marks_only_completed_tasks(self, admin_client: APIClient) -> None:
|
||||
@@ -474,11 +449,6 @@ class TestAcknowledgeAll:
|
||||
assert response.data == {"result": 1}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TestSummary
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.django_db()
|
||||
class TestSummary:
|
||||
def test_returns_per_type_totals(self, admin_client: APIClient) -> None:
|
||||
@@ -505,11 +475,6 @@ class TestSummary:
|
||||
assert by_type["train_classifier"]["total_count"] == 1
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TestActive
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.django_db()
|
||||
class TestActive:
|
||||
def test_returns_pending_and_started_only(self, admin_client: APIClient) -> None:
|
||||
@@ -537,11 +502,6 @@ class TestActive:
|
||||
assert len(response.data) == 0
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TestRun
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.django_db()
|
||||
class TestRun:
|
||||
def test_forbidden_for_regular_user(self, user_client: APIClient) -> None:
|
||||
|
||||
Reference in New Issue
Block a user