From 7ce99e19c7d932f467e7465ee50fa57f98015f50 Mon Sep 17 00:00:00 2001 From: Andy Mitchell <326561+Themitchell@users.noreply.github.com> Date: Mon, 30 Mar 2026 14:08:32 +0100 Subject: [PATCH 1/2] PPHA-706: Use past tense for former smokers on PeriodsWhenYourStoppedSmoking --- ...riods_when_you_stopped_smoking_response.py | 13 ++++--- ...riods_when_you_stopped_smoking_response.py | 34 ++++++++++++++++++- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/lung_cancer_screening/questions/models/periods_when_you_stopped_smoking_response.py b/lung_cancer_screening/questions/models/periods_when_you_stopped_smoking_response.py index 404d69e9..14de6322 100644 --- a/lung_cancer_screening/questions/models/periods_when_you_stopped_smoking_response.py +++ b/lung_cancer_screening/questions/models/periods_when_you_stopped_smoking_response.py @@ -56,8 +56,11 @@ def _validate_duration_years_is_less_than_time_they_have_smoked(self): return None if self.duration_years > self.response_set.age_when_started_smoking_response.years_smoked_including_stopped(): - raise ValidationError( - { - "duration_years": "The number of years you stopped smoking must be fewer than the total number of years you have been smoking" - } - ) + if self.response_set.current_smoker(): + message = "The number of years you stopped smoking must be fewer than the total number of years you have been smoking" + else: + message = "The number of years you stopped or quit smoking must be fewer than the total number of years you smoked" + + raise ValidationError({ + "duration_years": message + }) diff --git a/lung_cancer_screening/questions/tests/unit/models/test_periods_when_you_stopped_smoking_response.py b/lung_cancer_screening/questions/tests/unit/models/test_periods_when_you_stopped_smoking_response.py index d5c880fa..6d97d152 100644 --- a/lung_cancer_screening/questions/tests/unit/models/test_periods_when_you_stopped_smoking_response.py +++ b/lung_cancer_screening/questions/tests/unit/models/test_periods_when_you_stopped_smoking_response.py @@ -7,6 +7,8 @@ from ...factories.periods_when_you_stopped_smoking_response_factory import PeriodsWhenYouStoppedSmokingResponseFactory from ...factories.date_of_birth_response_factory import DateOfBirthResponseFactory from ...factories.age_when_started_smoking_response_factory import AgeWhenStartedSmokingResponseFactory +from ...factories.have_you_ever_smoked_response_factory import HaveYouEverSmokedResponseFactory + from ....models.periods_when_you_stopped_smoking_response import PeriodsWhenYouStoppedSmokingResponse @@ -135,12 +137,17 @@ def test_is_invalid_if_they_havent_answered_age_started_smoking(self): ) - def test_is_invalid_if_duration_years_is_longer_than_time_they_have_smoked(self): + def test_is_invalid_if_duration_years_is_longer_than_time_they_have_smoked_and_they_are_a_current_smoker(self): self.date_of_birth_response.value = datetime.today() - relativedelta(years=55) self.date_of_birth_response.save() self.age_when_started_smoking_response.value = 18 self.age_when_started_smoking_response.save() + HaveYouEverSmokedResponseFactory.create( + response_set=self.response_set, + current_smoker=True, + ) + response = PeriodsWhenYouStoppedSmokingResponseFactory.build( response_set=self.response_set, value=True, @@ -153,3 +160,28 @@ def test_is_invalid_if_duration_years_is_longer_than_time_they_have_smoked(self) context.exception.messages[0], "The number of years you stopped smoking must be fewer than the total number of years you have been smoking", ) + + @tag("wip") + def test_is_invalid_if_duration_years_is_longer_than_time_they_have_smoked_and_they_are_a_former_smoker(self): + self.date_of_birth_response.value = datetime.today() - relativedelta(years=55) + self.date_of_birth_response.save() + self.age_when_started_smoking_response.value = 18 + self.age_when_started_smoking_response.save() + + HaveYouEverSmokedResponseFactory.create( + response_set=self.response_set, + former_smoker=True, + ) + + response = PeriodsWhenYouStoppedSmokingResponseFactory.build( + response_set=self.response_set, + value=True, + duration_years=self.date_of_birth_response.age_in_years() - self.age_when_started_smoking_response.value + 1 + ) + with self.assertRaises(ValidationError) as context: + response.full_clean() + + self.assertEqual( + context.exception.messages[0], + "The number of years you stopped or quit smoking must be fewer than the total number of years you smoked", + ) From 526b1351d9a8418a893db2eea2fd75783296bf33 Mon Sep 17 00:00:00 2001 From: Andy Mitchell <326561+Themitchell@users.noreply.github.com> Date: Mon, 30 Mar 2026 14:14:19 +0100 Subject: [PATCH 2/2] PPHA-706: Use correct label class for duration years in periods stopped smoking --- .../questions/forms/periods_when_you_stopped_smoking_form.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lung_cancer_screening/questions/forms/periods_when_you_stopped_smoking_form.py b/lung_cancer_screening/questions/forms/periods_when_you_stopped_smoking_form.py index cba1c4d9..068a74c9 100644 --- a/lung_cancer_screening/questions/forms/periods_when_you_stopped_smoking_form.py +++ b/lung_cancer_screening/questions/forms/periods_when_you_stopped_smoking_form.py @@ -31,7 +31,7 @@ def __init__(self, *args, **kwargs): self.fields["duration_years"] = IntegerField( label=self.duration_years_label(), - label_classes="nhsuk-fieldset__legend--s", + label_classes="nhsuk-label--s", classes="nhsuk-input--width-4", hint=self.duration_years_hint(), required=False,