Change created_at filter param to hit_date in search terms report view

pull/11202/head
Sage Abdullah 2024-11-28 12:30:05 +00:00 zatwierdzone przez Matt Westcott
rodzic 9a1c7126e2
commit 789a0c2572
2 zmienionych plików z 23 dodań i 2 usunięć
wagtail/contrib/search_promotions

Wyświetl plik

@ -1037,7 +1037,8 @@ class TestFilteredQueryHitsView(BaseReportViewTestCase):
def setUp(self):
self.user = self.login()
self.query_hit = Query.get("This will be found")
self.query_hit.add_hit(timezone.now())
self.date = timezone.now().date()
self.query_hit.add_hit(date=self.date)
def test_search_by_query_string(self):
response = self.get(params={"q": "Found"})
@ -1051,3 +1052,23 @@ class TestFilteredQueryHitsView(BaseReportViewTestCase):
self.assertContains(response, "There are no results.")
self.assertNotContains(response, "this will be found")
self.assertActiveFilterNotRendered(self.get_soup(response.content))
def test_filter_by_date(self):
params = {
"hit_date_from": self.date.replace(day=1, month=1),
}
response = self.get(params=params)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "this will be found")
self.assertNotContains(response, "There are no results.")
self.assertActiveFilter(
self.get_soup(response.content), "hit_date_from", params["hit_date_from"]
)
params["hit_date_from"] = self.date.replace(year=self.date.year + 1)
params["hit_date_to"] = self.date.replace(year=self.date.year + 2)
response = self.get(params=params)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "There are no results.")
self.assertNotContains(response, "this will be found")

Wyświetl plik

@ -9,7 +9,7 @@ from wagtail.contrib.search_promotions.models import Query
class SearchTermsReportFilterSet(WagtailFilterSet):
created_at = DateFromToRangeFilter(
hit_date = DateFromToRangeFilter(
label=_("Date"),
field_name="daily_hits__date",
widget=DateRangePickerWidget,