Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions apps/events/templates/events/includes/time_tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
{{ next_time.dt_start|date:"Y" }}
</span>

<span id="start-{{ object.id }}"{% if scheduled_end_this_year %} class="say-no-more"{% endif %}>
{{ next_time.dt_start|date:"Y" }}
</span>

{% if not next_time.all_day %}
{{ next_time.dt_start|date:"fA"|lower }} {{ next_time.dt_start|date:"e" }}
{% if next_time.valid_dt_end %} – {{ next_time.dt_end|date:"fA"|lower }}
Expand Down
52 changes: 52 additions & 0 deletions apps/events/tests/test_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import datetime

from django.template.loader import render_to_string
from django.test import TestCase

from ..models import Event, EventLocation, Calendar

Check failure on line 6 in apps/events/tests/test_templates.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (TID252)

apps/events/tests/test_templates.py:6:1: TID252 Prefer absolute imports over relative imports

Check failure on line 6 in apps/events/tests/test_templates.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (TID252)

apps/events/tests/test_templates.py:6:1: TID252 Prefer absolute imports over relative imports
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test uses a relative import (from ..models ...), but the repo’s Ruff config bans all relative imports (flake8-tidy-imports). This will fail lint; switch to absolute imports (e.g., from apps.events.models import ...). Also EventLocation is imported but unused, which will trigger F401.

Suggested change
from ..models import Event, EventLocation, Calendar
from apps.events.models import Event, Calendar

Copilot uses AI. Check for mistakes.


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

Check failure on line 15 in apps/events/tests/test_templates.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (DTZ011)

apps/events/tests/test_templates.py:15:23: DTZ011 `datetime.date.today()` used

calendar = Calendar.objects.create(name="Test Calendar")
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calendar.slug is a required field (non-null, non-blank). Creating a Calendar with only name will raise an integrity/validation error when the test runs. Provide a unique slug (and optionally creator like other tests do).

Suggested change
calendar = Calendar.objects.create(name="Test Calendar")
calendar = Calendar.objects.create(
name="Test Calendar",
slug="test-calendar-time-tag-single-day-event",
)

Copilot uses AI. Check for mistakes.

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)

Check failure on line 28 in apps/events/tests/test_templates.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (DTZ001)

apps/events/tests/test_templates.py:28:33: DTZ001 `datetime.datetime()` called without a `tzinfo` argument
self.dt_end = datetime.datetime(future_year, 5, 25, 14, 0)

Check failure on line 29 in apps/events/tests/test_templates.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (DTZ001)

apps/events/tests/test_templates.py:29:31: DTZ001 `datetime.datetime()` called without a `tzinfo` argument
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}"
)
Loading