From eb8497dcd3758d20447d4de977780c2c78a38613 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 16 Oct 2020 11:05:42 +0100 Subject: Improvements to simple event form. --- ctrack/register/forms.py | 2 + ctrack/register/models.py | 14 ++ .../templates/single_datetime_event_create.html | 5 +- ctrack/register/tests/test_event_models.py | 219 ------------------- ctrack/register/tests/test_forms.py | 16 ++ ctrack/register/tests/test_models.py | 234 +++++++++++++++++++++ 6 files changed, 270 insertions(+), 220 deletions(-) delete mode 100644 ctrack/register/tests/test_event_models.py create mode 100644 ctrack/register/tests/test_models.py diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py index 85a450e..adb154f 100644 --- a/ctrack/register/forms.py +++ b/ctrack/register/forms.py @@ -21,8 +21,10 @@ class CreateSimpleDateTimeEventForm(forms.ModelForm): model = SingleDateTimeEvent fields = [ "type_descriptor", + "private", "short_description", "datetime", + "participants", "requested_response_date", "response_received_date", "url", diff --git a/ctrack/register/models.py b/ctrack/register/models.py index 3ab760e..11e4a6b 100644 --- a/ctrack/register/models.py +++ b/ctrack/register/models.py @@ -17,6 +17,7 @@ class EventType(Enum): PHONE_CALL = auto() VIDEO_CALL = auto() EMAIL = auto() + NOTE = auto() # single date caf events CAF_INITIAL_CAF_RECEIVED = auto() CAF_FEEDBACK_EMAILED_OES = auto() @@ -157,18 +158,31 @@ class ResponseRequiredMixin(models.Model): abstract = True +class PrivateEventMixin(models.Model): + private = models.BooleanField( + default=False, help_text="Private events can only be seen by you. Official records should " + "not be private, but you can use private events to track your own " + "work." + ) + + class Meta: + abstract = True + + class SingleDateTimeEvent( EventBase, ResponseRequiredMixin, URLEventMixin, ThirdPartyEventMixin, SingleDateTimeEventMixin, + PrivateEventMixin, ): AVAILABLE_TYPES = [ (EventType.MEETING.name, "Meeting"), (EventType.PHONE_CALL.name, "Phone Call"), (EventType.VIDEO_CALL.name, "Video Call"), (EventType.EMAIL.name, "Email"), + (EventType.NOTE.name, "Note"), ] type_descriptor = models.CharField( blank=False, max_length=50, choices=AVAILABLE_TYPES diff --git a/ctrack/register/templates/single_datetime_event_create.html b/ctrack/register/templates/single_datetime_event_create.html index f663dac..6e607be 100644 --- a/ctrack/register/templates/single_datetime_event_create.html +++ b/ctrack/register/templates/single_datetime_event_create.html @@ -4,7 +4,10 @@ {% load crispy_forms_tags %} {% block form %} -

Create a new Simple Event (Meeting, Phone call, Email)

+

Create a new simple event

+

Simple events are emails, phone calls, basic meetings, notes, deadlines, etc. + If you arrived at this page from an organisation's page, you are able to select + participants in the event from that organisation.

{% csrf_token %} {{ form|crispy }} diff --git a/ctrack/register/tests/test_event_models.py b/ctrack/register/tests/test_event_models.py deleted file mode 100644 index e92b282..0000000 --- a/ctrack/register/tests/test_event_models.py +++ /dev/null @@ -1,219 +0,0 @@ -import datetime - -import pytest -from django.db import IntegrityError - -from ctrack.register.models import ( - EventType, - SingleDateTimeEvent, - CAFSingleDateEvent, - CAFTwinDateEvent, -) - -pytestmark = pytest.mark.django_db - - -@pytest.mark.parametrize( - "allowed_type", - [ - "CAF_INITIAL_CAF_RECEIVED", - "CAF_FEEDBACK_EMAILED_OES", - "CAF_RECEIVED", - "CAF_EMAILED_ROSA", - "CAF_VALIDATION_SIGN_OFF", - "CAF_VALIDATION_RECORD_EMAILED_TO_OES", - ], -) -def test_caf_single_date_events(allowed_type, user, caf): - now = datetime.datetime.now() - e = CAFSingleDateEvent.objects.create( - type_descriptor=allowed_type, - related_caf=caf, - short_description="CAF received for X Company", - date="2020-10-10", - comments="Nice comments for this event", - user=user, - ) - assert e.created_date.day == now.day - 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 - - -@pytest.mark.parametrize( - "allowed_type", ["CAF_PEER_REVIEW_PERIOD", "CAF_VALIDATION_PERIOD"] -) -def test_caf_twin_date_event_no_end_date(allowed_type, user, caf): - e = CAFTwinDateEvent.objects.create( - type_descriptor=allowed_type, - related_caf=caf, - short_description="CAF received for X Company", - start_date="2020-10-10", - comments="Nice comments for this event", - user=user, - ) - assert e.end_date is None - - -@pytest.mark.parametrize( - "allowed_type", ["CAF_PEER_REVIEW_PERIOD", "CAF_VALIDATION_PERIOD"] -) -def test_caf_twin_date_event_no_start_date_not_allowed(allowed_type, user, caf): - with pytest.raises(IntegrityError): - CAFTwinDateEvent.objects.create( - type_descriptor=allowed_type, - related_caf=caf, - short_description="CAF received for X Company", - end_date="2020-10-10", - comments="Nice comments for this event", - user=user, - ) - - -def test_cannot_add_two_caf_initial_caf_received_events_on_same_date(user, caf): - CAFSingleDateEvent.objects.create( - type_descriptor="CAF_INITIAL_CAF_RECEIVED", - related_caf=caf, - short_description="CAF received for X Company", - date="2020-10-10", - comments="Nice comments for this event", - user=user, - ) - with pytest.raises(IntegrityError): - CAFSingleDateEvent.objects.create( - type_descriptor="CAF_INITIAL_CAF_RECEIVED", - related_caf=caf, - short_description="CAF received for X Company", - date="2020-10-10", - comments="Nice comments for this event", - user=user, - ) - - -def test_can_email_two_caf_on_same_date(user, caf): - CAFSingleDateEvent.objects.create( - type_descriptor="CAF_EMAILED_ROSA", - related_caf=caf, - short_description="CAF sent to Rosa for X Company", - date="2020-10-10", - comments="Nice comments for this event", - user=user, - ) - CAFSingleDateEvent.objects.create( - type_descriptor="CAF_EMAILED_ROSA", - related_caf=caf, - short_description="CAF sent to Rosa for X Company", - date="2020-10-10", - comments="Nice comments for this event", - user=user, - ) - - -def test_cannot_receive_the_same_caf_on_the_same_day(user, caf): - CAFSingleDateEvent.objects.create( - type_descriptor="CAF_RECEIVED", - related_caf=caf, - short_description="CAF received to Rosa for X Company", - date="2020-10-10", - comments="Nice comments for this event", - user=user, - ) - with pytest.raises(IntegrityError): - CAFSingleDateEvent.objects.create( - type_descriptor="CAF_RECEIVED", - related_caf=caf, - short_description="CAF received to Rosa for X Company", - date="2020-10-10", - comments="Nice comments for this event", - user=user, - ) - - -def test_event_type_enum(): - assert EventType.MEETING.name == "MEETING" - assert EventType.PHONE_CALL.name == "PHONE_CALL" - assert EventType.VIDEO_CALL.name == "VIDEO_CALL" - assert EventType.EMAIL.name == "EMAIL" - assert EventType.CAF_INITIAL_CAF_RECEIVED.name == "CAF_INITIAL_CAF_RECEIVED" - assert EventType.CAF_FEEDBACK_EMAILED_OES.name == "CAF_FEEDBACK_EMAILED_OES" - assert EventType.CAF_RECEIVED.name == "CAF_RECEIVED" - assert EventType.CAF_EMAILED_ROSA.name == "CAF_EMAILED_ROSA" - assert EventType.CAF_PEER_REVIEW_PERIOD.name == "CAF_PEER_REVIEW_PERIOD" - assert EventType.CAF_VALIDATION_PERIOD.name == "CAF_VALIDATION_PERIOD" - assert EventType.CAF_VALIDATION_SIGN_OFF.name == "CAF_VALIDATION_SIGN_OFF" - assert ( - EventType.CAF_VALIDATION_RECORD_EMAILED_TO_OES.name - == "CAF_VALIDATION_RECORD_EMAILED_TO_OES" - ) - - -@pytest.mark.parametrize("allowed_type", ["PHONE_CALL", "MEETING", "VIDEO_CALL", "EMAIL"]) -def test_single_datetime_event(person, user, allowed_type): - """This tests for phone call, video call and email events""" - now = datetime.datetime.now() - event = SingleDateTimeEvent.objects.create( - type_descriptor=allowed_type, - short_description="Important event", - url = "http://fake.url.com", - requested_response_date="2021-01-24", - response_received_date=None, - datetime="2020-10-10T15:00", - comments="Comments on important event", - # location is optional - user=user, - ) - event.participants.add(person) - assert event.type_descriptor == allowed_type - assert person in event.participants.all() - assert event.created_date.day == now.day - - -@pytest.mark.parametrize( - "allowed_type", ["CAF_PEER_REVIEW_PERIOD", "CAF_VALIDATION_PERIOD", "VIDEO_CALL"] -) -def test_cannot_create_twin_date_event_model_end_date_precedes_start(allowed_type, user, caf): - with pytest.raises(IntegrityError): - CAFTwinDateEvent.objects.create( - type_descriptor=allowed_type, - 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() - e = SingleDateTimeEvent.objects.create( - type_descriptor="Meeting", - short_description="Big Important Meeting", - datetime="2020-10-10T15:00", - comments="Nice comments", - location="Harvey's House", - user=user, - ) - e.participants.add(person) - assert len(e.participants.all()) == 1 - assert e.type_descriptor == "Meeting" - assert person in e.participants.all() - assert e.user.name == uname - assert e.created_date.day == now.day - assert e.modified_date.day == now.day diff --git a/ctrack/register/tests/test_forms.py b/ctrack/register/tests/test_forms.py index ac21abb..2307a20 100644 --- a/ctrack/register/tests/test_forms.py +++ b/ctrack/register/tests/test_forms.py @@ -60,6 +60,22 @@ def test_create_simple_datetime_event(user): assert form.is_valid() +def test_create_private_note(user): + form = CreateSimpleDateTimeEventForm( + { + "type_descriptor": "NOTE", + "short_description": "Test Short Description", + "datetime": "2010-10-10 10:00", + "requested_response_date": "2020-12-24", + "response_received_date": "2020-12-25", + "url": "https://fake.url.com", + "private": True, + "comments": "Test Comments not needed" + }, user=user, + ) + assert form.is_valid() + + def test_response_date_cannot_be_before_date(user): form = CreateSimpleDateTimeEventForm( { diff --git a/ctrack/register/tests/test_models.py b/ctrack/register/tests/test_models.py new file mode 100644 index 0000000..1f8923b --- /dev/null +++ b/ctrack/register/tests/test_models.py @@ -0,0 +1,234 @@ +import datetime + +import pytest +from django.db import IntegrityError + +from ctrack.register.models import ( + EventType, + SingleDateTimeEvent, + CAFSingleDateEvent, + CAFTwinDateEvent, +) + +pytestmark = pytest.mark.django_db + + +@pytest.mark.parametrize( + "allowed_type", + [ + "CAF_INITIAL_CAF_RECEIVED", + "CAF_FEEDBACK_EMAILED_OES", + "CAF_RECEIVED", + "CAF_EMAILED_ROSA", + "CAF_VALIDATION_SIGN_OFF", + "CAF_VALIDATION_RECORD_EMAILED_TO_OES", + ], +) +def test_caf_single_date_events(allowed_type, user, caf): + now = datetime.datetime.now() + e = CAFSingleDateEvent.objects.create( + type_descriptor=allowed_type, + related_caf=caf, + short_description="CAF received for X Company", + date="2020-10-10", + comments="Nice comments for this event", + user=user, + ) + assert e.created_date.day == now.day + 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 + + +@pytest.mark.parametrize( + "allowed_type", ["CAF_PEER_REVIEW_PERIOD", "CAF_VALIDATION_PERIOD"] +) +def test_caf_twin_date_event_no_end_date(allowed_type, user, caf): + e = CAFTwinDateEvent.objects.create( + type_descriptor=allowed_type, + related_caf=caf, + short_description="CAF received for X Company", + start_date="2020-10-10", + comments="Nice comments for this event", + user=user, + ) + assert e.end_date is None + + +@pytest.mark.parametrize( + "allowed_type", ["CAF_PEER_REVIEW_PERIOD", "CAF_VALIDATION_PERIOD"] +) +def test_caf_twin_date_event_no_start_date_not_allowed(allowed_type, user, caf): + with pytest.raises(IntegrityError): + CAFTwinDateEvent.objects.create( + type_descriptor=allowed_type, + related_caf=caf, + short_description="CAF received for X Company", + end_date="2020-10-10", + comments="Nice comments for this event", + user=user, + ) + + +def test_cannot_add_two_caf_initial_caf_received_events_on_same_date(user, caf): + CAFSingleDateEvent.objects.create( + type_descriptor="CAF_INITIAL_CAF_RECEIVED", + related_caf=caf, + short_description="CAF received for X Company", + date="2020-10-10", + comments="Nice comments for this event", + user=user, + ) + with pytest.raises(IntegrityError): + CAFSingleDateEvent.objects.create( + type_descriptor="CAF_INITIAL_CAF_RECEIVED", + related_caf=caf, + short_description="CAF received for X Company", + date="2020-10-10", + comments="Nice comments for this event", + user=user, + ) + + +def test_can_email_two_caf_on_same_date(user, caf): + CAFSingleDateEvent.objects.create( + type_descriptor="CAF_EMAILED_ROSA", + related_caf=caf, + short_description="CAF sent to Rosa for X Company", + date="2020-10-10", + comments="Nice comments for this event", + user=user, + ) + CAFSingleDateEvent.objects.create( + type_descriptor="CAF_EMAILED_ROSA", + related_caf=caf, + short_description="CAF sent to Rosa for X Company", + date="2020-10-10", + comments="Nice comments for this event", + user=user, + ) + + +def test_cannot_receive_the_same_caf_on_the_same_day(user, caf): + CAFSingleDateEvent.objects.create( + type_descriptor="CAF_RECEIVED", + related_caf=caf, + short_description="CAF received to Rosa for X Company", + date="2020-10-10", + comments="Nice comments for this event", + user=user, + ) + with pytest.raises(IntegrityError): + CAFSingleDateEvent.objects.create( + type_descriptor="CAF_RECEIVED", + related_caf=caf, + short_description="CAF received to Rosa for X Company", + date="2020-10-10", + comments="Nice comments for this event", + user=user, + ) + + +def test_event_type_enum(): + assert EventType.MEETING.name == "MEETING" + assert EventType.PHONE_CALL.name == "PHONE_CALL" + assert EventType.VIDEO_CALL.name == "VIDEO_CALL" + assert EventType.EMAIL.name == "EMAIL" + assert EventType.NOTE.name == "NOTE" + assert EventType.CAF_INITIAL_CAF_RECEIVED.name == "CAF_INITIAL_CAF_RECEIVED" + assert EventType.CAF_FEEDBACK_EMAILED_OES.name == "CAF_FEEDBACK_EMAILED_OES" + assert EventType.CAF_RECEIVED.name == "CAF_RECEIVED" + assert EventType.CAF_EMAILED_ROSA.name == "CAF_EMAILED_ROSA" + assert EventType.CAF_PEER_REVIEW_PERIOD.name == "CAF_PEER_REVIEW_PERIOD" + assert EventType.CAF_VALIDATION_PERIOD.name == "CAF_VALIDATION_PERIOD" + assert EventType.CAF_VALIDATION_SIGN_OFF.name == "CAF_VALIDATION_SIGN_OFF" + assert ( + EventType.CAF_VALIDATION_RECORD_EMAILED_TO_OES.name + == "CAF_VALIDATION_RECORD_EMAILED_TO_OES" + ) + + +@pytest.mark.parametrize("allowed_type", ["PHONE_CALL", "MEETING", "VIDEO_CALL", "EMAIL"]) +def test_single_datetime_event(person, user, allowed_type): + """This tests for phone call, video call and email events""" + now = datetime.datetime.now() + event = SingleDateTimeEvent.objects.create( + type_descriptor=allowed_type, + short_description="Important event", + url = "http://fake.url.com", + requested_response_date="2021-01-24", + response_received_date=None, + datetime="2020-10-10T15:00", + comments="Comments on important event", + # location is optional + user=user, + ) + event.participants.add(person) + assert event.type_descriptor == allowed_type + assert person in event.participants.all() + assert event.created_date.day == now.day + + +@pytest.mark.parametrize( + "allowed_type", ["CAF_PEER_REVIEW_PERIOD", "CAF_VALIDATION_PERIOD", "VIDEO_CALL"] +) +def test_cannot_create_twin_date_event_model_end_date_precedes_start(allowed_type, user, caf): + with pytest.raises(IntegrityError): + CAFTwinDateEvent.objects.create( + type_descriptor=allowed_type, + 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() + e = SingleDateTimeEvent.objects.create( + type_descriptor="Meeting", + short_description="Big Important Meeting", + datetime="2020-10-10T15:00", + comments="Nice comments", + location="Harvey's House", + user=user, + ) + e.participants.add(person) + assert len(e.participants.all()) == 1 + assert e.type_descriptor == "Meeting" + assert person in e.participants.all() + assert e.user.name == uname + assert e.created_date.day == now.day + assert e.modified_date.day == now.day + + +@pytest.mark.parametrize("allowed_type", ["NOTE"]) +def test_note_event(user, allowed_type): + e = SingleDateTimeEvent.objects.create( + type_descriptor=allowed_type, + short_description="Test short description", + datetime="2020-10-10 10:30", + comments="The guy I deal with at X Co Ltd is made of cheese,", + url="https://evidenceofcheese.com", + private=True, + user=user + ) + assert e.type_descriptor == allowed_type -- cgit v1.2.3