From 8868c0b5ef777d13942bb0ffb8e8874d521bf283 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 15 Aug 2024 23:56:03 -0400 Subject: [PATCH] membershipworks: Add basic tests for validity of Event financial queries --- membershipworks/tests.py | 67 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/membershipworks/tests.py b/membershipworks/tests.py index a39b155..24d764d 100644 --- a/membershipworks/tests.py +++ b/membershipworks/tests.py @@ -1 +1,66 @@ -# Create your tests here. +from datetime import datetime + +from django.db.models.functions import TruncYear +from django.test import TestCase +from django.utils import timezone + +from membershipworks.models import ( + Event, + EventCategory, + EventExt, + EventInstructor, + EventTicketType, + Flag, +) + + +class EventFinancials(TestCase): + def setUp(self) -> None: + members_folder = Flag.objects.create( + id="members_folder_flag", name="Members", type="folder" + ) + instructor = EventInstructor.objects.create(name="instructor1") + category = EventCategory.objects.create(id=1, title="cat1") + EventExt.objects.create( + eid="event1", + url="", + title="Test Event 1", + instructor=instructor, + materials_fee=10, + materials_fee_included_in_price=True, + instructor_percentage=0.5, + start=datetime(2024, 1, 1, 18, 0, tzinfo=timezone.get_default_timezone()), + end=datetime(2024, 1, 1, 21, 0, tzinfo=timezone.get_default_timezone()), + count=10, + category=category, + calendar=Event.EventCalendar.PURPLE, + details={ + "tkt": [ + { + "id": 1, + "lbl": "tkt1", + "amt": 123.4, + "cnt": 1, + "dsp": [members_folder.id], + } + ], + "usr": [{"sum": 123.4}], + }, + ) + + def test_ticket_type_annotations(self): + # TODO: test for correctness + list(EventTicketType.objects.all()) + + def test_with_financials(self): + # TODO: test for correctness + list(EventExt.objects.with_financials().all()) + + def test_with_financials_summary(self): + # TODO: test for correctness + list( + EventExt.objects.with_financials() + .values(year=TruncYear("start")) + .summarize() + .order_by("year") + )