Skip to content

Commit 9c0779b

Browse files
committed
Bypass current for former smoker
1 parent 7e265f4 commit 9c0779b

10 files changed

Lines changed: 93 additions & 9 deletions

features/smoked_amount.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Feature: Smoked amount page
44
Scenario: The page is accessible
55
Given I am logged in
66
And I have answered questions showing I am eligible
7+
And I have answered questions showing I have smoked for "10" years
78
And I have answered questions showing I currently smoke "Cigarettes"
89
And I have answered questions showing I have smoked "Cigarettes" daily
910
When I go to "/cigarettes-smoked-amount"
@@ -12,6 +13,7 @@ Feature: Smoked amount page
1213
Scenario: Form errors
1314
Given I am logged in
1415
And I have answered questions showing I am eligible
16+
And I have answered questions showing I have smoked for "10" years
1517
And I have answered questions showing I currently smoke "Cigarettes"
1618
And I have answered questions showing I have smoked "Cigarettes" daily
1719
When I go to "/cigarettes-smoked-amount"
@@ -23,6 +25,7 @@ Feature: Smoked amount page
2325
Scenario: Navigating backwards and forwards
2426
Given I am logged in
2527
And I have answered questions showing I am eligible
28+
And I have answered questions showing I have smoked for "10" years
2629
And I have answered questions showing I currently smoke "Cigarettes"
2730
And I have answered questions showing I have smoked "Cigarettes" daily
2831
When I go to "/cigarettes-smoked-amount"

features/smoking_change.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Feature: Smoking change page
33
Scenario: The page is accessible
44
Given I am logged in
55
And I have answered questions showing I am eligible
6+
And I have answered questions showing I have smoked for "10" years
67
And I have answered questions showing I currently smoke "Cigarettes"
78
And I have answered questions showing I have smoked 10 "Cigarettes" "daily"
89
When I go to "/cigarettes-smoking-change"
@@ -11,6 +12,7 @@ Feature: Smoking change page
1112
Scenario: Form errors
1213
Given I am logged in
1314
And I have answered questions showing I am eligible
15+
And I have answered questions showing I have smoked for "10" years
1416
And I have answered questions showing I currently smoke "Cigarettes"
1517
And I have answered questions showing I have smoked 10 "Cigarettes" "daily"
1618
When I go to "/cigarettes-smoking-change"
@@ -25,6 +27,7 @@ Feature: Smoking change page
2527
Scenario: Navigating backwards and forwards
2628
Given I am logged in
2729
And I have answered questions showing I am eligible
30+
And I have answered questions showing I have smoked for "10" years
2831
And I have answered questions showing I currently smoke "Cigarettes"
2932
And I have answered questions showing I have smoked 10 "Cigarettes" "daily"
3033
When I go to "/cigarettes-smoking-change"

features/smoking_current.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ Feature: Smoking current page
44
Scenario: The page is accessible
55
Given I am logged in
66
And I have answered questions showing I am eligible
7+
And I have answered questions showing I have smoked for "10" years
78
And I have answered questions showing I have smoked "Cigarettes"
89
When I go to "/cigarettes-smoking-current"
910
Then there are no accessibility violations
1011

1112
Scenario: Form errors
1213
Given I am logged in
1314
And I have answered questions showing I am eligible
15+
And I have answered questions showing I have smoked for "10" years
1416
And I have answered questions showing I have smoked "Cigarettes, Pipe"
1517
When I go to "/cigarettes-smoking-current"
1618
And I click "Continue"

features/smoking_frequency.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Feature: Smoking frequency page
44
Scenario: The page is accessible
55
Given I am logged in
66
And I have answered questions showing I am eligible
7+
And I have answered questions showing I have smoked for "10" years
78
And I have answered questions showing I have smoked "Cigarettes"
89
And I have answered questions showing I currently smoke "Cigarettes"
910
When I go to "/cigarettes-smoking-frequency"
@@ -12,6 +13,7 @@ Feature: Smoking frequency page
1213
Scenario: Form errors
1314
Given I am logged in
1415
And I have answered questions showing I am eligible
16+
And I have answered questions showing I have smoked for "10" years
1517
And I have answered questions showing I have smoked "Cigarettes"
1618
And I have answered questions showing I currently smoke "Cigarettes"
1719
When I go to "/cigarettes-smoking-frequency"
@@ -33,6 +35,7 @@ Feature: Smoking frequency page
3335
Scenario: When I say that I have increased the amount I smoke I am shown the correct page
3436
Given I am logged in
3537
And I have answered questions showing I am eligible
38+
And I have answered questions showing I have smoked for "10" years
3639
And I have answered questions showing I currently smoke "Cigarettes"
3740
And I have answered questions showing I have smoked 10 "Cigarettes" "daily"
3841
And I have answered questions showing I have "increased" my level of "Cigarettes" smoking from "10 cigarettes a day"

