aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-10-11 17:01:45 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-10-11 17:01:45 +0100
commit61e4e92cf683520eb53b4c1d1889f3256a8b754b (patch)
tree86a5eb3da74d569326e8f188b2ae497b6bccaab7
parentca6a7cc617f9f0fb37931a1268a75ab9ec1879cd (diff)
more testing of CAFSingleDateEventForm
Diffstat (limited to '')
-rw-r--r--ctrack/register/forms.py4
-rw-r--r--ctrack/register/tests/test_forms.py54
2 files changed, 56 insertions, 2 deletions
diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py
index ef3ef14..cff2fe4 100644
--- a/ctrack/register/forms.py
+++ b/ctrack/register/forms.py
@@ -29,7 +29,7 @@ class AddMeetingForm(forms.ModelForm):
self.user = kwargs.pop("user")
super().__init__(*args, **kwargs)
- def save(self):
+ def save(self, **kwargs):
form = super().save(commit=False)
form.user = self.user
form.save()
@@ -51,7 +51,7 @@ class CAFSingleDateEventForm(forms.ModelForm):
self.user = kwargs.pop("user")
super().__init__(*args, **kwargs)
- def save(self):
+ def save(self, **kwargs):
form = super().save(commit=False)
form.user = self.user
form.save()
diff --git a/ctrack/register/tests/test_forms.py b/ctrack/register/tests/test_forms.py
index f13662d..322ea1c 100644
--- a/ctrack/register/tests/test_forms.py
+++ b/ctrack/register/tests/test_forms.py
@@ -1,4 +1,5 @@
import pytest
+from django.db import IntegrityError
from ..forms import AddMeetingForm, CAFSingleDateEventForm
@@ -60,3 +61,56 @@ def test_caf_initial_received_form(allowed_type, user, caf):
user=user,
)
assert form.is_valid()
+
+
+def test_cannot_create_two_caf_initial_receipt_events_on_same_day(user, caf):
+ form1 = CAFSingleDateEventForm(
+ {
+ "type_descriptor": "CAF_INITIAL_CAF_RECEIVED",
+ "related_caf": caf,
+ "short_description": "Test Short Description",
+ "date": "2010-07-01",
+ "comments": "Meaningless comments",
+ },
+ user=user,
+ )
+ form2 = CAFSingleDateEventForm(
+ {
+ "type_descriptor": "CAF_INITIAL_CAF_RECEIVED",
+ "related_caf": caf,
+ "short_description": "Test Short Description",
+ "date": "2010-07-01",
+ "comments": "Meaningless comments",
+ },
+ user=user,
+ )
+ assert form1.is_valid()
+ form1.save()
+ assert form2.is_valid()
+ with pytest.raises(IntegrityError):
+ form2.save()
+
+
+def test_can_register_two_send_to_rosa_events_on_same_day(user, caf):
+ form1 = CAFSingleDateEventForm(
+ {
+ "type_descriptor": "CAF_EMAILED_ROSA",
+ "related_caf": caf,
+ "short_description": "Test Short Description",
+ "date": "2010-07-01",
+ "comments": "Meaningless comments",
+ },
+ user=user,
+ )
+ form2 = CAFSingleDateEventForm(
+ {
+ "type_descriptor": "CAF_EMAILED_ROSA",
+ "related_caf": caf,
+ "short_description": "Test Short Description 2",
+ "date": "2010-07-01",
+ "comments": "Meaningless comments 2",
+ },
+ user=user,
+ )
+ assert form1.is_valid()
+ assert form2.is_valid()