From 58f026c7e23d4fab7d4fd8f52dd93564deb044c7 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 9 Oct 2020 16:16:09 +0100 Subject: tests up --- ctrack/register/tests/test_engagement_events.py | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 ctrack/register/tests/test_engagement_events.py (limited to 'ctrack/register') diff --git a/ctrack/register/tests/test_engagement_events.py b/ctrack/register/tests/test_engagement_events.py new file mode 100644 index 0000000..426603c --- /dev/null +++ b/ctrack/register/tests/test_engagement_events.py @@ -0,0 +1,52 @@ +import pytest +from django.db import models + +from ctrack.organisations.models import Person +from ctrack.register.models import EngagementType +from ctrack.register.tests.factories import EngagementTypeFactory + +pytestmark = pytest.mark.django_db + + +def event_type(): + return EngagementTypeFactory.create(descriptor="CAF type") + + +class EngagementEventBase(models.Model): + type = models.ForeignKey(EngagementType, on_delete=models.CASCADE) + 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) + + class Meta: + 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) + + +def test_event_inheritance(): + caf_single_date_event = SingleDateCAFEvent.objects.create( + short_description="Test Short Description", date="2010-10-10" + ) + assert isinstance(caf_single_date_event.type, EngagementType) + assert caf_single_date_event.short_description == "Test Short Description" + assert caf_single_date_event.caf_related is True + assert len(caf_single_date_event.participants.all()) == 0 + assert caf_single_date_event.date == "2010-10-10" + assert caf_single_date_event.document_link is None + assert caf_single_date_event.response_date_requested is None -- cgit v1.2.3