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"])