Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Evenement] patch #1 - mois sans evenement #437

Merged
merged 5 commits into from
Oct 16, 2023
Merged
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
37 changes: 28 additions & 9 deletions lacommunaute/event/tests/tests_views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lacommunaute/event/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions lacommunaute/templates/event/event_archive_month.html
Original file line number Diff line number Diff line change
@@ -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 %}
Expand Down