membershipworks: Add basic tests for validity of Event financial queries

This commit is contained in:
Adam Goldsmith 2024-08-15 23:56:03 -04:00
parent 5ddecaaea8
commit 8868c0b5ef

View File

@ -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")
)