From dddf3df6dfa390df57c1143a8aa98287d085546b Mon Sep 17 00:00:00 2001 From: Maxim Loginov Date: Sun, 30 Oct 2022 09:47:56 +0700 Subject: [PATCH] fix Pierre-Sassoulas/django-survey#134 with test The code is taken from Pierre-Sassoulas/django-survey#168, the test is based on fixture from Pierre-Sassoulas/django-survey#177. --- survey/templates/survey/question.html | 2 +- survey/tests/views/test_survey_category.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/survey/templates/survey/question.html b/survey/templates/survey/question.html index 69fc0ef6..37265ee7 100644 --- a/survey/templates/survey/question.html +++ b/survey/templates/survey/question.html @@ -9,7 +9,7 @@ --> {% for form in response_form %} - {% if form.field.widget.attrs.category == category.name or not form.field.widget.attrs.category %} + {% if form.field.widget.attrs.category == category.name or category.name == 'No category' and not form.field.widget.attrs.category %} {{ form.label|safe }} diff --git a/survey/tests/views/test_survey_category.py b/survey/tests/views/test_survey_category.py index a6bc7aa4..093757fd 100644 --- a/survey/tests/views/test_survey_category.py +++ b/survey/tests/views/test_survey_category.py @@ -14,3 +14,12 @@ def test_category_description_none_not_shown(self): """ response = self.client.get(reverse("survey-detail", args=(13,))) self.assertNotContains(response, "None") + + def test_without_category_not_duplicated(self): + """ + Checks that question without category is not duplicated when there is + a question with category in the same survey. + + """ + response = self.client.get(reverse("survey-detail", args=(13,))) + self.assertContains(response, "Question without category", count=1)