From 4017d87c392c3946d3d4cd83d8f0ce1a6a56d6bb Mon Sep 17 00:00:00 2001 From: Wyatt Pearsall Date: Thu, 19 Dec 2024 09:27:38 -0800 Subject: [PATCH 1/3] Return an empty list for tccp situations when invalid data gets cleaned --- cfgov/tccp/tests/test_views.py | 4 ++++ cfgov/tccp/views.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cfgov/tccp/tests/test_views.py b/cfgov/tccp/tests/test_views.py index adbdfba1481..48967e1dc01 100644 --- a/cfgov/tccp/tests/test_views.py +++ b/cfgov/tccp/tests/test_views.py @@ -23,6 +23,10 @@ def test_basic_get(self): response = self.make_request() self.assertEqual(response.status_code, 200) + def test_invalid_situations(self): + response = self.make_request("?situations=fake+and+bad") + self.assertEqual(response.status_code, 200) + def test_situation_redirect(self): tier = "Credit scores from 620 to 719" diff --git a/cfgov/tccp/views.py b/cfgov/tccp/views.py index 7645ebac201..e8a281ac15a 100644 --- a/cfgov/tccp/views.py +++ b/cfgov/tccp/views.py @@ -145,7 +145,7 @@ def list(self, request, *args, **kwargs): # If we're rendering HTML, we need to augment the response context. if render_format == "html": form = filter_backend.used_filterset.form - situations = form.cleaned_data["situations"] + situations = form.cleaned_data.get("situations", []) purchase_apr_rating_ranges = self.get_purchase_apr_rating_ranges( cards From 0842377e40c668245661193f7649b666eda1732b Mon Sep 17 00:00:00 2001 From: Wyatt Pearsall Date: Thu, 19 Dec 2024 12:53:09 -0500 Subject: [PATCH 2/3] Update cfgov/tccp/tests/test_views.py Co-authored-by: Andy Chosak --- cfgov/tccp/tests/test_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfgov/tccp/tests/test_views.py b/cfgov/tccp/tests/test_views.py index 48967e1dc01..f0a8b6c7370 100644 --- a/cfgov/tccp/tests/test_views.py +++ b/cfgov/tccp/tests/test_views.py @@ -25,7 +25,7 @@ def test_basic_get(self): def test_invalid_situations(self): response = self.make_request("?situations=fake+and+bad") - self.assertEqual(response.status_code, 200) + self.assertContains(response, "There are no results for your search.") def test_situation_redirect(self): tier = "Credit scores from 620 to 719" From 6dafc58576c0188d35338e8cc8959e0a07317ca9 Mon Sep 17 00:00:00 2001 From: Wyatt Pearsall Date: Thu, 19 Dec 2024 10:44:18 -0800 Subject: [PATCH 3/3] Move invalid situations test to card list view --- cfgov/tccp/tests/test_views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cfgov/tccp/tests/test_views.py b/cfgov/tccp/tests/test_views.py index f0a8b6c7370..ac4c1d81d73 100644 --- a/cfgov/tccp/tests/test_views.py +++ b/cfgov/tccp/tests/test_views.py @@ -23,10 +23,6 @@ def test_basic_get(self): response = self.make_request() self.assertEqual(response.status_code, 200) - def test_invalid_situations(self): - response = self.make_request("?situations=fake+and+bad") - self.assertContains(response, "There are no results for your search.") - def test_situation_redirect(self): tier = "Credit scores from 620 to 719" @@ -88,6 +84,10 @@ def test_no_querystring_filters_by_good_tier(self): self.assertContains(response, "Consumer Financial Protection Bureau") self.assertContains(response, "There are no results for your search.") + def test_invalid_situations(self): + response = self.make_request("?situations=fake+and+bad") + self.assertContains(response, "There are no results for your search.") + def test_htmx_includes_only_results(self): response = self.make_request(**{"HTTP_HX-Request": "true"}) self.assertNotContains(