summaryrefslogtreecommitdiffstats
path: root/instruments/tests/test_models.py
blob: 9b826292c0861d29c69fe13c8b34f16375e3d321 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import datetime

import pytest

from engagements import models
from engagements.utils import populate_database
from instruments.models import SOP
from myuser.models import TeamUser

pytestmark = pytest.mark.django_db


@pytest.fixture
def test_data():
    return populate_database()


def test_sop():
    user = TeamUser.objects.create_user(email="ming@mingy.com")
    SOP.objects.create(
        name="SOP 1",
        designation="SOP1",
        sp_link="https://example.com",
        draft_status="Draft",
        author_lead=user,
    )


class TestModels:
    def test_check_all_dcs(self, test_data):
        dscs = test_data.get("sub_instruments")
        assert dscs[0].title == "DSC 1 - Title 1"

    def test_get_hours_of_effort_for_dsc_for_org(self, test_data):
        org = test_data["orgs"][0]
        et = models.EngagementType.objects.get(name="INSPECTION")
        si = test_data["sub_instruments"][0]
        si2 = test_data["sub_instruments"][2]
        si3 = test_data["sub_instruments"][3]
        # si_not = test_data["sub_instruments"][1]
        engagement = models.Engagement.objects.create(
            proposed_start_date=datetime.date(2022, 10, 10),
            proposed_end_date=datetime.date(2022, 10, 10),
            engagement_type=et,
            external_party=org,
        )
        ef1 = models.EngagementEffort.objects.create(
            is_planned=True,
            effort_type="REGULATION",
            proposed_start_date=datetime.datetime(2022, 10, 10, 10, 0),
            proposed_end_date=datetime.datetime(2022, 10, 10, 12, 0),
            engagement=engagement,
        )
        ef1.sub_instruments.add(si)  # DSC 1
        ef1.sub_instruments.add(si2)  # DSC 3
        ef1.sub_instruments.add(si3)  # DSC 4
        ef1.save()
        assert si.effort_for_org(org) == 2
        assert si2.effort_for_org(org) == 2
        assert si3.effort_for_org(org) == 2