From 0f951dcf029d4af284467543a3afdf5bf6581a20 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Tue, 23 Apr 2024 11:16:38 +0100 Subject: switched to Django --- engagements/tests/test_forms.py | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 engagements/tests/test_forms.py (limited to 'engagements/tests/test_forms.py') diff --git a/engagements/tests/test_forms.py b/engagements/tests/test_forms.py new file mode 100644 index 0000000..b6aab9a --- /dev/null +++ b/engagements/tests/test_forms.py @@ -0,0 +1,45 @@ +from django.test import TestCase + +from engagements.forms import EngagementEffortCreateForm +from engagements.models import Engagement, EngagementType, Organisation +from myuser.models import TeamUser + + +class EngagementEffortCreate(TestCase): + def setUp(self): + data = { + "proposed_start_date": "2022-10-01", + "engagement_type": EngagementType.objects.create(name="ET1"), + "external_party": Organisation.objects.create(name="O1"), + } + self.e = Engagement.objects.create(**data) + self.user = TeamUser.objects.create_user(email="ming@ming.com") + + def test_basic_validation(self): + form = EngagementEffortCreateForm( + data={ + "is_planned": True, + "proposed_start_date": "2022-10-10 10:00", + "proposed_end_date": "2022-10-10 12:00", + "engagement": self.e, + "effort_type": "PLANNING", + "officers": [self.user], + } + ) + self.assertFalse(form.errors) + + def test_basic_validation_on_bad_entry(self): + form = EngagementEffortCreateForm( + data={ + "is_planned": True, + "proposed_start_date": "20240-10-10 10:00", + "proposed_end_date": "2022-10-10 12:00", + "engagement": self.e, + "effort_type": "bobbins", + "officers": [self.user], + "sub_instruments": [""], + } + ) + self.assertTrue(form.errors["effort_type"]) + self.assertTrue(form.errors["proposed_start_date"]) + self.assertTrue(form.errors["sub_instruments"]) -- cgit v1.2.3