From 2058dbd918b7fc8a128a76e41a22b941b85ab188 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 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/pytest/eligibility/test_forms.py b/tests/pytest/eligibility/test_forms.py index bd65892fea..3736fe3dc3 100644 --- a/tests/pytest/eligibility/test_forms.py +++ b/tests/pytest/eligibility/test_forms.py @@ -6,8 +6,26 @@ 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 + 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