mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-05-11 00:55:23 +00:00
Chore(mypy): Annotate None returns for typing improvements (#11213)
This commit is contained in:
committed by
GitHub
parent
a9c0b06e28
commit
3b5ffbf9fa
@@ -16,13 +16,13 @@ from documents.views import TasksViewSet
|
||||
class TestTasks(DirectoriesMixin, APITestCase):
|
||||
ENDPOINT = "/api/tasks/"
|
||||
|
||||
def setUp(self):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
|
||||
self.user = User.objects.create_superuser(username="temp_admin")
|
||||
self.client.force_authenticate(user=self.user)
|
||||
|
||||
def test_get_tasks(self):
|
||||
def test_get_tasks(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- Attempted celery tasks
|
||||
@@ -57,7 +57,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
self.assertEqual(returned_task2["status"], celery.states.PENDING)
|
||||
self.assertEqual(returned_task2["task_file_name"], task2.task_file_name)
|
||||
|
||||
def test_get_single_task_status(self):
|
||||
def test_get_single_task_status(self) -> None:
|
||||
"""
|
||||
GIVEN
|
||||
- Query parameter for a valid task ID
|
||||
@@ -86,7 +86,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
|
||||
self.assertEqual(returned_task1["task_id"], task1.task_id)
|
||||
|
||||
def test_get_single_task_status_not_valid(self):
|
||||
def test_get_single_task_status_not_valid(self) -> None:
|
||||
"""
|
||||
GIVEN
|
||||
- Query parameter for a non-existent task ID
|
||||
@@ -110,7 +110,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(len(response.data), 0)
|
||||
|
||||
def test_acknowledge_tasks(self):
|
||||
def test_acknowledge_tasks(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- Attempted celery tasks
|
||||
@@ -136,7 +136,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
response = self.client.get(self.ENDPOINT + "?acknowledged=false")
|
||||
self.assertEqual(len(response.data), 0)
|
||||
|
||||
def test_acknowledge_tasks_requires_change_permission(self):
|
||||
def test_acknowledge_tasks_requires_change_permission(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A regular user initially without change permissions
|
||||
@@ -174,7 +174,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
def test_tasks_owner_aware(self):
|
||||
def test_tasks_owner_aware(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- Existing PaperlessTasks with owner and with no owner
|
||||
@@ -220,7 +220,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
self.assertEqual(acknowledge_response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(acknowledge_response.data, {"result": 2})
|
||||
|
||||
def test_task_result_no_error(self):
|
||||
def test_task_result_no_error(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A celery task completed without error
|
||||
@@ -246,7 +246,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
self.assertEqual(returned_data["result"], "Success. New document id 1 created")
|
||||
self.assertEqual(returned_data["related_document"], "1")
|
||||
|
||||
def test_task_result_with_error(self):
|
||||
def test_task_result_with_error(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A celery task completed with an exception
|
||||
@@ -274,7 +274,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
"test.pdf: Unexpected error during ingestion.",
|
||||
)
|
||||
|
||||
def test_task_name_webui(self):
|
||||
def test_task_name_webui(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- Attempted celery task
|
||||
@@ -300,7 +300,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
|
||||
self.assertEqual(returned_data["task_file_name"], "test.pdf")
|
||||
|
||||
def test_task_name_consume_folder(self):
|
||||
def test_task_name_consume_folder(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- Attempted celery task
|
||||
@@ -326,7 +326,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
|
||||
self.assertEqual(returned_data["task_file_name"], "anothertest.pdf")
|
||||
|
||||
def test_task_result_duplicate_warning_includes_count(self):
|
||||
def test_task_result_duplicate_warning_includes_count(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A celery task succeeds, but a duplicate exists
|
||||
@@ -365,7 +365,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
|
||||
self.assertEqual(returned_data["related_document"], str(created_doc.pk))
|
||||
|
||||
def test_run_train_classifier_task(self):
|
||||
def test_run_train_classifier_task(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A superuser
|
||||
@@ -402,7 +402,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
mock_train_classifier.assert_called_once_with(scheduled=False)
|
||||
|
||||
@mock.patch("documents.tasks.sanity_check")
|
||||
def test_run_task_requires_superuser(self, mock_check_sanity):
|
||||
def test_run_task_requires_superuser(self, mock_check_sanity) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A regular user
|
||||
|
||||
Reference in New Issue
Block a user