Events
-Events
+These events are open to the public and free to attend. We'd love to meet you, so come say hi!
Events
{% endif %}Upcoming Events
No upcoming events.
+Past Events
+No past events.
+Program Sessions
-Sessions
+These sessions are limited to those who are accepted from an application diff --git a/home/tests/__init__.py b/home/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/home/tests/test_event_list.py b/home/tests/test_event_list.py new file mode 100644 index 00000000..88b878e0 --- /dev/null +++ b/home/tests/test_event_list.py @@ -0,0 +1,68 @@ +from datetime import datetime, timezone + +from django.test import Client, TestCase +from django.urls import reverse +from freezegun import freeze_time + +from home.models import Event + + +@freeze_time("2012-01-14") +class EventListViewTests(TestCase): + def setUp(self): + self.client = Client() + + @staticmethod + def create_upcoming_event(): + return Event.objects.create( + title="Testathon 5.0", + slug="testathon-5", + start_time=datetime(2023, 2, 1, 10, 0, tzinfo=timezone.utc), + end_time=datetime(2023, 2, 1, 11, 0, tzinfo=timezone.utc), + location="zoom", + status=Event.SCHEDULED, + ) + + @staticmethod + def create_past_event(): + return Event.objects.create( + title="Coffee Chat", + slug="coffee-chat", + start_time=datetime(2010, 2, 1, 10, 0, tzinfo=timezone.utc), + end_time=datetime(2010, 2, 1, 11, 0, tzinfo=timezone.utc), + location="zoom", + status=Event.SCHEDULED, + ) + + def test_no_events(self): + url = reverse("event_list") + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed("home/prerelease/event_list.html") + self.assertContains(response, "No upcoming events.") + self.assertContains(response, "No past events.") + + def test_upcoming_events_no_past(self): + upcoming_event = self.create_upcoming_event() + url = reverse("event_list") + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed("home/prerelease/event_list.html") + self.assertNotContains(response, "No upcoming events.") + self.assertContains(response, "No past events.") + self.assertContains(response, upcoming_event.title) + self.assertContains(response, upcoming_event.get_absolute_url()) + + def test_upcoming_events_and_past(self): + upcoming_event = self.create_upcoming_event() + past_event = self.create_past_event() + url = reverse("event_list") + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed("home/prerelease/event_list.html") + self.assertNotContains(response, "No upcoming events.") + self.assertNotContains(response, "No past events.") + self.assertContains(response, upcoming_event.title) + self.assertContains(response, upcoming_event.get_absolute_url()) + self.assertContains(response, past_event.title) + self.assertContains(response, past_event.get_absolute_url()) diff --git a/home/views.py b/home/views.py index 73985640..b1afbc49 100644 --- a/home/views.py +++ b/home/views.py @@ -56,13 +56,16 @@ class EventListView(ListView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - events = Event.objects.visible().order_by("-start_time") + upcoming_events = Event.objects.visible().upcoming().order_by("-start_time") + past_events = Event.objects.visible().past().order_by("-start_time") tag = self.request.GET.get("tag") if tag: - events = events.filter(tags__name=tag) + upcoming_events = upcoming_events.filter(tags__name=tag) + past_events = past_events.filter(tags__name=tag) - context["events"] = events + context["upcoming_events"] = upcoming_events + context["past_events"] = past_events context["tags"] = self.get_event_tags() context["current_tag"] = tag return context diff --git a/requirements/requirements-test.txt b/requirements/requirements-test.txt index e5cf0870..7d79aaf5 100644 --- a/requirements/requirements-test.txt +++ b/requirements/requirements-test.txt @@ -1,6 +1,2 @@ -r requirements.txt -pytest -pytest-cov -pytest-django -pytest-django -tox +freezegun