aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack
diff options
context:
space:
mode:
Diffstat (limited to 'ctrack')
-rw-r--r--ctrack/register/forms.py29
-rw-r--r--ctrack/register/tests/test_forms.py55
2 files changed, 67 insertions, 17 deletions
diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py
index 16c82f0..ef3ef14 100644
--- a/ctrack/register/forms.py
+++ b/ctrack/register/forms.py
@@ -6,7 +6,12 @@ from django.urls import reverse
from ctrack.caf.models import CAF
from ctrack.organisations.models import Person, Organisation
-from ctrack.register.models import EngagementEvent, EngagementType, MeetingEvent
+from ctrack.register.models import (
+ EngagementEvent,
+ EngagementType,
+ MeetingEvent,
+ CAFSingleDateEvent,
+)
class AddMeetingForm(forms.ModelForm):
@@ -31,6 +36,28 @@ class AddMeetingForm(forms.ModelForm):
return form
+class CAFSingleDateEventForm(forms.ModelForm):
+ class Meta:
+ model = CAFSingleDateEvent
+ fields = [
+ "type_descriptor",
+ "related_caf",
+ "short_description",
+ "date",
+ "comments",
+ ]
+
+ def __init__(self, *args, **kwargs):
+ self.user = kwargs.pop("user")
+ super().__init__(*args, **kwargs)
+
+ def save(self):
+ form = super().save(commit=False)
+ form.user = self.user
+ form.save()
+ return form
+
+
class EngagementEventCreateForm(forms.ModelForm):
def __init__(self, user, caf=None, org_slug=None, *args, **kwargs):
super().__init__(*args, **kwargs)
diff --git a/ctrack/register/tests/test_forms.py b/ctrack/register/tests/test_forms.py
index 6d7d914..f13662d 100644
--- a/ctrack/register/tests/test_forms.py
+++ b/ctrack/register/tests/test_forms.py
@@ -1,6 +1,6 @@
import pytest
-from ..forms import AddMeetingForm
+from ..forms import AddMeetingForm, CAFSingleDateEventForm
pytestmark = pytest.mark.django_db
@@ -8,17 +8,19 @@ pytestmark = pytest.mark.django_db
# TODO this test and the form code needs to be amended to save created_by and update_by
# on the model
+
def test_init(user):
"""Here we test that we can pass in the user value from the view.
We don't want that to be field in the form.
"""
- form = AddMeetingForm({
- "type_descriptor": "MEETING", # Must be Meeting as that is in the choices param
- "short_description": "Test short description",
- "datetime": "2010-10-10T13:00",
- "comments": "Test Comments",
- "location": "Transient Moabs"
- },
+ form = AddMeetingForm(
+ {
+ "type_descriptor": "MEETING", # Must be Meeting as that is in the choices param
+ "short_description": "Test short description",
+ "datetime": "2010-10-10T13:00",
+ "comments": "Test Comments",
+ "location": "Transient Moabs",
+ },
user=user,
)
assert form.is_valid()
@@ -26,14 +28,35 @@ def test_init(user):
def test_meeting_blank_data(user):
"""Missing datetime fields is required. Location is optional"""
- form = AddMeetingForm({
- "type_descriptor": "MEETING",
- "short_description": "Test short description",
- "comments": "Test Comments",
- },
+ form = AddMeetingForm(
+ {
+ "type_descriptor": "MEETING",
+ "short_description": "Test short description",
+ "comments": "Test Comments",
+ },
user=user,
)
assert form.is_valid() is False
- assert form.errors == {
- "datetime": ["This field is required."]
- }
+ assert form.errors == {"datetime": ["This field is required."]}
+
+
+@pytest.mark.parametrize(
+ "allowed_type",
+ [
+ ("CAF_INITIAL_CAF_RECEIVED"),
+ ("CAF_RECEIVED"),
+ ("CAF_EMAILED_ROSA"),
+ ],
+)
+def test_caf_initial_received_form(allowed_type, user, caf):
+ form = CAFSingleDateEventForm(
+ {
+ "type_descriptor": allowed_type,
+ "related_caf": caf,
+ "short_description": "Test Short Description",
+ "date": "2010-07-01",
+ "comments": "Meaningless comments",
+ },
+ user=user,
+ )
+ assert form.is_valid()