-
-
Notifications
You must be signed in to change notification settings - Fork 669
Expand file tree
/
Copy pathtest_templates.py
More file actions
55 lines (45 loc) · 2.09 KB
/
test_templates.py
File metadata and controls
55 lines (45 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import datetime
from django.template.loader import render_to_string
from django.test import TestCase
from apps.events.models import Event, Calendar
class TimeTagTemplateTests(TestCase):
def test_single_day_event_year_rendering(self):
"""
Verify that a single-day event does not render the year twice (Issue #2626).
"""
# Create a single day event in the future to trigger the year rendering condition
future_year = datetime.date.today().year + 1
calendar = Calendar.objects.create(
name="Test Calendar",
slug="test-calendar-time-tag-single-day-event",
)
event = Event.objects.create(
title="Single Day Future Event",
description="Test event",
calendar=calendar,
)
# Manually create the next_time context object
class MockTime:
def __init__(self):
self.dt_start = datetime.datetime(future_year, 5, 25, 12, 0)
self.dt_end = datetime.datetime(future_year, 5, 25, 14, 0)
self.single_day = True
self.all_day = False
self.valid_dt_end = True
context = {
"next_time": MockTime(),
"scheduled_start_this_year": False, # Event is in the future year
"scheduled_end_this_year": False,
"object": event,
}
rendered = render_to_string("events/includes/time_tag.html", context)
# The year should only appear visibly once in the output (not counting the datetime ISO tag).
year_str = str(future_year)
# Using string splitting to exclude the `datetime="2027...` occurrence by checking how many times
# it appears wrapped with whitespace or inside a span.
visible_occurrences = rendered.split(">\n " + year_str + "\n </span>")
self.assertEqual(
len(visible_occurrences) - 1,
1,
f"Expected the visible span containing {year_str} to appear exactly once, but it was duplicated: {rendered}"
)