summaryrefslogblamecommitdiffstats
path: root/instruments/tests/test_models.py
blob: 7762ddedcefd4a41d52d5c52d5875e08a8e81017 (plain) (tree)
1
2
3
4
5
6
7
8
9


               



                                               

                                  
 
               

                              
 
 






                                                                  
                                                                 



                                                  
















                                                                       


                                           
import datetime

import pytest

from engagements import models
from engagements.utils import populate_database

pytestmark = pytest.mark.django_db


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


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