Sort linked events chronologically

This commit is contained in:
2026-09-15 15:54:36 +02:00
parent 45c086b032
commit 5a29514aa4
2 changed files with 59 additions and 2 deletions
+58 -1
View File
@@ -1,9 +1,10 @@
"""Local PostgreSQL and simulated Firebase tests. Never contacts Firebase."""
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from datetime import datetime, timedelta
import hashlib
import os
from pathlib import Path
import re
import unittest
from unittest.mock import Mock, patch
from uuid import uuid4
@@ -192,6 +193,62 @@ class NotificationDatabaseTests(unittest.TestCase):
self.clients[0].post(f'/concerts/{concert}/edit', data=form, follow_redirects=False)
self.assertEqual(self.scalar("SELECT count(*) FROM push_notifications WHERE state='pending'"), 1)
def test_linkable_events_are_chronological_in_create_and_edit_forms(self):
with main.get_db_connection() as db:
rows = db.execute("""
INSERT INTO concerts(artist, start_datetime, end_datetime, event_type, visibility, created_by)
VALUES
('Active festival', date_trunc('day', CURRENT_TIMESTAMP) - INTERVAL '1 day' + INTERVAL '18 hours', date_trunc('day', CURRENT_TIMESTAMP) + INTERVAL '23 hours 59 minutes', 'festival', 'public', 1),
('Near concert', date_trunc('day', CURRENT_TIMESTAMP) + INTERVAL '2 days 20 hours', NULL, 'concert', 'public', 1),
('Same-time concert', date_trunc('day', CURRENT_TIMESTAMP) + INTERVAL '2 days 20 hours', NULL, 'concert', 'public', 1),
('Upcoming festival', date_trunc('day', CURRENT_TIMESTAMP) + INTERVAL '3 days 10 hours', date_trunc('day', CURRENT_TIMESTAMP) + INTERVAL '4 days 23 hours', 'festival', 'public', 1),
('Later concert', date_trunc('day', CURRENT_TIMESTAMP) + INTERVAL '6 days 20 hours', NULL, 'concert', 'public', 1),
('Past concert', date_trunc('day', CURRENT_TIMESTAMP) - INTERVAL '1 day', NULL, 'concert', 'public', 1),
('Finished festival', date_trunc('day', CURRENT_TIMESTAMP) - INTERVAL '3 days', date_trunc('day', CURRENT_TIMESTAMP) - INTERVAL '1 day', 'festival', 'public', 1)
RETURNING id
""").fetchall()
active_festival, near_concert, same_time_concert, upcoming_festival, later_concert, _, _ = [row[0] for row in rows]
edit_event_id = db.execute("""
INSERT INTO concerts(artist, start_datetime, event_type, visibility, created_by)
VALUES ('Test pre-show', date_trunc('day', CURRENT_TIMESTAMP) + INTERVAL '5 days', 'other', 'public', 1)
RETURNING id
""").fetchone()[0]
expected_ids = [active_festival, near_concert, same_time_concert, upcoming_festival, later_concert]
for language in ('de', 'en'):
self.clients[0].get('/language/' + language, follow_redirects=False)
create_page = self.clients[0].get('/concerts/new')
self.assertEqual(create_page.status_code, 200)
create_select = re.search(r'<select name="parent_event_id".*?</select>', create_page.text, re.S).group()
create_ids = [int(value) for value in re.findall(r'<option value="(\d+)"', create_select)]
self.assertEqual(create_ids, expected_ids)
edit_page = self.clients[0].get(f'/concerts/{edit_event_id}/edit')
self.assertEqual(edit_page.status_code, 200)
edit_select = re.search(r'<select name="parent_event_id".*?</select>', edit_page.text, re.S).group()
edit_ids = [int(value) for value in re.findall(r'<option value="(\d+)"', edit_select)]
self.assertEqual(edit_ids, expected_ids)
submitted = self.clients[0].post('/concerts', data={
'artist': 'Linked pre-show test',
'event_type': 'other',
'parent_event_id': str(upcoming_festival),
'visibility': 'public',
'start_datetime': (datetime.now() + timedelta(days=2)).strftime('%Y-%m-%dT%H:%M'),
}, follow_redirects=False)
self.assertEqual(submitted.status_code, 303)
linked_id = int(submitted.headers['location'].rsplit('/', 1)[1])
self.assertEqual(self.scalar('SELECT parent_event_id FROM concerts WHERE id=%s', (linked_id,)), upcoming_festival)
self.clients[0].post(f'/concerts/{edit_event_id}/edit', data={
'artist': 'Test pre-show',
'event_type': 'other',
'parent_event_id': str(near_concert),
'visibility': 'public',
'start_datetime': (datetime.now() + timedelta(days=5)).strftime('%Y-%m-%dT%H:%M'),
}, follow_redirects=False)
self.assertEqual(self.scalar('SELECT parent_event_id FROM concerts WHERE id=%s', (edit_event_id,)), near_concert)
def test_profile_preferences_and_alpha_render_in_both_languages(self):
for language, label in [('de', 'Push-Benachrichtigungen'), ('en', 'Push notifications')]:
self.clients[1].get('/language/'+language, follow_redirects=False)