-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpreflight_steps.py
More file actions
179 lines (146 loc) · 8.34 KB
/
preflight_steps.py
File metadata and controls
179 lines (146 loc) · 8.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
from behave import given
from inflection import humanize
from features.steps.debug_steps import screenshot
from features.steps.form_steps import (
when_i_fill_in_and_submit_my_date_of_birth_as_x_years_ago,
when_i_submit_the_form,
when_i_check_label,
when_i_fill_in_label_with_value
)
from lung_cancer_screening.questions.models.tobacco_smoking_history import TobaccoSmokingHistory
from lung_cancer_screening.questions.tests.factories.have_you_ever_smoked_response_factory import (
ResponseSetFactory,
)
from lung_cancer_screening.questions.tests.factories.have_you_ever_smoked_response_factory import (
HaveYouEverSmokedResponseFactory,
)
from lung_cancer_screening.questions.tests.factories.date_of_birth_response_factory import (
DateOfBirthResponseFactory,
)
from lung_cancer_screening.questions.tests.factories.age_when_started_smoking_response_factory import (
AgeWhenStartedSmokingResponseFactory,
)
from lung_cancer_screening.questions.tests.factories.terms_of_use_response_factory import TermsOfUseResponseFactory
def get_or_create_response_set(context):
return (
context.current_user.most_recent_response_set()
or ResponseSetFactory.create(
user=context.current_user,
)
)
@given("I have answered questions showing I have accepted the terms of use")
def given_i_have_answered_questions_showing_i_have_accepted_the_terms_of_use(context):
response_set = get_or_create_response_set(context)
TermsOfUseResponseFactory.create(
response_set=response_set,
value=True,
)
@given('I have answered have you ever smoked with an eligible response')
def given_i_have_answered_have_your_ever_smoked_with_an_eligible_response(context):
response_set = get_or_create_response_set(context)
HaveYouEverSmokedResponseFactory.create(
response_set=response_set,
eligible=True,
)
@given('I have answered date of birth with an eligible date of birth')
def given_i_have_answered_date_of_birth_with_an_eligible_date_of_birth(context):
response_set = get_or_create_response_set(context)
DateOfBirthResponseFactory.create(
response_set=response_set,
eligible=True,
)
@given("I have answered questions showing I am eligible")
def given_i_have_answered_questions_showing_i_am_eligible(context):
ResponseSetFactory.create(
user=context.current_user,
eligible=True,
)
@given("I have answered questions showing I am a {current_or_former} smoker")
def given_i_have_answered_questions_showing_i_am_a_current_smoker(context, current_or_former):
context.page.goto(f"{context.live_server_url}/have-you-ever-smoked")
if current_or_former == "current":
when_i_check_label(context, "Yes, I currently smoke")
elif current_or_former == "former":
when_i_check_label(context, "Yes, I used to smoke")
else:
raise ValueError(f"Invalid current_or_former: {current_or_former}")
when_i_submit_the_form(context)
@given('I have answered questions showing I started smoking "{years}" years ago')
@given('I have answered questions showing I have smoked for "{years}" years')
def given_i_have_answered_questions_showing_i_have_smoked_for_years_years(context, years):
response_set = get_or_create_response_set(context)
AgeWhenStartedSmokingResponseFactory.create(
response_set=response_set,
value=response_set.date_of_birth_response.age_in_years() - int(years),
)
@given('I have answered questions showing I am aged "{years}" years old')
def given_i_have_answered_questions_showing_i_am_aged_60_years_old(context, years):
context.page.goto(f"{context.live_server_url}/date-of-birth")
when_i_fill_in_and_submit_my_date_of_birth_as_x_years_ago(context, years)
@given("I have answered questions showing I quit smoking at \"{years}\" years old")
def given_i_have_answered_questions_showing_i_quit_smoking_at_years_old(context, years):
context.page.goto(f"{context.live_server_url}/when-you-quit-smoking")
when_i_fill_in_label_with_value(context, "How old were you when you quit smoking?", years)
when_i_submit_the_form(context)
@given('I have answered questions showing I stopped smoking for "{years}" years')
def given_i_have_answered_questions_showing_i_stopped_smoking_for_years_years(context, years):
context.page.goto(f"{context.live_server_url}/periods-when-you-stopped-smoking")
when_i_check_label(context, "Yes")
when_i_fill_in_label_with_value(context, "Enter the total number of years you stopped smoking", years)
when_i_submit_the_form(context)
@given('I have answered questions showing I have smoked "{tobacco_types}"')
def given_i_have_answered_questions_showing_i_have_smoked_tobacco_type(
context, tobacco_types
):
context.page.goto(f"{context.live_server_url}/types-tobacco-smoking")
for tobacco_type in tobacco_types.split(","):
when_i_check_label(context, tobacco_type.strip())
when_i_submit_the_form(context)
@given('I have answered questions showing I currently smoke "{tobacco_type}"')
def given_i_have_answered_questions_showing_i_currently_smoke_tobacco_type(context, tobacco_type):
given_i_have_answered_questions_showing_i_have_smoked_tobacco_type(
context, tobacco_type
)
context.page.goto(
f"{context.live_server_url}/{tobacco_type.lower()}-smoking-current"
)
when_i_check_label(context, "Yes")
when_i_submit_the_form(context)
@given('I have answered questions showing I have smoked "{tobacco_type}" {frequency}')
def given_i_have_answered_questions_showing_i_have_smoked_tobacco_type_frequency(context, tobacco_type, frequency):
given_i_have_answered_questions_showing_i_have_smoked_tobacco_type(context, tobacco_type)
context.page.goto(f"{context.live_server_url}/{tobacco_type.lower()}-smoking-frequency")
when_i_check_label(context, humanize(frequency))
when_i_submit_the_form(context)
@given('I have answered questions showing I have smoked {amount} "{tobacco_type}" "{frequency}"')
def i_have_answered_questions_showing_i_have_smoked_amount_tobacco_type_frequency(context, amount, tobacco_type, frequency):
given_i_have_answered_questions_showing_i_have_smoked_tobacco_type_frequency(context, tobacco_type, frequency)
given_i_have_answered_questions_showing_i_have_smoked_amount_tobacco_type(context, amount, tobacco_type)
@given('I have answered questions showing I have smoked {amount} "{tobacco_type}" as the amount')
def given_i_have_answered_questions_showing_i_have_smoked_amount_tobacco_type(context, amount, tobacco_type):
context.page.goto(f"{context.live_server_url}/{tobacco_type.lower()}-smoked-amount")
when_i_fill_in_label_with_value(context, f"Roughly how many {tobacco_type.lower()} do you currently smoke in a normal day?", amount)
when_i_submit_the_form(context)
@given('I have answered questions showing I have "{level}" my level of "{tobacco_type}" smoking from "{previous_level}"')
def given_i_have_answered_questions_showing_i_have_level_of_smoking(context, level, tobacco_type, previous_level):
context.page.goto(f"{context.live_server_url}/{tobacco_type.lower()}-smoking-change")
when_i_check_label(context, f"{TobaccoSmokingHistory.Levels[level.upper()].label} than {previous_level.lower()}")
when_i_submit_the_form(context)
@given('I have answered questions showing I have "{level}" my frequency of "{tobacco_type}" smoking to "{frequency}"')
def given_i_have_answered_questions_showing_i_have_changed_frequency_of_smoked_tobacco_type(
context, level, tobacco_type, frequency
):
given_i_have_answered_questions_showing_i_have_smoked_tobacco_type(
context, tobacco_type
)
context.page.goto(
f"{context.live_server_url}/{tobacco_type.lower()}-smoking-{level}-frequency"
)
when_i_check_label(context, humanize(frequency))
when_i_submit_the_form(context)
@given('I have answered questions showing I have "{level}" my amount of "{tobacco_type}" smoking to "{amount}"')
def given_i_have_answered_questions_showing_i_have_changed_amount_of_smoked_tobacco_type(context, level, tobacco_type, amount):
given_i_have_answered_questions_showing_i_have_smoked_tobacco_type(context, tobacco_type)
context.page.goto(f"{context.live_server_url}/{tobacco_type.lower()}-smoked-{level}-amount")
when_i_fill_in_label_with_value(context, f"roughly how many {tobacco_type.lower()} did you normally smoke a", amount, exact=False)
when_i_submit_the_form(context)