Skip to content

Commit

Permalink
Distinguish between upcoming and past events.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahboyce committed Nov 5, 2023
1 parent a61e961 commit 65b80f3
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 13 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions home/static/css/events.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@
width: 100%;
height: 150px;
}

.no-data-img {
width: 100%;
height: 150px;
}
1 change: 1 addition & 0 deletions home/static/img/no_data.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 22 additions & 3 deletions home/templates/home/prerelease/event_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<main class="section">

<div class="container-lg">
<h3>Events</h3>
<div class="row">
<h1>Events</h1>
<div class="row pt-4 pb-4">
<div class="col">
<p>These events are open to the public and free to attend. We'd love to meet you, so come say hi!</p>
</div>
Expand All @@ -27,10 +27,29 @@ <h3>Events</h3>
{% endif %}
</div>
</div>
<h2>Upcoming Events</h2>
<div class="g-2 g-lg-3 row row-cols-4 justify-content-evenly pt-4">

{% for event in events %}
{% for event in upcoming_events %}
{% include 'home/includes/event_card.html' %}
{% empty %}
<div class="text-center">
<img alt="No data image" class="no-data-img" src="{% static 'img/no_data.svg' %}" />
<p class="pt-4">No upcoming events.</p>
</div>
{% endfor %}

</div>
<h2>Past Events</h2>
<div class="g-2 g-lg-3 row row-cols-4 justify-content-evenly pt-4">

{% for event in past_events %}
{% include 'home/includes/event_card.html' %}
{% empty %}
<div class="text-center">
<img alt="No data image" class="no-data-img" src="{% static 'img/no_data.svg' %}" />
<p class="pt-4">No past events.</p>
</div>
{% endfor %}

</div>
Expand Down
4 changes: 2 additions & 2 deletions home/templates/home/prerelease/session_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
{% block content %}
<main class="section">
<div class="container-lg">
<h3>Program Sessions</h3>
<div class="row">
<h1>Sessions</h1>
<div class="row pt-4">
<div class="col">
<p>
These sessions are limited to those who are accepted from an application
Expand Down
Empty file added home/tests/__init__.py
Empty file.
68 changes: 68 additions & 0 deletions home/tests/test_event_list.py
Original file line number Diff line number Diff line change
@@ -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())
9 changes: 6 additions & 3 deletions home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions requirements/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
-r requirements.txt
pytest
pytest-cov
pytest-django
pytest-django
tox
freezegun

0 comments on commit 65b80f3

Please sign in to comment.