diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-12 12:26:39 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-12 12:26:39 +0100 |
commit | 3f818f99669ab0b49f98b7e7da43c38dc119bfd5 (patch) | |
tree | 972a6603c46581495e5946bf6a1995eac9ddf4b7 /ctrack | |
parent | 7db4392801aca82d1dec6eb57abf7cb74c10689c (diff) |
another test added for CAFTwinDateEventForm
Diffstat (limited to 'ctrack')
-rw-r--r-- | ctrack/register/forms.py | 24 | ||||
-rw-r--r-- | ctrack/register/models.py | 21 | ||||
-rw-r--r-- | ctrack/register/tests/test_forms.py | 17 |
3 files changed, 54 insertions, 8 deletions
diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py index b09804e..1d46c36 100644 --- a/ctrack/register/forms.py +++ b/ctrack/register/forms.py @@ -11,6 +11,7 @@ from ctrack.register.models import ( EngagementType, CAFSingleDateEvent, SingleDateTimeEvent, + CAFTwinDateEvent, ) @@ -58,6 +59,29 @@ class CAFSingleDateEventForm(forms.ModelForm): return form +class CAFTwinDateEventForm(forms.ModelForm): + class Meta: + model = CAFTwinDateEvent + fields = [ + "type_descriptor", + "related_caf", + "short_description", + "start_date", + "end_date", + "comments", + ] + + def __init__(self, *args, **kwargs): + self.user = kwargs.pop("user") + super().__init__(*args, **kwargs) + + def save(self, **kwargs): + 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/models.py b/ctrack/register/models.py index f69deca..9e0516e 100644 --- a/ctrack/register/models.py +++ b/ctrack/register/models.py @@ -45,7 +45,7 @@ def _day_string(days: int) -> str: class AuditableEventBase(models.Model): - user = models.ForeignKey(User, on_delete=models.CASCADE) + user = models.ForeignKey(User, on_delete=models.CASCADE, blank=False) created_date = models.DateTimeField() modified_date = models.DateTimeField() @@ -66,6 +66,7 @@ class EventBase(AuditableEventBase): short_description = models.CharField( max_length=50, help_text="Short description of the event. Use Comments field for full detail.", + blank=False, ) document_link = models.URLField( max_length=1000, @@ -93,14 +94,14 @@ class ThirdPartyEventMixin(models.Model): class SingleDateTimeEventMixin(models.Model): - datetime = models.DateTimeField() + datetime = models.DateTimeField(blank=False) class Meta: abstract = True class SingleDateMixin(models.Model): - date = models.DateField() + date = models.DateField(blank=False) class Meta: abstract = True @@ -115,7 +116,7 @@ class TwinDateMixin(models.Model): class CAFMixin(models.Model): - related_caf = models.ForeignKey(CAF, on_delete=models.CASCADE) + related_caf = models.ForeignKey(CAF, on_delete=models.CASCADE, blank=False) class SingleDateTimeEvent(EventBase, ThirdPartyEventMixin, SingleDateTimeEventMixin): @@ -124,7 +125,9 @@ class SingleDateTimeEvent(EventBase, ThirdPartyEventMixin, SingleDateTimeEventMi (EventType.PHONE_CALL.name, "Phone Call"), (EventType.VIDEO_CALL.name, "Video Call"), ] - type_descriptor = models.CharField(max_length=50, choices=AVAILABLE_TYPES) + type_descriptor = models.CharField( + blank=False, max_length=50, choices=AVAILABLE_TYPES + ) def __str__(self): return self.type_descriptor @@ -142,7 +145,9 @@ class CAFSingleDateEvent(EventBase, CAFMixin, SingleDateMixin): "CAF - Validation Record Sent to OES", ), ] - type_descriptor = models.CharField(max_length=50, choices=AVAILABLE_TYPES) + type_descriptor = models.CharField( + blank=False, max_length=50, choices=AVAILABLE_TYPES + ) class Meta: constraints = [ @@ -161,7 +166,9 @@ class CAFTwinDateEvent(EventBase, CAFMixin, TwinDateMixin): (EventType.CAF_PEER_REVIEW_PERIOD.name, "CAF - Peer Review Period"), (EventType.CAF_VALIDATION_PERIOD.name, "CAF - Validation Period"), ] - type_descriptor = models.CharField(max_length=50, choices=AVAILABLE_TYPES) + type_descriptor = models.CharField( + blank=False, max_length=50, choices=AVAILABLE_TYPES + ) # OLD CODE BELOW diff --git a/ctrack/register/tests/test_forms.py b/ctrack/register/tests/test_forms.py index 9dd7437..f1b8630 100644 --- a/ctrack/register/tests/test_forms.py +++ b/ctrack/register/tests/test_forms.py @@ -1,7 +1,7 @@ import pytest from django.db import IntegrityError -from ..forms import AddMeetingForm, CAFSingleDateEventForm +from ..forms import AddMeetingForm, CAFSingleDateEventForm, CAFTwinDateEventForm pytestmark = pytest.mark.django_db @@ -139,3 +139,18 @@ def test_can_register_two_send_to_rosa_events_on_same_day(user, caf): ) assert form1.is_valid() assert form2.is_valid() + + +def test_caf_twin_date_event(user, caf): + form = CAFTwinDateEventForm( + { + "type_descriptor": "CAF_PEER_REVIEW_PERIOD", + "related_caf": caf, + "short_description": "Test Description", + "start_date": "2009-10-01", + "end_date": "2015-10-1", + "comments": "Meaningless comments", + }, + user=user, + ) + assert form.is_valid() |