summaryrefslogtreecommitdiffstats
path: root/engagements/tests/test_forms.py
blob: b6aab9a54ae75c5fda336de1279b957012af8367 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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"])