summaryrefslogtreecommitdiffstats
path: root/engagements/tests/test_forms.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-04-23 11:16:38 +0100
committerMatthew Lemon <y@yulqen.org>2024-04-23 11:16:38 +0100
commit0f951dcf029d4af284467543a3afdf5bf6581a20 (patch)
treea48384210cdc168e3bd3ccff6d6d516eeed9e748 /engagements/tests/test_forms.py
parent8b084e9fe7a5f3a04c32daf9a24f7f2cf67300f9 (diff)
switched to Django
Diffstat (limited to 'engagements/tests/test_forms.py')
-rw-r--r--engagements/tests/test_forms.py45
1 files changed, 45 insertions, 0 deletions
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"])