Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,11 @@ def fill_in_and_submit_ethnicity(page, ethnicity):
page.get_by_label(ethnicity, exact=True).check()

page.click("text=Continue")

def fill_in_and_submit_asbestos_exposure(page, answer):
expect(page.locator("legend")).to_have_text(
"Have you ever worked in a job where you might have been exposed to asbestos?")

page.get_by_label(answer, exact=True).check()

page.click("text=Continue")
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
fill_in_and_submit_date_of_birth,
fill_in_and_submit_sex_at_birth,
fill_in_and_submit_gender,
fill_in_and_submit_ethnicity
fill_in_and_submit_ethnicity,
fill_in_and_submit_asbestos_exposure
)

class TestQuestionnaire(StaticLiveServerTestCase):
Expand Down Expand Up @@ -46,6 +47,7 @@ def test_cannot_change_responses_once_checked_and_submitted(self):
fill_in_and_submit_sex_at_birth(page, "Male")
fill_in_and_submit_gender(page, "Male")
fill_in_and_submit_ethnicity(page, "White")
fill_in_and_submit_asbestos_exposure(page, "No")

page.click("text=Submit")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
fill_in_and_submit_weight_imperial,
fill_in_and_submit_sex_at_birth,
fill_in_and_submit_gender,
fill_in_and_submit_ethnicity
fill_in_and_submit_ethnicity,
fill_in_and_submit_asbestos_exposure
)

from .helpers.assertion_helpers import expect_back_link_to_have_url
Expand Down Expand Up @@ -90,9 +91,14 @@ def test_full_questionnaire_user_journey(self):

fill_in_and_submit_ethnicity(page, "White")

expect(page).to_have_url(f"{self.live_server_url}/responses")
expect(page).to_have_url(f"{self.live_server_url}/asbestos-exposure")
expect_back_link_to_have_url(page, "/ethnicity")

fill_in_and_submit_asbestos_exposure(page, "No")

expect(page).to_have_url(f"{self.live_server_url}/responses")
expect_back_link_to_have_url(page, "/asbestos-exposure")

responses = page.locator(".responses")
expect(responses).to_contain_text("Have you ever smoked? Yes, I used to smoke regularly")
expect(responses).to_contain_text(
Expand All @@ -102,6 +108,7 @@ def test_full_questionnaire_user_journey(self):
expect(responses).to_contain_text("What was your sex at birth? Male")
expect(responses).to_contain_text("Which of these best describes you? Male")
expect(responses).to_contain_text("What is your ethnic background? White")
expect(responses).to_contain_text("Have you ever worked in a job where you might have been exposed to asbestos? No")

page.click("text=Submit")

Expand Down
25 changes: 25 additions & 0 deletions lung_cancer_screening/questions/forms/asbestos_exposure_form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django import forms
from ...nhsuk_forms.typed_choice_field import TypedChoiceField
from ..models.response_set import ResponseSet


class AsbestosExposureForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.participant = kwargs.pop('participant')
super().__init__(*args, **kwargs)
self.instance.participant = self.participant

self.fields["asbestos_exposure"] = TypedChoiceField(
choices=[(True, 'Yes'), (False, 'No')],
widget=forms.RadioSelect,
label="Have you ever worked in a job where you might have been exposed to asbestos?",
label_classes="nhsuk-fieldset__legend--m",
coerce=lambda x: x == 'True',
error_messages={
'required': 'Select if you have been exposed to asbestos.'
}
)

class Meta:
model = ResponseSet
fields = ['asbestos_exposure']
61 changes: 61 additions & 0 deletions lung_cancer_screening/questions/jinja2/asbestos_exposure.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% extends 'layout.jinja' %}
{% from 'nhsuk/components/button/macro.jinja' import button %}
{% from 'nhsuk/components/back-link/macro.jinja' import backLink %}
{% from 'nhsuk/components/details/macro.jinja' import details %}

{% block beforeContent %}
{{
backLink({
"href": url("questions:ethnicity"),
"text": "Back"
})
}}
{% endblock beforeContent %}

{% block page_content %}
<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-two-thirds">
<h1 class="nhsuk-heading-l">Tell us if you might have been exposed to asbestos at work</h1>

<p>You may have been exposed to asbestos if you worked in an industry such as building or construction, particularly from the 1950s to the 1990s.</p>

<p>You could be exposed to asbestos today if your job involves working in certain roles in old buildings.</p>

<p>Examples include:</p>
<ul>
<li>heating and ventilation engineers</li>
<li>demolition workers</li>
<li>plumbers</li>
<li>construction workers</li>
<li>electricians</li>
</ul>

<p>You may have come into contact with asbestos from existing asbestos-containing materials in buildings and products. If they are intact or undamaged, they pose very little risk.</p>

{{
details({
"summaryText": "What is asbestos?",
"html": "<p>Asbestos was used in a number of building materials and products. For example:</p>
<ul>
<li>boilers and pipes</li>
<li>car brakes</li>
<li>cement for roofing sheets</li>
<li>floor tiles</li>
<li>insulating board to protect buildings and ships against fire</li>
</ul>
<p>If you worked in an industry such as building or construction you are more likely to have come into contact with damaged asbestos materials and products.</p>"
})
}}

<form action="{{ request.path }}" method="POST">
{{ csrf_input }}

{{ form }}

{{ button({
"text": "Continue"
}) }}
</form>
</div>
</div>
{% endblock %}
3 changes: 2 additions & 1 deletion lung_cancer_screening/questions/jinja2/responses.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% block beforeContent %}
{{
backLink({
"href": url("questions:ethnicity"),
"href": url("questions:asbestos_exposure"),
"text": "Back"
})
}}
Expand All @@ -23,6 +23,7 @@
<li>What was your sex at birth? {{ response_set.get_sex_at_birth_display() }}</li>
<li>Which of these best describes you? {{ response_set.get_gender_display() }}</li>
<li>What is your ethnic background? {{ response_set.get_ethnicity_display() }}</li>
<li>Have you ever worked in a job where you might have been exposed to asbestos? {{ "Yes" if response_set.asbestos_exposure else "No" }}</li>
</ul>

