Skip to content

Commit 9fbd65d

Browse files
authored
Merge branch 'main' into PPHA-749-replace-fewer-with-less
2 parents 81d6c27 + db9e9c9 commit 9fbd65d

4 files changed

Lines changed: 48 additions & 38 deletions

File tree

Dockerfile

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,44 +49,19 @@ ENV PATH="$VIRTUAL_ENV/bin:$PATH"
4949
USER root
5050
WORKDIR ${APP_DIR}
5151

52-
# Install system dependencies needed for Playwright
53-
RUN apt-get update && apt-get install -y \
54-
fonts-liberation \
55-
libasound2 \
56-
libatk-bridge2.0-0 \
57-
libatk1.0-0 \
58-
libatspi2.0-0 \
59-
libcups2 \
60-
libdbus-1-3 \
61-
libdrm2 \
62-
libexpat1 \
63-
libgbm1 \
64-
libglib2.0-0 \
65-
libgtk-3-0 \
66-
libnspr4 \
67-
libnss3 \
68-
libx11-6 \
69-
libxcomposite1 \
70-
libxdamage1 \
71-
libxext6 \
72-
libxfixes3 \
73-
libxrandr2 \
74-
libxss1 \
75-
libxtst6 \
76-
xdg-utils \
77-
&& rm -rf /var/lib/apt/lists/*
78-
7952
ENV POETRY_NO_INTERACTION=1 \
8053
POETRY_VIRTUALENVS_IN_PROJECT=1 \
8154
POETRY_VIRTUALENVS_CREATE=1 \
8255
POETRY_CACHE_DIR=/tmp/poetry_cache \
8356
PLAYWRIGHT_BROWSERS_PATH=${APP_DIR}/browsers
8457

8558
COPY pyproject.toml poetry.lock ./
86-
RUN pip install poetry
87-
RUN poetry install --no-root && rm -rf $POETRY_CACHE_DIR
88-
RUN poetry run playwright install --with-deps chromium
89-
RUN chown -R ${USER}:${USER} ${APP_DIR}
59+
60+
RUN pip install --no-cache-dir poetry \
61+
&& poetry install --no-root && rm -rf $POETRY_CACHE_DIR \
62+
&& poetry run playwright install --with-deps chromium \
63+
&& chown -R ${USER}:${USER} ${APP_DIR} \
64+
&& rm -rf /root/.cache/pip /tmp/*
9065

9166
USER ${USER}
9267
COPY --chown=${USER}:${USER} . .

lung_cancer_screening/questions/forms/periods_when_you_stopped_smoking_form.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, *args, **kwargs):
3131

3232
self.fields["duration_years"] = IntegerField(
3333
label=self.duration_years_label(),
34-
label_classes="nhsuk-fieldset__legend--s",
34+
label_classes="nhsuk-label--s",
3535
classes="nhsuk-input--width-4",
3636
hint=self.duration_years_hint(),
3737
required=False,

lung_cancer_screening/questions/models/periods_when_you_stopped_smoking_response.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ def _validate_duration_years_is_less_than_time_they_have_smoked(self):
5656
return None
5757

5858
if self.duration_years > self.response_set.age_when_started_smoking_response.years_smoked_including_stopped():
59-
raise ValidationError(
60-
{
61-
"duration_years": "The number of years you stopped smoking must be fewer than the total number of years you have been smoking"
62-
}
63-
)
59+
if self.response_set.current_smoker():
60+
message = "The number of years you stopped smoking must be fewer than the total number of years you have been smoking"
61+
else:
62+
message = "The number of years you stopped or quit smoking must be fewer than the total number of years you smoked"
63+
64+
raise ValidationError({
65+
"duration_years": message
66+
})

lung_cancer_screening/questions/tests/unit/models/test_periods_when_you_stopped_smoking_response.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from ...factories.periods_when_you_stopped_smoking_response_factory import PeriodsWhenYouStoppedSmokingResponseFactory
88
from ...factories.date_of_birth_response_factory import DateOfBirthResponseFactory
99
from ...factories.age_when_started_smoking_response_factory import AgeWhenStartedSmokingResponseFactory
10+
from ...factories.have_you_ever_smoked_response_factory import HaveYouEverSmokedResponseFactory
11+
1012
from ....models.periods_when_you_stopped_smoking_response import PeriodsWhenYouStoppedSmokingResponse
1113

1214

@@ -135,12 +137,17 @@ def test_is_invalid_if_they_havent_answered_age_started_smoking(self):
135137
)
136138

137139

138-
def test_is_invalid_if_duration_years_is_longer_than_time_they_have_smoked(self):
140+
def test_is_invalid_if_duration_years_is_longer_than_time_they_have_smoked_and_they_are_a_current_smoker(self):
139141
self.date_of_birth_response.value = datetime.today() - relativedelta(years=55)
140142
self.date_of_birth_response.save()
141143
self.age_when_started_smoking_response.value = 18
142144
self.age_when_started_smoking_response.save()
143145

146+
HaveYouEverSmokedResponseFactory.create(
147+
response_set=self.response_set,
148+
current_smoker=True,
149+
)
150+
144151
response = PeriodsWhenYouStoppedSmokingResponseFactory.build(
145152
response_set=self.response_set,
146153
value=True,
@@ -153,3 +160,28 @@ def test_is_invalid_if_duration_years_is_longer_than_time_they_have_smoked(self)
153160
context.exception.messages[0],
154161
"The number of years you stopped smoking must be fewer than the total number of years you have been smoking",
155162
)
163+
164+
165+
def test_is_invalid_if_duration_years_is_longer_than_time_they_have_smoked_and_they_are_a_former_smoker(self):
166+
self.date_of_birth_response.value = datetime.today() - relativedelta(years=55)
167+
self.date_of_birth_response.save()
168+
self.age_when_started_smoking_response.value = 18
169+
self.age_when_started_smoking_response.save()
170+
171+
HaveYouEverSmokedResponseFactory.create(
172+
response_set=self.response_set,
173+
former_smoker=True,
174+
)
175+
176+
response = PeriodsWhenYouStoppedSmokingResponseFactory.build(
177+
response_set=self.response_set,
178+
value=True,
179+
duration_years=self.date_of_birth_response.age_in_years() - self.age_when_started_smoking_response.value + 1
180+
)
181+
with self.assertRaises(ValidationError) as context:
182+
response.full_clean()
183+
184+
self.assertEqual(
185+
context.exception.messages[0],
186+
"The number of years you stopped or quit smoking must be fewer than the total number of years you smoked",
187+
)

0 commit comments

Comments
 (0)