diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-12 16:09:17 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-12 16:09:17 +0100 |
commit | a0f2ae2c885f8bcc72fe0bbc549384fcc20b857b (patch) | |
tree | d4448250d4b4e78d6d4543cab9eedf4c7d4562b0 /ctrack | |
parent | 0bd4f8e84e4d1788d6119a78823881a96c039427 (diff) |
cannot put constrain on abstract Meta class seemingly...
Diffstat (limited to 'ctrack')
-rw-r--r-- | ctrack/register/models.py | 9 | ||||
-rw-r--r-- | ctrack/register/tests/test_event_models.py | 12 | ||||
-rw-r--r-- | ctrack/register/tests/test_forms.py | 4 |
3 files changed, 18 insertions, 7 deletions
diff --git a/ctrack/register/models.py b/ctrack/register/models.py index 03a7d80..4404650 100644 --- a/ctrack/register/models.py +++ b/ctrack/register/models.py @@ -5,7 +5,7 @@ from typing import Optional, Dict from django.contrib.auth import get_user_model from django.db import models -from django.db.models import Q, F +from django.db.models import F from ctrack.caf.models import CAF from ctrack.organisations.models import Person @@ -155,7 +155,7 @@ class CAFSingleDateEvent(EventBase, CAFMixin, SingleDateMixin): # the type is declared with the Q expression. models.UniqueConstraint( fields=["date", "type_descriptor"], - condition=~Q(type_descriptor="CAF_EMAILED_ROSA"), + condition=~models.Q(type_descriptor="CAF_EMAILED_ROSA"), name="unique_caf_for_date", ), ] @@ -179,12 +179,11 @@ class CAFTwinDateEvent(EventBase, CAFMixin, TwinDateMixin): class Meta: constraints = [ models.CheckConstraint( - name="end_date_cannot_precede_start_date", - check=~Q(end_date__lt=F("start_date")), + name="%(app_label)s_%(class)s_cannot_precede_start_date", + check=~models.Q(end_date__lt=F("start_date")), ) ] - # OLD CODE BELOW class EngagementType(models.Model): """ diff --git a/ctrack/register/tests/test_event_models.py b/ctrack/register/tests/test_event_models.py index 39b501c..61a541c 100644 --- a/ctrack/register/tests/test_event_models.py +++ b/ctrack/register/tests/test_event_models.py @@ -180,6 +180,18 @@ def test_single_datetime_event(person, user, allowed_type): assert event.created_date.day == now.day +def test_cannot_create_twin_date_event_model_end_date_precedes_start(user, caf): + with pytest.raises(IntegrityError): + CAFTwinDateEvent.objects.create( + type_descriptor="CAF_PEER_REVIEW_PERIOD", + related_caf=caf, + start_date="2010-10-10", + end_date="2010-01-01", + short_description="Bobbins", + user=user + ) + + def test_meeting_event(user, person): uname = user.name now = datetime.datetime.now() diff --git a/ctrack/register/tests/test_forms.py b/ctrack/register/tests/test_forms.py index 401ed2f..49cd5b4 100644 --- a/ctrack/register/tests/test_forms.py +++ b/ctrack/register/tests/test_forms.py @@ -20,7 +20,7 @@ def test_init(user): "short_description": "Test short description", "datetime": "2010-10-10T13:00", "comments": "Test Comments", - "location": "Transient Moabs", + "location": "Transient Moats", }, user=user, ) @@ -188,7 +188,7 @@ def test_cannot_create_twin_date_event_for_caf_whose_end_date_is_open(allowed_ty @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" + """This one is done with a database integrity check instead of a form validation""" with pytest.raises(IntegrityError): CAFTwinDateEventForm( { |