<form action="{{ request.path }}" method="post">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.2.8 on 2025-11-12 08:26

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('questions', '0015_responseset_ethnicity_alter_responseset_gender'),
]

operations = [
migrations.AddField(
model_name='responseset',
name='asbestos_exposure',
field=models.CharField(blank=True, choices=[('Y', 'Yes'), ('N', 'No')], max_length=1, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.2.7 on 2025-11-12 11:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('questions', '0016_responseset_asbestos_exposure'),
]

operations = [
migrations.AlterField(
model_name='responseset',
name='asbestos_exposure',
field=models.BooleanField(blank=True, null=True),
),
]
5 changes: 5 additions & 0 deletions lung_cancer_screening/questions/models/response_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ class ResponseSet(BaseModel):
blank=True
)

asbestos_exposure = models.BooleanField(
null=True,
blank=True
)

submitted_at = models.DateTimeField(null=True, blank=True)

class Meta:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from django.test import TestCase

from ....models.participant import Participant
from ....forms.asbestos_exposure_form import AsbestosExposureForm


class TestAsbestosExposureForm(TestCase):
def setUp(self):
self.participant = Participant.objects.create(unique_id="1234567890")

def test_is_valid_with_yes(self):
form = AsbestosExposureForm(
participant=self.participant,
data={
"asbestos_exposure": True
}
)
self.assertTrue(form.is_valid())
self.assertEqual(
form.cleaned_data["asbestos_exposure"],
True
)

def test_is_valid_with_no(self):
form = AsbestosExposureForm(
participant=self.participant,
data={
"asbestos_exposure": False
}
)
self.assertTrue(form.is_valid())
self.assertEqual(
form.cleaned_data["asbestos_exposure"],
False
)

def test_is_invalid_with_an_invalid_value(self):
form = AsbestosExposureForm(
participant=self.participant,
data={
"asbestos_exposure": "invalid"
}
)
self.assertFalse(form.is_valid())
self.assertEqual(
form.errors["asbestos_exposure"],
["Select a valid choice. invalid is not one of the available choices."]
)

def test_is_invalid_when_no_option_is_selected(self):
form = AsbestosExposureForm(
participant=self.participant,
data={
"asbestos_exposure": None
}
)
self.assertFalse(form.is_valid())
self.assertEqual(
form.errors["asbestos_exposure"],
["Select if you have been exposed to asbestos."]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from django.test import TestCase
from django.urls import reverse

from lung_cancer_screening.questions.models.participant import Participant


class TestAsbestosExposure(TestCase):
def setUp(self):
self.participant = Participant.objects.create(unique_id="12345")
self.participant.responseset_set.create()
self.valid_params = {"asbestos_exposure": True}

session = self.client.session
session['participant_id'] = self.participant.unique_id
session.save()

def test_get_redirects_if_the_participant_does_not_exist(self):
session = self.client.session
session['participant_id'] = "somebody none existant participant"
session.save()

response = self.client.get(
reverse("questions:asbestos_exposure")
)

self.assertRedirects(response, reverse("questions:start"))

def test_get_responds_successfully(self):
response = self.client.get(reverse("questions:asbestos_exposure"))
self.assertEqual(response.status_code, 200)

def test_get_contains_the_correct_form_fields(self):
response = self.client.get(reverse("questions:asbestos_exposure"))
self.assertContains(response, "Have you ever worked in a job where you might have been exposed to asbestos?")

def test_post_redirects_if_the_participant_does_not_exist(self):
session = self.client.session
session['participant_id'] = "somebody none existant participant"
session.save()

response = self.client.post(
reverse("questions:asbestos_exposure"),
self.valid_params
)

self.assertRedirects(response, reverse("questions:start"))

def test_post_stores_a_valid_response_for_the_participant(self):
self.client.post(
reverse("questions:asbestos_exposure"),
self.valid_params
)

response_set = self.participant.responseset_set.first()
self.assertEqual(
response_set.asbestos_exposure,
self.valid_params["asbestos_exposure"]
)
self.assertEqual(response_set.participant, self.participant)

def test_post_redirects_to_the_next_page(self):
response = self.client.post(
reverse("questions:asbestos_exposure"),
self.valid_params
)

# Assuming it redirects to the next question page - adjust as needed
self.assertEqual(response.status_code, 302)

def test_post_responds_with_422_if_the_response_fails_to_create(self):
response = self.client.post(
reverse("questions:asbestos_exposure"),
{"asbestos_exposure": "something not in list"}
)

self.assertEqual(response.status_code, 422)

def test_post_does_not_update_response_set_on_invalid_data(self):
self.client.post(
reverse("questions:asbestos_exposure"),
{"asbestos_exposure": "invalid"}
)

self.assertEqual(
self.participant.responseset_set.first().asbestos_exposure,
None
)
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ def test_post_sets_the_participant_id_in_session(self):

self.assertEqual(self.client.session["participant_id"], "12345")

def test_post_redirects_to_the_responses_path(self):
def test_post_redirects_to_the_asbestos_exposure_path(self):
response = self.client.post(
reverse("questions:ethnicity"),
self.valid_params
)

self.assertRedirects(response, reverse("questions:responses"))
self.assertRedirects(response, reverse("questions:asbestos_exposure"))

def test_post_responds_with_422_if_the_date_response_fails_to_create(self):
response = self.client.post(
Expand Down
Loading
Loading