diff --git a/lacommunaute/event/tests/tests_views.py b/lacommunaute/event/tests/tests_views.py index eff6dc04b..0a33c95b1 100644 --- a/lacommunaute/event/tests/tests_views.py +++ b/lacommunaute/event/tests/tests_views.py @@ -1,9 +1,11 @@ from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta +from django.conf import settings from django.test import TestCase from django.urls import reverse -from django.utils import timezone +from django.utils import timezone, translation +from django.utils.formats import date_format from faker import Faker from lacommunaute.event.factories import EventFactory @@ -222,22 +224,39 @@ def test_view_wo_args(self): self.assertContains(response, reverse("event:create")) def test_view_with_args(self): + event = EventFactory(date=timezone.now()) + old_event = EventFactory(date=timezone.now() - relativedelta(months=1)) + response = self.client.get( + reverse("event:month", kwargs={"year": old_event.date.year, "month": old_event.date.month}) + ) + self.assertNotContains(response, event.name, status_code=200) + self.assertContains(response, old_event.name, status_code=200) + + def test_allow_future(self): event = EventFactory(date=timezone.now() + relativedelta(months=1)) response = self.client.get(reverse("event:month", kwargs={"year": event.date.year, "month": event.date.month})) self.assertContains(response, event.name, status_code=200) + def test_allow_empty(self): + response = self.client.get(reverse("event:month", kwargs={"year": 2000, "month": 1})) + self.assertContains(response, "Aucun évènement", status_code=200, html=True) + def test_navbar(self): - event = EventFactory(date=timezone.now()) - event_in_the_future = EventFactory(date=event.date + relativedelta(months=1)) - event_in_the_past = EventFactory(date=event.date - relativedelta(months=1)) - response = self.client.get(reverse("event:current")) + with translation.override(settings.LANGUAGE_CODE): + current_date = timezone.now() + next_month = current_date + relativedelta(months=1) + previous_month = current_date - relativedelta(months=1) + + response = self.client.get(reverse("event:current")) + self.assertContains(response, date_format(current_date, "F Y"), status_code=200) + self.assertContains( response, reverse( "event:month", kwargs={ - "year": event_in_the_past.date.year, - "month": f"{event_in_the_past.date.month:02d}", + "year": previous_month.year, + "month": f"{previous_month.month:02d}", }, ), status_code=200, @@ -247,8 +266,8 @@ def test_navbar(self): reverse( "event:month", kwargs={ - "year": event_in_the_future.date.year, - "month": f"{event_in_the_future.date.month:02d}", + "year": next_month.year, + "month": f"{next_month.month:02d}", }, ), status_code=200, diff --git a/lacommunaute/event/views.py b/lacommunaute/event/views.py index ab4d948ed..91143afc5 100644 --- a/lacommunaute/event/views.py +++ b/lacommunaute/event/views.py @@ -72,6 +72,7 @@ class EventDetailView(DetailView): class EventMonthArchiveView(MonthArchiveView): allow_future = True + allow_empty = True date_field = "date" queryset = Event.objects.all() month_format = "%m" diff --git a/lacommunaute/templates/event/event_archive_month.html b/lacommunaute/templates/event/event_archive_month.html index 94eb24e8a..04cce29db 100644 --- a/lacommunaute/templates/event/event_archive_month.html +++ b/lacommunaute/templates/event/event_archive_month.html @@ -1,6 +1,7 @@ {% extends "layouts/base.html" %} {% load i18n %} +{% block title %}{% trans "Events" %}{{ block.super }}{% endblock %} {% block sub_title %}{% trans "Events" %} {{ month }}{% endblock sub_title %} {% block content %}