summaryrefslogtreecommitdiffstats
path: root/engagements/tests/test_views.py
blob: 4899c58f77871ffcbb673df29a95a031c04cb159 (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
61
62
63
64
import datetime
from http import HTTPStatus

import pytest
from django.test import RequestFactory
from django.urls import reverse

from engagements import models, views
from engagements.utils import populate_database


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


@pytest.fixture
def request_factory():
    return RequestFactory()


@pytest.mark.django_db
def test_dscs_for_ep(client, test_data, request_factory):
    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]

    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.date(2022, 10, 10),
        proposed_end_date=datetime.date(2022, 10, 10),
        engagement=engagement,
    )
    ef1.sub_instruments.add(si, si2, si3)

    url = reverse("engagements:plan_for_org", kwargs={"orgslug": org.slug})
    client.force_login(test_data["superuser"])
    response = client.get(url)

    assert response.status_code == HTTPStatus.OK
    assert response.context["entity"]
    assert response.context["entity"].name == org.name
    assert si in response.context["dscs"]
    assert si2 in response.context["dscs"]
    assert si3 in response.context["dscs"]

@pytest.mark.django_db
def test_get_blank_form(client, test_data, request_factory):
    url = reverse("engagements:effort_create", kwargs={"eid": 1, "etype": "PLANNING"})
    client.force_login(test_data["superuser"])
    request = request_factory.get(url)
    request.user = test_data["superuser"]
    response = views.engagement_effort_create(request, eid=1, etype="PLANNING")
    assert response.status_code == HTTPStatus.OK