Skip to content

Commit

Permalink
Merge pull request #458 from maykinmedia/issue-1073-productfinder-no-…
Browse files Browse the repository at this point in the history
…conditions

[#1073] Fix/handle product finder empty conditions
  • Loading branch information
alextreme authored Feb 7, 2023
2 parents d59119f + f391a27 commit 6dbe49d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/open_inwoner/pdc/tests/test_product_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from open_inwoner.accounts.tests.factories import UserFactory

from ..models import ProductCondition
from .factories import ProductConditionFactory, ProductFactory


Expand Down Expand Up @@ -1547,3 +1548,21 @@ def test_q1_no_q2_no_q3_no_q4_no(self):
self.assertIn(self.product11, possible_products)
self.assertNotIn(self.product12, matched_products)
self.assertIn(self.product12, possible_products)

def test_product_finder_is_reset_when_no_condition(self):
response = self.app.get(reverse("pdc:product_finder"))
form = response.forms["product-finder"]

ProductCondition.objects.all().delete()

form["answer"].value = "yes"
response = form.submit()

self.assertRedirects(response, reverse("pdc:product_finder"))

session = self.app.session
response.follow()

self.assertEqual(session["product_finder"], {})
self.assertIsNone(session["current_condition"])
self.assertFalse(session["conditions_done"])
7 changes: 7 additions & 0 deletions src/open_inwoner/pdc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ def get_context_data(self, **kwargs):
return context

def form_valid(self, form):
# redirect user to reset product finder if no conditions exist
if not self.condition:
self.request.session["product_finder"] = {}
self.request.session["current_condition"] = None
self.request.session["conditions_done"] = False
return HttpResponseRedirect(self.get_success_url())

self.set_product_condition_sessions(form.cleaned_data.get("answer"))
next_condition = self.get_next_condition()
if next_condition:
Expand Down

0 comments on commit 6dbe49d

Please sign in to comment.