mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-07 03:13:19 +00:00
Chore(mypy): Annotate None returns for typing improvements (#11213)
This commit is contained in:
@@ -35,12 +35,12 @@ class TestViews(DirectoriesMixin, TestCase):
|
||||
self.user = User.objects.create_user("testuser")
|
||||
super().setUp()
|
||||
|
||||
def test_login_redirect(self):
|
||||
def test_login_redirect(self) -> None:
|
||||
response = self.client.get("/")
|
||||
self.assertEqual(response.status_code, status.HTTP_302_FOUND)
|
||||
self.assertEqual(response.url, "/accounts/login/?next=/")
|
||||
|
||||
def test_index(self):
|
||||
def test_index(self) -> None:
|
||||
self.client.force_login(self.user)
|
||||
for language_given, language_actual in [
|
||||
("", "en-US"),
|
||||
@@ -84,7 +84,7 @@ class TestViews(DirectoriesMixin, TestCase):
|
||||
)
|
||||
|
||||
@override_settings(BASE_URL="/paperless/")
|
||||
def test_index_app_logo_with_base_url(self):
|
||||
def test_index_app_logo_with_base_url(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- Existing config with app_logo specified
|
||||
@@ -103,7 +103,7 @@ class TestViews(DirectoriesMixin, TestCase):
|
||||
f"/paperless{config.app_logo}",
|
||||
)
|
||||
|
||||
def test_share_link_views(self):
|
||||
def test_share_link_views(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- Share link created
|
||||
@@ -169,7 +169,7 @@ class TestViews(DirectoriesMixin, TestCase):
|
||||
self.assertEqual(response.request["PATH_INFO"], "/accounts/login/")
|
||||
self.assertContains(response, b"Share link has expired")
|
||||
|
||||
def test_list_with_full_permissions(self):
|
||||
def test_list_with_full_permissions(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- Tags with different permissions
|
||||
@@ -238,7 +238,7 @@ class TestViews(DirectoriesMixin, TestCase):
|
||||
else:
|
||||
assert False, f"Unexpected tag found: {tag['name']}"
|
||||
|
||||
def test_list_no_n_plus_1_queries(self):
|
||||
def test_list_no_n_plus_1_queries(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- Tags with different permissions
|
||||
@@ -281,7 +281,7 @@ class TestViews(DirectoriesMixin, TestCase):
|
||||
|
||||
|
||||
class TestAISuggestions(DirectoriesMixin, TestCase):
|
||||
def setUp(self):
|
||||
def setUp(self) -> None:
|
||||
self.user = User.objects.create_superuser(username="testuser")
|
||||
self.document = Document.objects.create(
|
||||
title="Test Document",
|
||||
@@ -300,7 +300,11 @@ class TestAISuggestions(DirectoriesMixin, TestCase):
|
||||
AI_ENABLED=True,
|
||||
LLM_BACKEND="mock_backend",
|
||||
)
|
||||
def test_suggestions_with_cached_llm(self, mock_refresh_cache, mock_get_cache):
|
||||
def test_suggestions_with_cached_llm(
|
||||
self,
|
||||
mock_refresh_cache,
|
||||
mock_get_cache,
|
||||
) -> None:
|
||||
mock_get_cache.return_value = MagicMock(suggestions={"tags": ["tag1", "tag2"]})
|
||||
|
||||
self.client.force_login(user=self.user)
|
||||
@@ -317,7 +321,7 @@ class TestAISuggestions(DirectoriesMixin, TestCase):
|
||||
def test_suggestions_with_ai_enabled(
|
||||
self,
|
||||
mock_get_ai_classification,
|
||||
):
|
||||
) -> None:
|
||||
mock_get_ai_classification.return_value = {
|
||||
"title": "AI Title",
|
||||
"tags": ["tag1", "tag2"],
|
||||
@@ -346,7 +350,7 @@ class TestAISuggestions(DirectoriesMixin, TestCase):
|
||||
},
|
||||
)
|
||||
|
||||
def test_invalidate_suggestions_cache(self):
|
||||
def test_invalidate_suggestions_cache(self) -> None:
|
||||
self.client.force_login(user=self.user)
|
||||
suggestions = {
|
||||
"title": "AI Title",
|
||||
@@ -384,7 +388,7 @@ class TestAISuggestions(DirectoriesMixin, TestCase):
|
||||
class TestAIChatStreamingView(DirectoriesMixin, TestCase):
|
||||
ENDPOINT = "/api/documents/chat/"
|
||||
|
||||
def setUp(self):
|
||||
def setUp(self) -> None:
|
||||
self.user = User.objects.create_user(username="testuser", password="pass")
|
||||
self.client.force_login(user=self.user)
|
||||
self.document = Document.objects.create(
|
||||
@@ -395,7 +399,7 @@ class TestAIChatStreamingView(DirectoriesMixin, TestCase):
|
||||
super().setUp()
|
||||
|
||||
@override_settings(AI_ENABLED=False)
|
||||
def test_post_ai_disabled(self):
|
||||
def test_post_ai_disabled(self) -> None:
|
||||
response = self.client.post(
|
||||
self.ENDPOINT,
|
||||
data='{"q": "question"}',
|
||||
@@ -407,7 +411,7 @@ class TestAIChatStreamingView(DirectoriesMixin, TestCase):
|
||||
@patch("documents.views.stream_chat_with_documents")
|
||||
@patch("documents.views.get_objects_for_user_owner_aware")
|
||||
@override_settings(AI_ENABLED=True)
|
||||
def test_post_no_document_id(self, mock_get_objects, mock_stream_chat):
|
||||
def test_post_no_document_id(self, mock_get_objects, mock_stream_chat) -> None:
|
||||
mock_get_objects.return_value = [self.document]
|
||||
mock_stream_chat.return_value = iter([b"data"])
|
||||
response = self.client.post(
|
||||
@@ -420,7 +424,7 @@ class TestAIChatStreamingView(DirectoriesMixin, TestCase):
|
||||
|
||||
@patch("documents.views.stream_chat_with_documents")
|
||||
@override_settings(AI_ENABLED=True)
|
||||
def test_post_with_document_id(self, mock_stream_chat):
|
||||
def test_post_with_document_id(self, mock_stream_chat) -> None:
|
||||
mock_stream_chat.return_value = iter([b"data"])
|
||||
response = self.client.post(
|
||||
self.ENDPOINT,
|
||||
@@ -431,7 +435,7 @@ class TestAIChatStreamingView(DirectoriesMixin, TestCase):
|
||||
self.assertEqual(response["Content-Type"], "text/event-stream")
|
||||
|
||||
@override_settings(AI_ENABLED=True)
|
||||
def test_post_with_invalid_document_id(self):
|
||||
def test_post_with_invalid_document_id(self) -> None:
|
||||
response = self.client.post(
|
||||
self.ENDPOINT,
|
||||
data='{"q": "question", "document_id": 999999}',
|
||||
@@ -442,7 +446,7 @@ class TestAIChatStreamingView(DirectoriesMixin, TestCase):
|
||||
|
||||
@patch("documents.views.has_perms_owner_aware")
|
||||
@override_settings(AI_ENABLED=True)
|
||||
def test_post_with_document_id_no_permission(self, mock_has_perms):
|
||||
def test_post_with_document_id_no_permission(self, mock_has_perms) -> None:
|
||||
mock_has_perms.return_value = False
|
||||
response = self.client.post(
|
||||
self.ENDPOINT,
|
||||
|
||||
Reference in New Issue
Block a user