From 65b80f334fd26911a7427eef27b0b778dcb9cea8 Mon Sep 17 00:00:00 2001 From: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> Date: Sun, 5 Nov 2023 18:16:22 +0100 Subject: [PATCH] Distinguish between upcoming and past events. --- .github/workflows/tests.yml | 28 ++++++++ home/static/css/events.css | 5 ++ home/static/img/no_data.svg | 1 + .../templates/home/prerelease/event_list.html | 25 ++++++- .../home/prerelease/session_list.html | 4 +- home/tests/__init__.py | 0 home/tests/test_event_list.py | 68 +++++++++++++++++++ home/views.py | 9 ++- requirements/requirements-test.txt | 6 +- 9 files changed, 133 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/tests.yml create mode 100644 home/static/img/no_data.svg create mode 100644 home/tests/__init__.py create mode 100644 home/tests/test_event_list.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..4729960f --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,28 @@ +name: Run tests + +on: + pull_request: + +jobs: + build: + env: + ENVIRONMENT: 'dev' + DJANGO_SETTINGS_MODULE: 'indymeet.settings.dev' + SECRET_KEY: ${{ secrets.SECRET_KEY }} + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python version + uses: actions/setup-python@v2 + with: + python-version: '3.9' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements/requirements-test.txt + + - name: Run tests + run: python manage.py test diff --git a/home/static/css/events.css b/home/static/css/events.css index f1ccfc41..3c1b83a4 100644 --- a/home/static/css/events.css +++ b/home/static/css/events.css @@ -18,3 +18,8 @@ width: 100%; height: 150px; } + +.no-data-img { + width: 100%; + height: 150px; +} diff --git a/home/static/img/no_data.svg b/home/static/img/no_data.svg new file mode 100644 index 00000000..4e5f0608 --- /dev/null +++ b/home/static/img/no_data.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/home/templates/home/prerelease/event_list.html b/home/templates/home/prerelease/event_list.html index 58a883d0..5ff42c09 100644 --- a/home/templates/home/prerelease/event_list.html +++ b/home/templates/home/prerelease/event_list.html @@ -14,8 +14,8 @@
-

Events

-
+

Events

+

These events are open to the public and free to attend. We'd love to meet you, so come say hi!

@@ -27,10 +27,29 @@

Events

{% endif %}
+

Upcoming Events

- {% for event in events %} + {% for event in upcoming_events %} {% include 'home/includes/event_card.html' %} + {% empty %} +
+ No data image +

No upcoming events.

+
+ {% endfor %} + +
+

Past Events

+
+ + {% for event in past_events %} + {% include 'home/includes/event_card.html' %} + {% empty %} +
+ No data image +

No past events.

+
{% endfor %}
diff --git a/home/templates/home/prerelease/session_list.html b/home/templates/home/prerelease/session_list.html index 209ace81..67550e65 100644 --- a/home/templates/home/prerelease/session_list.html +++ b/home/templates/home/prerelease/session_list.html @@ -14,8 +14,8 @@ {% block content %}
-

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