features/steps/navigation_steps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from behave import when, then
1+
from behave import when, then, step
22
from playwright.sync_api import expect
33

44

5-
@when('I go to "{path}"')
5+
@step('I go to "{path}"')
66
def given_i_go_to(context, path):
77
context.page.goto(f"{context.live_server_url}{path}")
88

features/steps/preflight_steps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ def given_i_have_answered_questions_showing_i_am_aged_60_years_old(context, year
9696
context.page.goto(f"{context.live_server_url}/date-of-birth")
9797
when_i_fill_in_and_submit_my_date_of_birth_as_x_years_ago(context, years)
9898

99+
@given("I have answered questions showing I quit smoking at \"{years}\" years old")
100+
def given_i_have_answered_questions_showing_i_quit_smoking_at_years_old(context, years):
101+
context.page.goto(f"{context.live_server_url}/when-you-quit-smoking")
102+
when_i_fill_in_label_with_value(context, "How old were you when you quit smoking?", years)
103+
when_i_submit_the_form(context)
99104

100105
@given('I have answered questions showing I stopped smoking for "{years}" years')
101106
def given_i_have_answered_questions_showing_i_stopped_smoking_for_years_years(context, years):

features/types_tobacco_smoking.feature

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Feature: Types tobacco smoking page
1818
And I see a form error "Select the type of tobacco you smoke or have smoked"
1919
And there are no accessibility violations
2020

21-
Scenario: Navigating backwards and forwards
21+
Scenario: Current smokers navigating backwards and forwards
2222
Given I am logged in
2323
And I have answered questions showing I am eligible
2424
And I have answered questions showing I have smoked for "10" years
@@ -35,6 +35,29 @@ Feature: Types tobacco smoking page
3535
Then I am on "/cigarettes-smoking-current"
3636
And I see a back link to "/types-tobacco-smoking"
3737

38+
Scenario: Former smokers navigating backwards and forwards
39+
Given I am logged in
40+
And I have answered questions showing I am eligible
41+
And I have answered questions showing I am aged "70" years old
42+
And I have answered questions showing I am a former smoker
43+
And I have answered questions showing I have smoked for "50" years
44+
And I have answered questions showing I quit smoking at "50" years old
45+
And I go to "/check-your-answers"
46+
And I take a screenshot
47+
When I go to "/types-tobacco-smoking"
48+
Then I see a back link to "/periods-when-you-stopped-smoking"
49+
When I check "Cigarettes"
50+
And I take a screenshot
51+
And I submit the form
52+
Then I am on "/cigarettes-smoking-frequency"
53+
When I click "Back"
54+
Then I am on "/types-tobacco-smoking"
55+
And I see "Cigarettes" selected
56+
When I check "Pipe"
57+
And I click "Continue"
58+
Then I am on "/cigarettes-smoked-total-years"
59+
And I see a back link to "/types-tobacco-smoking"
60+
3861
Scenario: Checking responses and changing them
3962
Given I am logged in
4063
And I have answered questions showing I am eligible

lung_cancer_screening/questions/tests/unit/views/test_types_tobacco_smoking.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ def test_redirects_when_the_user_is_not_eligible(self):
5555

5656

5757
def test_get_responds_successfully(self):
58-
ResponseSetFactory.create(user=self.user, eligible=True)
58+
response_set = ResponseSetFactory.create(user=self.user, eligible=True)
59+
60+
AgeWhenStartedSmokingResponseFactory.create(
61+
response_set=response_set,
62+
value=20
63+
)
5964

6065
response = self.client.get(
6166
reverse("questions:types_tobacco_smoking")
@@ -64,7 +69,12 @@ def test_get_responds_successfully(self):
6469
self.assertEqual(response.status_code, 200)
6570

6671
def test_get_back_link_url_returns_responses_url_if_changing_responses(self):
67-
ResponseSetFactory.create(user=self.user, eligible=True)
72+
response_set = ResponseSetFactory.create(user=self.user, eligible=True)
73+
74+
AgeWhenStartedSmokingResponseFactory.create(
75+
response_set=response_set,
76+
value=20
77+
)
6878

6979
response = self.client.get(
7080
reverse("questions:types_tobacco_smoking") + "?change=True"
@@ -76,7 +86,12 @@ def test_get_back_link_url_returns_responses_url_if_changing_responses(self):
7686
)
7787

7888
def test_get_back_link_url_returns_periods_when_you_stopped_smoking_url_if_not_changing_responses(self):
79-
ResponseSetFactory.create(user=self.user, eligible=True)
89+
response_set = ResponseSetFactory.create(user=self.user, eligible=True)
90+
91+
AgeWhenStartedSmokingResponseFactory.create(
92+
response_set=response_set,
93+
value=20
94+
)
8095

8196
response = self.client.get(
8297
reverse("questions:types_tobacco_smoking")
@@ -147,9 +162,15 @@ def test_creates_a_tobacco_smoking_type_parent_model_for_each_type_given(self):
147162
self.assertEqual(response_set.tobacco_smoking_history.count(), 1)
148163
self.assertEqual(response_set.tobacco_smoking_history.first().type, TobaccoSmokingHistoryTypes.CIGARETTES.value)
149164

150-
165+
@tag("wip")
151166
def test_post_redirects_to_the_current_of_first_type_of_tobacco_smoking_history_if_multiple_types_given(self):
152-
ResponseSetFactory.create(user=self.user, eligible=True)
167+
response_set = ResponseSetFactory.create(user=self.user, eligible=True)
168+
169+
AgeWhenStartedSmokingResponseFactory.create(
170+
response_set=response_set,
171+
value=20
172+
)
173+
153174
response = self.client.post(
154175
reverse("questions:types_tobacco_smoking"),
155176
{"value": [TobaccoSmokingHistoryTypes.CIGARETTES.value, TobaccoSmokingHistoryTypes.PIPE.value]}

lung_cancer_screening/questions/views/smoked_total_years.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def get_success_url(self):
8888

8989
def get_back_link_url(self):
9090
if self.tobacco_smoking_history_item().is_normal():
91+
if self.request.response_set.former_smoker():
92+
return reverse("questions:types_tobacco_smoking")
9193
return reverse(
9294
"questions:smoking_current",
9395
kwargs={"tobacco_type": self.kwargs["tobacco_type"]},

lung_cancer_screening/questions/views/types_tobacco_smoking.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.urls import reverse
2+
from django.shortcuts import redirect
23
from django.contrib.auth.mixins import LoginRequiredMixin
34
from django.views.generic.edit import FormView
45

@@ -7,8 +8,21 @@
78

89
from ..forms.types_tobacco_smoking_form import TypesTobaccoSmokingForm
910

11+
class EnsureReadyForTobaccoTypesMixin:
12+
def dispatch(self, request, *args, **kwargs):
13+
if (
14+
not hasattr(request.response_set, "age_when_started_smoking_response")
15+
):
16+
return redirect(reverse("questions:age_when_started_smoking"))
17+
if (
18+
not hasattr(request.response_set, "when_you_quit_smoking_response")
19+
and request.response_set.former_smoker()
20+
):
21+
return redirect(reverse("questions:when_you_quit_smoking"))
22+
23+
return super().dispatch(request, *args, **kwargs)
1024
class TypesTobaccoSmokingView(
11-
LoginRequiredMixin, EnsureResponseSet, EnsureEligibleMixin, FormView
25+
LoginRequiredMixin, EnsureResponseSet, EnsureEligibleMixin, EnsureReadyForTobaccoTypesMixin, FormView
1226
):
1327
template_name = "types_tobacco_smoking.jinja"
1428
form_class = TypesTobaccoSmokingForm
@@ -41,6 +55,14 @@ def get_success_url(self):
4155
"tobacco_type": next_tobacco_smoking_history.url_type()
4256
})
4357

58+
if self.request.response_set.former_smoker():
59+
return reverse(
60+
"questions:smoked_total_years",
61+
kwargs={
62+
"tobacco_type": next_tobacco_smoking_history.url_type()
63+
}
64+
)
65+
4466
return reverse(
4567
"questions:smoking_current",
4668
kwargs={

0 commit comments

Comments
 (0)