From 3a34f8287ce3c3f8d45c40f7089c7c51d3f06057 Mon Sep 17 00:00:00 2001 From: Andy Mitchell <326561+Themitchell@users.noreply.github.com> Date: Thu, 26 Mar 2026 11:50:45 +0000 Subject: [PATCH 1/4] PPHA-602: Ensure change smoking history redirect to responses When coming to the end of a journey for a particular smoking history type make sure to redirect to responses if the participant is coming from the chekc your answeres page --- features/smoking_history.feature | 74 ++++++++++++++++- .../unit/views/test_smoked_total_years.py | 83 ++++++++++++++++++- .../questions/views/smoked_total_years.py | 15 ++-- 3 files changed, 161 insertions(+), 11 deletions(-) diff --git a/features/smoking_history.feature b/features/smoking_history.feature index f7168f25..710473d4 100644 --- a/features/smoking_history.feature +++ b/features/smoking_history.feature @@ -99,6 +99,7 @@ Feature: Smoking history pages And I see "40 cigarettes a day for 5 years" as a response to "When you smoked more than 25 cigarettes a month" under "Cigarette smoking history" + @wip Scenario: Multiple smoking histories Given I am logged in And I have answered questions showing I am eligible @@ -386,7 +387,7 @@ Feature: Smoking history pages And I see "2 cigarillos a month" as a response to "Current cigarillo smoking" under "Cigarillo smoking history" And I see "4 cigarillos a week for 3 years" as a response to "When you smoked more than 2 cigarillos a month" under "Cigarillo smoking history" - # Change cigarette smoking history + # Change cigarette smoking history with increased and decreased When I click the link to change "Cigarette" smoking history Then I am on "/cigarettes-smoking-current?change=True" @@ -419,9 +420,78 @@ Feature: Smoking history pages And I submit the form Then I am on "/cigarettes-smoked-increased-years?change=True" + When I submit the form - When I go to "/check-your-answers" + Then I am on "/cigarettes-smoking-decreased-frequency?change=True" + When I submit the form + + Then I am on "/cigarettes-smoked-decreased-amount?change=True" + When I submit the form + + Then I am on "/cigarettes-smoked-decreased-years?change=True" + When I submit the form + + Then I am on "/check-your-answers" Then I see "17 years" as a response to "Total number of years you smoked cigarettes" under "Cigarette smoking history" And I see "25 cigarettes a month" as a response to "Current cigarette smoking" under "Cigarette smoking history" And I see "40 cigarettes a day for 5 years" as a response to "When you smoked more than 25 cigarettes a month" under "Cigarette smoking history" + + # Change medium cigars with decreased + When I click the link to change "Medium cigar" smoking history + + Then I am on "/medium-cigars-smoking-current?change=True" + When I submit the form + + Then I am on "/medium-cigars-smoked-total-years?change=True" + When I submit the form + + Then I am on "/medium-cigars-smoking-frequency?change=True" + When I submit the form + + Then I am on "/medium-cigars-smoked-amount?change=True" + When I submit the form + + Then I am on "/medium-cigars-smoking-change?change=True" + When I submit the form + + Then I am on "/medium-cigars-smoking-decreased-frequency?change=True" + When I submit the form + + Then I am on "/medium-cigars-smoked-decreased-amount?change=True" + When I submit the form + + Then I am on "/medium-cigars-smoked-decreased-years?change=True" + When I submit the form + + Then I am on "/check-your-answers" + + # Change cigarillos with increased + When I click the link to change "Cigarillo" smoking history + + Then I am on "/cigarillos-smoking-current?change=True" + When I submit the form + + Then I am on "/cigarillos-smoked-total-years?change=True" + When I submit the form + + Then I am on "/cigarillos-smoking-frequency?change=True" + When I submit the form + + Then I am on "/cigarillos-smoked-amount?change=True" + When I submit the form + + Then I am on "/cigarillos-smoking-change?change=True" + When I submit the form + + Then I am on "/cigarillos-smoking-increased-frequency?change=True" + When I submit the form + + Then I am on "/cigarillos-smoked-increased-amount?change=True" + When I submit the form + + Then I am on "/cigarillos-smoked-increased-years?change=True" + When I submit the form + + Then I am on "/check-your-answers" + diff --git a/lung_cancer_screening/questions/tests/unit/views/test_smoked_total_years.py b/lung_cancer_screening/questions/tests/unit/views/test_smoked_total_years.py index 4742451f..b197a8f9 100644 --- a/lung_cancer_screening/questions/tests/unit/views/test_smoked_total_years.py +++ b/lung_cancer_screening/questions/tests/unit/views/test_smoked_total_years.py @@ -316,7 +316,22 @@ def test_creates_a_smoked_total_years_response(self): ) - def test_redirects_to_frequency_by_default(self): + # Normal level - frequency + # Increased level - no decreased level - responses + # Increased level - decreased level - decreased frequency + # increased level - no decreased level and change true - responses + # increased level - decreased level and change true - decreased frequency + # decreased level - no other type - responses + # decreased level - other type - total years next type + # decreased level - no other type and change true - responses + # decreased level - other type and change true - responses + + + + + + + def test_redirects_to_frequency_if_level_is_normal(self): response = self.client.post( reverse("questions:smoked_total_years", kwargs = { "tobacco_type": TobaccoSmokingHistoryTypes.CIGARETTES.value.lower() @@ -348,7 +363,7 @@ def test_redirects_to_responses_if_the_smoking_history_change_item_is_increased_ self.assertRedirects(response, reverse("questions:responses")) - def test_redirects_to_the_next_type_if_the_smoking_history_change_item_is_increased_and_there_is_another_type_of_tobacco_smoking_history(self): + def test_redirects_to_the_next_type_if_level_is_increased_and_there_is_another_type_of_tobacco_smoking_history(self): increased = TobaccoSmokingHistoryFactory.create( response_set=self.response_set, type=self.tobacco_smoking_history.type, @@ -496,6 +511,70 @@ def test_redirects_to_next_question_forwarding_the_change_query_param(self): fetch_redirect_response=False, ) + @tag("wip") + def test_redirects_to_responses_if_increased_level_and_change_true_and_no_decreased_and_another_type_exists(self): + self.tobacco_smoking_history.delete() + TobaccoSmokingHistoryFactory.create( + response_set=self.response_set, + small_cigars=True, + complete=True, + normal=True, + ) + normal = TobaccoSmokingHistoryFactory.create( + response_set=self.response_set, + cigarettes=True, + complete=True, + normal=True, + ) + increased = TobaccoSmokingHistoryFactory.create( + response_set=self.response_set, + type=normal.type, + complete=True, + increased=True, + ) + + response = self.client.post( + reverse("questions:smoked_total_years", kwargs = { + "tobacco_type": increased.url_type(), + "level": increased.level, + }), + {**self.valid_params, "change": "True"} + ) + + self.assertRedirects(response, reverse("questions:responses")) + + + def test_redirects_to_response_if_decreased_level_and_change_true_and_another_type_exists(self): + self.tobacco_smoking_history.delete() + TobaccoSmokingHistoryFactory.create( + response_set=self.response_set, + small_cigars=True, + complete=True, + normal=True, + ) + normal = TobaccoSmokingHistoryFactory.create( + response_set=self.response_set, + cigarettes=True, + complete=True, + normal=True, + ) + decreased = TobaccoSmokingHistoryFactory.create( + response_set=self.response_set, + type=normal.type, + complete=True, + decreased=True, + ) + + response = self.client.post( + reverse("questions:smoked_total_years", kwargs = { + "tobacco_type": decreased.url_type(), + "level": decreased.level, + }), + {**self.valid_params, "change": "True"} + ) + + self.assertRedirects(response, reverse("questions:responses")) + def test_responds_with_422_if_the_response_fails_to_create(self): response = self.client.post( diff --git a/lung_cancer_screening/questions/views/smoked_total_years.py b/lung_cancer_screening/questions/views/smoked_total_years.py index 33e39233..87b34e68 100644 --- a/lung_cancer_screening/questions/views/smoked_total_years.py +++ b/lung_cancer_screening/questions/views/smoked_total_years.py @@ -45,7 +45,14 @@ def get_context_data(self, **kwargs): return context + def has_decreased_level(self): + return self.request.response_set.tobacco_smoking_history.filter( + type=self.tobacco_smoking_history_item().type, + ).decreased().exists() + + def get_success_url(self): + # Total years is the first question of a normal smoking hitory if self.tobacco_smoking_history_item().is_normal(): return reverse( "questions:smoking_frequency", @@ -66,7 +73,7 @@ def get_success_url(self): query=self.get_change_query_params(), ) - if self.next_unanswered_history(): + if self.next_unanswered_history() and not self.should_redirect_to_responses(self.request): return reverse( "questions:smoking_current", kwargs={ @@ -93,12 +100,6 @@ def get_back_link_url(self): ) - def has_decreased_level(self): - return self.request.response_set.tobacco_smoking_history.filter( - type=self.tobacco_smoking_history_item().type, - ).decreased().exists() - - def prerequisite_responses(self): if self.tobacco_smoking_history_item().is_normal(): return [ From 389b286a4f08d937c0bc7186ba0dd5b29ae0686d Mon Sep 17 00:00:00 2001 From: Andy Mitchell <326561+Themitchell@users.noreply.github.com> Date: Thu, 26 Mar 2026 12:24:55 +0000 Subject: [PATCH 2/4] PPHA-602: Fix smoking no change redirect when changing responses --- features/smoking_history.feature | 24 ++++++++++++++++++ .../tests/unit/views/test_smoking_change.py | 25 +++++++++++++++++++ .../questions/views/smoking_change.py | 17 +++++++------ 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/features/smoking_history.feature b/features/smoking_history.feature index 710473d4..6be6bf1c 100644 --- a/features/smoking_history.feature +++ b/features/smoking_history.feature @@ -495,3 +495,27 @@ Feature: Smoking history pages Then I am on "/check-your-answers" + # Change cigarettes change to no change + When I click the link to change "Cigarette" smoking history + + Then I am on "/cigarettes-smoking-current?change=True" + When I submit the form + + Then I am on "/cigarettes-smoked-total-years?change=True" + When I submit the form + + Then I am on "/cigarettes-smoking-frequency?change=True" + When I submit the form + + Then I am on "/cigarettes-smoked-amount?change=True" + When I submit the form + + Then I am on "/cigarettes-smoking-change?change=True" + When I uncheck "Yes, I used to smoke more than 25 cigarettes a month" + And I uncheck "Yes, I used to smoke fewer than 25 cigarettes a month" + And I check "No, it has not changed" + When I submit the form + + Then I am on "/check-your-answers" + + diff --git a/lung_cancer_screening/questions/tests/unit/views/test_smoking_change.py b/lung_cancer_screening/questions/tests/unit/views/test_smoking_change.py index ede39c0e..ff1aa2ae 100644 --- a/lung_cancer_screening/questions/tests/unit/views/test_smoking_change.py +++ b/lung_cancer_screening/questions/tests/unit/views/test_smoking_change.py @@ -259,6 +259,31 @@ def test_redirects_to_the_next_question_given_level_decreased_only(self): "level": TobaccoSmokingHistory.Levels.DECREASED.value.lower() })) + @tag("wip") + def test_redirects_to_responses_if_change_true_and_no_change_is_selected_and_another_type_exists(self): + self.tobacco_smoking_history.delete() + TobaccoSmokingHistoryFactory.create( + response_set=self.response_set, + small_cigars=True, + complete=True, + normal=True, + ) + normal = TobaccoSmokingHistoryFactory.create( + response_set=self.response_set, + cigarettes=True, + complete=True, + normal=True, + ) + + response = self.client.post( + reverse("questions:smoking_change", kwargs = { + "tobacco_type": normal.url_type() + }), + {"value": [TobaccoSmokingHistory.Levels.NO_CHANGE], "change": "True"} + ) + + self.assertRedirects(response, reverse("questions:responses")) + def test_creates_a_smoking_change_response(self): self.client.post( diff --git a/lung_cancer_screening/questions/views/smoking_change.py b/lung_cancer_screening/questions/views/smoking_change.py index cdb9f3f4..6249e97e 100644 --- a/lung_cancer_screening/questions/views/smoking_change.py +++ b/lung_cancer_screening/questions/views/smoking_change.py @@ -59,13 +59,16 @@ def form_valid(self, form): def get_success_url(self): if self.next_smoking_history(): if self.next_smoking_history().is_normal(): - return reverse( - "questions:smoking_current", - kwargs={ - "tobacco_type": self.next_smoking_history().url_type(), - }, - query=self.get_change_query_params(), - ) + if self.should_redirect_to_responses(self.request): + return reverse("questions:responses") + else: + return reverse( + "questions:smoking_current", + kwargs={ + "tobacco_type": self.next_smoking_history().url_type(), + }, + query=self.get_change_query_params(), + ) else: return reverse( "questions:smoking_frequency", From cf1406ca72ff0c58155a325baf320bfdb6200311 Mon Sep 17 00:00:00 2001 From: stephhou Date: Fri, 27 Mar 2026 17:47:41 +0000 Subject: [PATCH 3/4] fix:removed wip tag --- features/smoking_history.feature | 1 - 1 file changed, 1 deletion(-) diff --git a/features/smoking_history.feature b/features/smoking_history.feature index 6be6bf1c..711a93d8 100644 --- a/features/smoking_history.feature +++ b/features/smoking_history.feature @@ -99,7 +99,6 @@ Feature: Smoking history pages And I see "40 cigarettes a day for 5 years" as a response to "When you smoked more than 25 cigarettes a month" under "Cigarette smoking history" - @wip Scenario: Multiple smoking histories Given I am logged in And I have answered questions showing I am eligible From 611911e61ef7cef5e0d6cc9d134bb6d05b6696c7 Mon Sep 17 00:00:00 2001 From: Andy Mitchell <326561+Themitchell@users.noreply.github.com> Date: Thu, 26 Mar 2026 12:24:55 +0000 Subject: [PATCH 4/4] PPHA-602: Fix smoking no change redirect when changing responses --- .../tests/unit/views/test_smoked_total_years.py | 17 +---------------- .../tests/unit/views/test_smoking_change.py | 2 +- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/lung_cancer_screening/questions/tests/unit/views/test_smoked_total_years.py b/lung_cancer_screening/questions/tests/unit/views/test_smoked_total_years.py index b197a8f9..4c9f4050 100644 --- a/lung_cancer_screening/questions/tests/unit/views/test_smoked_total_years.py +++ b/lung_cancer_screening/questions/tests/unit/views/test_smoked_total_years.py @@ -316,21 +316,6 @@ def test_creates_a_smoked_total_years_response(self): ) - # Normal level - frequency - # Increased level - no decreased level - responses - # Increased level - decreased level - decreased frequency - # increased level - no decreased level and change true - responses - # increased level - decreased level and change true - decreased frequency - # decreased level - no other type - responses - # decreased level - other type - total years next type - # decreased level - no other type and change true - responses - # decreased level - other type and change true - responses - - - - - - def test_redirects_to_frequency_if_level_is_normal(self): response = self.client.post( reverse("questions:smoked_total_years", kwargs = { @@ -511,7 +496,7 @@ def test_redirects_to_next_question_forwarding_the_change_query_param(self): fetch_redirect_response=False, ) - @tag("wip") + def test_redirects_to_responses_if_increased_level_and_change_true_and_no_decreased_and_another_type_exists(self): self.tobacco_smoking_history.delete() TobaccoSmokingHistoryFactory.create( diff --git a/lung_cancer_screening/questions/tests/unit/views/test_smoking_change.py b/lung_cancer_screening/questions/tests/unit/views/test_smoking_change.py index ff1aa2ae..d3c37d58 100644 --- a/lung_cancer_screening/questions/tests/unit/views/test_smoking_change.py +++ b/lung_cancer_screening/questions/tests/unit/views/test_smoking_change.py @@ -259,7 +259,7 @@ def test_redirects_to_the_next_question_given_level_decreased_only(self): "level": TobaccoSmokingHistory.Levels.DECREASED.value.lower() })) - @tag("wip") + def test_redirects_to_responses_if_change_true_and_no_change_is_selected_and_another_type_exists(self): self.tobacco_smoking_history.delete() TobaccoSmokingHistoryFactory.create(