diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-11 19:32:34 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-11 19:32:34 +0100 |
commit | 721c0e7e3056d6e14499b807cdc2837505c5ca18 (patch) | |
tree | ae1bf3b6951b28cf9c6c761e250c4eb9b9b09186 | |
parent | 851017203f9962c2d9bd2f483e736ef88ef8f8aa (diff) |
first test for caf periodic event
-rw-r--r-- | ctrack/register/models.py | 20 | ||||
-rw-r--r-- | ctrack/register/tests/test_event_models.py | 19 |
2 files changed, 37 insertions, 2 deletions
diff --git a/ctrack/register/models.py b/ctrack/register/models.py index 549f77d..53b65a0 100644 --- a/ctrack/register/models.py +++ b/ctrack/register/models.py @@ -21,11 +21,11 @@ class EventType(Enum): CAF_FEEDBACK_EMAILED_OES = auto() CAF_RECEIVED = auto() CAF_EMAILED_ROSA = auto() + CAF_VALIDATION_SIGN_OFF = auto() + CAF_VALIDATION_RECORD_EMAILED_TO_OES = auto() # twin date caf events CAF_PEER_REVIEW_PERIOD = auto() CAF_VALIDATION_PERIOD = auto() - CAF_VALIDATION_SIGN_OFF = auto() - CAF_VALIDATION_RECORD_EMAILED_TO_OES = auto() def _style_descriptor(days: int) -> str: @@ -106,6 +106,14 @@ class SingleDateMixin(models.Model): abstract = True +class TwinDateMixin(models.Model): + start_date = models.DateField() + end_date = models.DateField() + + class Meta: + abstract = True + + class CAFMixin(models.Model): related_caf = models.ForeignKey(CAF, on_delete=models.CASCADE) @@ -143,6 +151,14 @@ class CAFSingleDateEvent(EventBase, CAFMixin, SingleDateMixin): ] +class CAFTwinDateEvent(EventBase, CAFMixin, TwinDateMixin): + AVAILABLE_TYPES = [ + (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) + + # OLD CODE BELOW diff --git a/ctrack/register/tests/test_event_models.py b/ctrack/register/tests/test_event_models.py index 4c4d77c..678d8b5 100644 --- a/ctrack/register/tests/test_event_models.py +++ b/ctrack/register/tests/test_event_models.py @@ -7,6 +7,7 @@ from ctrack.register.models import ( EventType, SingleDateTimeEvent, CAFSingleDateEvent, + CAFTwinDateEvent, ) pytestmark = pytest.mark.django_db @@ -35,6 +36,24 @@ def test_caf_single_date_events(allowed_type, user, caf): assert e.type_descriptor == allowed_type +@pytest.mark.parametrize( + "allowed_type", ["CAF_PEER_REVIEW_PERIOD", "CAF_VALIDATION_PERIOD"] +) +def test_caf_twin_date_events(allowed_type, user, caf): + now = datetime.datetime.now() + e = CAFTwinDateEvent.objects.create( + type_descriptor=allowed_type, + related_caf=caf, + short_description="CAF received for X Company", + start_date="2020-10-10", + end_date="2020-10-25", + comments="Nice comments for this event", + user=user, + ) + assert e.created_date.day == now.day + assert e.type_descriptor == allowed_type + + def test_cannot_add_two_caf_initial_caf_received_events_on_same_date(user, caf): CAFSingleDateEvent.objects.create( type_descriptor="CAF_INITIAL_CAF_RECEIVED", |