From 7d61b981b3fdbd8ab37bfed6cec1405fd4eeff2f Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 13 Oct 2026 13:26:16 -0700 Subject: [PATCH] Add/update tests --- src/documents/tests/test_api_bulk_edit.py | 3 +- src/documents/tests/test_api_search.py | 62 ++++++++++++++++++++++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/documents/tests/test_api_bulk_edit.py b/src/documents/tests/test_api_bulk_edit.py index 9c7ba3db8..208657564 100644 --- a/src/documents/tests/test_api_bulk_edit.py +++ b/src/documents/tests/test_api_bulk_edit.py @@ -835,6 +835,7 @@ class TestBulkEditAPI(DirectoriesMixin, APITestCase): for filters in ( {"text": "new doc 2017-03-16"}, {"title_search": "apple"}, + {"title_search": "apple", "query": "created:[-1 year to now]"}, ): with self.subTest(filters=filters): get_backend.return_value.search_ids.return_value = [self.doc2.id] @@ -886,7 +887,7 @@ class TestBulkEditAPI(DirectoriesMixin, APITestCase): "all": True, "filters": { "text": "B", - "query": "c1", + "title_search": "c1", }, "method": "set_storage_path", "parameters": {"storage_path": self.sp1.id}, diff --git a/src/documents/tests/test_api_search.py b/src/documents/tests/test_api_search.py index 0b7e4961b..d7a07f5ed 100644 --- a/src/documents/tests/test_api_search.py +++ b/src/documents/tests/test_api_search.py @@ -245,8 +245,68 @@ class TestDocumentSearchApi(DirectoriesMixin, APITestCase): self.assertEqual(response.data["count"], 1) self.assertEqual(response.data["results"][0]["id"], title_match.id) + def test_simple_search_combined_with_query_filter(self) -> None: + """ + GIVEN: + - A document with the term in its title, created this year + - A document with the term only in its content, created this year + - A document with the term in its title, created years ago + WHEN: + - A title or text search is combined with a relative created + date query, as the filter editor sends it + THEN: + - The simple search keeps its own field scope and the query only + narrows the results (issue #14436) + """ + this_year = timezone.localdate().replace(month=1, day=1) + title_match = Document.objects.create( + title="foo report", + content="nothing relevant", + checksum="F1", + created=this_year, + pk=21, + ) + content_match = Document.objects.create( + title="something else", + content="foo appears here", + checksum="F2", + created=this_year, + pk=22, + ) + old_title_match = Document.objects.create( + title="foo archive", + content="nothing relevant", + checksum="F3", + created=datetime.date(2001, 1, 1), + pk=23, + ) + backend = get_backend() + for doc in (title_match, content_match, old_title_match): + backend.add_or_update(doc) + + query = "created:[-1 year to now]" + response = self.client.get( + "/api/documents/", + {"title_search": "foo", "query": query}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual( + [r["id"] for r in response.data["results"]], + [title_match.id], + ) + + response = self.client.get( + "/api/documents/", + {"text": "foo", "query": query}, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertCountEqual( + [r["id"] for r in response.data["results"]], + [title_match.id, content_match.id], + ) + def test_search_rejects_multiple_search_modes(self) -> None: - response = self.client.get("/api/documents/?text=bank&query=bank") + response = self.client.get("/api/documents/?text=bank&title_search=bank") self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data["detail"],