aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/register/tests/test_forms.py
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-10-12 14:50:16 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-10-12 14:50:16 +0100
commit0bd4f8e84e4d1788d6119a78823881a96c039427 (patch)
tree9cda64f75df57406c88ab79f4d5306862af8c901 /ctrack/register/tests/test_forms.py
parent3f818f99669ab0b49f98b7e7da43c38dc119bfd5 (diff)
more constraints added at form and model level
Diffstat (limited to 'ctrack/register/tests/test_forms.py')
-rw-r--r--ctrack/register/tests/test_forms.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/ctrack/register/tests/test_forms.py b/ctrack/register/tests/test_forms.py
index f1b8630..401ed2f 100644
--- a/ctrack/register/tests/test_forms.py
+++ b/ctrack/register/tests/test_forms.py
@@ -154,3 +154,50 @@ def test_caf_twin_date_event(user, caf):
user=user,
)
assert form.is_valid()
+
+
+@pytest.mark.parametrize("allowed_type", ["CAF_PEER_REVIEW_PERIOD", "CAF_VALIDATION_PERIOD"])
+def test_cannot_create_twin_date_event_for_caf_whose_end_date_is_open(allowed_type, user, caf):
+ e1 = CAFTwinDateEventForm(
+ {
+ "type_descriptor": allowed_type,
+ "related_caf": caf,
+ "short_description": "caf peer review for x company",
+ "start_date": "2020-10-10",
+ "comments": "nice comments for this event",
+ },
+ user=user,
+ )
+ e2 = CAFTwinDateEventForm(
+ {
+ "type_descriptor": allowed_type,
+ "related_caf": caf,
+ "short_description": "caf peer review for x company",
+ "start_date": "2020-10-10",
+ "comments": "nice comments for this event",
+ },
+ user=user,
+ )
+ assert e1.is_valid()
+ e1.save()
+ assert e2.is_valid() is False
+ assert e2.errors == {
+ "start_date": ["You cannot have two CAF events starting on the same date."]
+ }
+
+
+@pytest.mark.parametrize("allowed_type", ["CAF_PEER_REVIEW_PERIOD", "CAF_VALIDATION_PERIOD"])
+def test_cannot_create_twin_date_event_where_end_date_precedes_start(allowed_type, user, caf):
+ "This one is done with a database integrity check instead of a form validation"
+ with pytest.raises(IntegrityError):
+ CAFTwinDateEventForm(
+ {
+ "type_descriptor": allowed_type,
+ "related_caf": caf,
+ "short_description": "caf peer review for x company",
+ "start_date": "2020-10-10",
+ "end_date": "2020-10-09",
+ "comments": "nice comments for this event",
+ },
+ user=user,
+ ).save()