From a9505657720e0617dc744a314379d2512fb8b3e0 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 7 Aug 2025 12:49:17 +0200 Subject: 🐛 searches: fix exact date searches for datetime fields (refs #6411) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- archaeological_operations/tests.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'archaeological_operations/tests.py') diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 8baf02727..caadbc94f 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -3315,6 +3315,28 @@ class OperationSearchTest(TestCase, OperationInitTest, SearchText): ] self._test_search(c, result, context="Boolean search") + # date searches + search_created_q = str(pgettext("key for text search", "created")) + today = datetime.date.today().strftime('%Y-%m-%d') + result = [ + (f'{search_created_q}="{today}"', len(self.operations)), + ] + self._test_search(c, result, context="Exact date search") + yesterday = (datetime.date.today() - datetime.timedelta(days=1)).strftime('%Y-%m-%d') + result = [ + (f'{search_created_q}="{yesterday}"', 0), + ] + self._test_search(c, result, context="Exact date search - no match") + result = [ + (f'{search_created_q}=>"{yesterday}"', len(self.operations)), + ] + self._test_search(c, result, context="After date search") + tomorrow = (datetime.date.today() + datetime.timedelta(days=1)).strftime('%Y-%m-%d') + result = [ + (f'{search_created_q}=<"{tomorrow}"', len(self.operations)), + ] + self._test_search(c, result, context="Before date search") + def test_mixed_search_vector(self): operation_1 = models.Operation.objects.get(pk=self.operations[0].pk) operation_1.common_name = "Opération : Château de Fougères" -- cgit v1.2.3