summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-09-10 15:44:55 +0100
committerMatthew Lemon <y@yulqen.org>2024-09-10 15:44:55 +0100
commit17d219976e003a22ac5e6199a8b02ef1c82e4bde (patch)
tree553232842f65b04ed0ab8cba0618708afa4446aa
parent15520388a725dd9763e80ad617f31aea3b2ddb67 (diff)
Test passing for CreateView for ES create form
-rw-r--r--engagements/tests/test_views.py30
1 files changed, 9 insertions, 21 deletions
diff --git a/engagements/tests/test_views.py b/engagements/tests/test_views.py
index 7a65ea0..017b96f 100644
--- a/engagements/tests/test_views.py
+++ b/engagements/tests/test_views.py
@@ -6,7 +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.models import EngagementStrategy, RegulatoryCycle, Organisation
from engagements.utils import populate_database
pytestmark = pytest.mark.django_db
@@ -78,19 +78,20 @@ 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)
+ mod = Organisation.objects.create(name="MOD", is_regulated_entity=False)
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,
+ "organisation": mod.pk,
+ "start_year": sy.pk, # Use the pk of the regulatory cycle instead of the object itself
+ "end_year": ey.pk,
"description": "Example description",
"inspector_sign_off": "2022-01-10",
- "owned_by": user,
- "reviewed_by": user,
+ "owned_by": user.pk, # Same here
+ "reviewed_by": user.pk,
"management_sign_off": "2022-02-10",
"status": "DRAFT",
}
@@ -99,18 +100,5 @@ def test_create_engagement_strategy(client, user, org, regulatory_cycles):
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)
+ assert response.status_code == 302
+ assert EngagementStrategy.objects.count() == 1