diff options
-rw-r--r-- | ctrack/register/models.py | 39 | ||||
-rw-r--r-- | ctrack/register/tests/test_events.py | 34 | ||||
-rw-r--r-- | ctrack/register/tests/test_forms.py | 3 |
3 files changed, 55 insertions, 21 deletions
diff --git a/ctrack/register/models.py b/ctrack/register/models.py index 8155fb7..c0467b0 100644 --- a/ctrack/register/models.py +++ b/ctrack/register/models.py @@ -24,6 +24,7 @@ class EventType(Enum): CAF_VALIDATION_SIGN_OFF = auto() CAF_VALIDATION_RECORD_EMAILED_TO_OES = auto() + def _style_descriptor(days: int) -> str: if days < 1: return "red" @@ -41,7 +42,7 @@ def _day_string(days: int) -> str: class AuditableEventBase(models.Model): - user = models.OneToOneField(User, on_delete=models.CASCADE) + user = models.ForeignKey(User, on_delete=models.CASCADE) created_date = models.DateTimeField() modified_date = models.DateTimeField() @@ -58,20 +59,17 @@ class AuditableEventBase(models.Model): return super().save(*args, **kwargs) -class EngagementEventBase(AuditableEventBase): - type_descriptor = "Base Type" +class EventBase(AuditableEventBase): short_description = models.CharField( max_length=50, help_text="Short description of the event. Use Comments field for full detail.", ) - participants = models.ManyToManyField(Person, null=True, blank=True) document_link = models.URLField( max_length=1000, blank=True, null=True, help_text="URL only - do not try to drag a file here.", ) - response_date_requested = models.DateField(blank=True, null=True) comments = models.TextField(max_length=1000, blank=True, null=True, help_text="Use this to provide further detail about the event.") @@ -79,9 +77,9 @@ class EngagementEventBase(AuditableEventBase): abstract = True -class MeetingEventMixin(models.Model): - participants = models.ManyToManyField(Person, blank=False, null=False) - location = models.CharField(max_length=100, blank=False) +class ThirdPartyEventMixin(models.Model): + participants = models.ManyToManyField(Person, null=True, blank=True) + location = models.CharField(max_length=100, blank=True) class Meta: abstract = True @@ -94,20 +92,25 @@ class SingleDateTimeEventMixin(models.Model): abstract = True -# class SingleDateCAFEvent(EngagementEventBase): -# type = models.ForeignKey( -# EngagementType, default=event_type, on_delete=models.CASCADE -# ) -# caf_related = models.BooleanField(default=True) -# date = models.DateField(blank=False, null=False) +class SingleDateTimeEvent(EventBase, ThirdPartyEventMixin, SingleDateTimeEventMixin): + AVAILABLE_TYPES = [ + (EventType.PHONE_CALL.name, "Phone Call"), + (EventType.VIDEO_CALL.name, "Video Call") + ] + type_descriptor = models.CharField(max_length=50, choices=AVAILABLE_TYPES) + + def __str__(self): + return self.type_descriptor -class MeetingEvent(EngagementEventBase, MeetingEventMixin, SingleDateTimeEventMixin): - MEETING_TYPES = [ - ("Meeting", "Meeting") +class MeetingEvent(EventBase, ThirdPartyEventMixin, SingleDateTimeEventMixin): + AVAILABLE_TYPES = [ + (EventType.MEETING.name, "Meeting") ] - type_descriptor = models.CharField(max_length=50, choices=MEETING_TYPES) + type_descriptor = models.CharField(max_length=50, choices=AVAILABLE_TYPES) + +# OLD CODE BELOW class EngagementType(models.Model): """ diff --git a/ctrack/register/tests/test_events.py b/ctrack/register/tests/test_events.py index 1cff086..b8e4d8b 100644 --- a/ctrack/register/tests/test_events.py +++ b/ctrack/register/tests/test_events.py @@ -2,7 +2,7 @@ import datetime import pytest -from ctrack.register.models import MeetingEvent, EventType +from ctrack.register.models import MeetingEvent, EventType, SingleDateTimeEvent pytestmark = pytest.mark.django_db @@ -39,6 +39,34 @@ def test_meeting_event(person, user): assert person in e.participants.all() assert e.user.name == uname assert e.created_date.day == now.day - assert e.created_date.hour == now.hour assert e.modified_date.day == now.day - assert e.modified_date.hour == now.hour + + +def test_single_date_event(person, user): + """This tests for phone call, video call and email events""" + now = datetime.datetime.now() + phone_event = SingleDateTimeEvent.objects.create( + type_descriptor="Phone Call", + short_description="Important Phone Call", + datetime="2020-10-10T15:00", + comments="Comments on phone call", + # location is optional + user=user + ) + phone_event.participants.add(person) + assert phone_event.type_descriptor == "Phone Call" + assert person in phone_event.participants.all() + assert phone_event.created_date.day == now.day + + video_event = SingleDateTimeEvent.objects.create( + type_descriptor="Video Call", + short_description="Important Video Call", + datetime="2020-10-10T15:00", + comments="Comments on phone call", + # location is optional + user=user + ) + video_event.participants.add(person) + assert video_event.type_descriptor == "Video Call" + assert person in video_event.participants.all() + assert video_event.created_date.day == now.day diff --git a/ctrack/register/tests/test_forms.py b/ctrack/register/tests/test_forms.py index 0383fa3..9a0f541 100644 --- a/ctrack/register/tests/test_forms.py +++ b/ctrack/register/tests/test_forms.py @@ -5,6 +5,9 @@ from ..forms import AddMeetingForm pytestmark = pytest.mark.django_db +# TODO this test and the form code needs to be amended to save created_by and update_by +# on the model + def test_init(user): """Here we test that we can pass in the user value from the view. We don't want that to be field in the form. |