From 00c9e86c03548adba7e9f2e7a2945ae1c219cd15 Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Tue, 23 Apr 2024 19:05:36 +0000 Subject: [PATCH] test: add assertions for form widget attributes --- tests/pytest/eligibility/test_forms.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/pytest/eligibility/test_forms.py b/tests/pytest/eligibility/test_forms.py index bd65892fea..6ddafb79b4 100644 --- a/tests/pytest/eligibility/test_forms.py +++ b/tests/pytest/eligibility/test_forms.py @@ -6,8 +6,28 @@ def test_MSTCourtesyCard(): assert form.is_valid() + sub_attrs = form.fields["sub"].widget.attrs + assert sub_attrs["pattern"] == r"\d{5}" + assert sub_attrs["inputmode"] == "numeric" + assert sub_attrs["maxlength"] == 5 + assert sub_attrs["data-custom-validity"] == "Please enter a 5-digit number." + + name_attrs = form.fields["name"].widget.attrs + assert name_attrs["maxlength"] == 255 + assert name_attrs["data-custom-validity"] == "Please enter your last name." + def test_SBMTDMobilityPass(): form = SBMTDMobilityPass(data={"sub": "1234", "name": "Barbara"}) assert form.is_valid() + + sub_attrs = form.fields["sub"].widget.attrs + assert sub_attrs["pattern"] == r"\d{4}" + assert sub_attrs["maxlength"] == 4 + assert sub_attrs["inputmode"] == "numeric" + assert sub_attrs["data-custom-validity"] == "Please enter a 4-digit number." + + name_attrs = form.fields["name"].widget.attrs + assert name_attrs["maxlength"] == 255 + assert name_attrs["data-custom-validity"] == "Please enter your last name."