diff --git a/features/smoking_history.feature b/features/smoking_history.feature index f7168f25..711a93d8 100644 --- a/features/smoking_history.feature +++ b/features/smoking_history.feature @@ -386,7 +386,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 +419,102 @@ 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" + + # 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_smoked_total_years.py b/lung_cancer_screening/questions/tests/unit/views/test_smoked_total_years.py index 4742451f..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,7 +316,7 @@ def test_creates_a_smoked_total_years_response(self): ) - def test_redirects_to_frequency_by_default(self): + 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 +348,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, @@ -497,6 +497,70 @@ def test_redirects_to_next_question_forwarding_the_change_query_param(self): ) + 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( reverse("questions:smoked_total_years", kwargs = { 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..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 @@ -260,6 +260,31 @@ def test_redirects_to_the_next_question_given_level_decreased_only(self): })) + 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( reverse("questions:smoking_change", kwargs = { 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 [ 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",