diff options
Diffstat (limited to 'engagements/tests')
-rw-r--r-- | engagements/tests/test_views.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/engagements/tests/test_views.py b/engagements/tests/test_views.py index 233ac7e..7a65ea0 100644 --- a/engagements/tests/test_views.py +++ b/engagements/tests/test_views.py @@ -6,6 +6,7 @@ from django.test import RequestFactory from django.urls import reverse from engagements import models, views +from engagements.models import EngagementStrategy, RegulatoryCycle from engagements.utils import populate_database pytestmark = pytest.mark.django_db @@ -63,3 +64,53 @@ def test_get_blank_form(client, test_data, request_factory): response = views.engagement_effort_create(request, eid=1, etype="PLANNING") assert response.status_code == HTTPStatus.OK + +# def test_get_form_to_create_engagement_strategy(client, request_factory): +# url = reverse("engagements:es-create") +# client.force_login(test_data["superuser"]) +# request = request_factory.get(url) +# request.user = test_data["superuser"] +# response = views.CreateEngagementStrategy() +# assert response.status_code == HTTPStatus.OK + + +def test_create_engagement_strategy(client, user, org, regulatory_cycles): + # Define the URL for the create view + url = reverse("engagements:es-create") + client.force_login(user) + + sy = RegulatoryCycle.objects.get(start_date__year="2022") + ey = RegulatoryCycle.objects.get(start_date__year="2024") + + # Define sample data for the form + data = { + "organisation": org, + "start_year": sy, + "end_year": ey, + "description": "Example description", + "inspector_sign_off": "2022-01-10", + "owned_by": user, + "reviewed_by": user, + "management_sign_off": "2022-02-10", + "status": "DRAFT", + } + + # Send a POST request to the view + response = client.post(url, data) + + # Check that the response redirects (status code 302) after successful creation + assert response.status_code == 200 + + # Check that a new EngagementStrategy object was created in the database + assert EngagementStrategy.objects.filter(organisation__name="MOD").exists() + + +# def test_create_view_uses_correct_form(self): +# # Define the URL for the create view +# url = reverse("engagement_strategy_create") +# +# # Send a GET request to the view +# response = self.client.get(url) +# +# # Check that the response uses the correct form class +# self.assertIsInstance(response.context["form"], EngagementStrategyCreateForm) |