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