Prepare isolated Firebase push configuration for pre-production

This commit is contained in:
2026-09-15 19:24:18 +02:00
parent e5fa427485
commit bb28e17220
16 changed files with 386 additions and 17 deletions
+45 -6
View File
@@ -40,17 +40,42 @@ class BadgeAndLanguageTests(unittest.TestCase):
with patch.dict(os.environ, {'ALPHA_TESTER_UNTIL':'2027-02-01', 'BETA_TESTER_UNTIL':'2027-01-31'}):
with self.assertRaises(ValueError): cohort(datetime(2026, 1, 1))
def test_one_language_link_targets_opposite_language(self):
import re
for language, target in [('de', 'en'), ('en', 'de')]:
def test_language_dropdown_offers_both_languages_and_marks_current(self):
for language in ('de', 'en'):
token = current_language.set(language)
try:
html = main.templates.get_template('_language_switch.html').render()
finally:
current_language.reset(token)
self.assertEqual(len(re.findall(r'<a\s', html)), 1)
self.assertIn('/language/' + target, html)
self.assertIn('>' + target.upper() + '</a>', html)
self.assertEqual(len(re.findall(r'<a\s', html)), 2)
for target in ('de', 'en'):
self.assertIn('/language/' + target, html)
self.assertRegex(html, rf'<a[^>]*lang="{language}"[^>]*aria-current="true"')
self.assertEqual(html.count('aria-current="true"'), 1)
def test_all_push_kinds_share_generic_android_payload_and_unique_tags(self):
from firebase_admin import messaging
from notifications import TEXT
sender = FirebaseSender()
sender.app = object()
tags = set()
for kind, (title, body) in TEXT.items():
with self.subTest(kind=kind), patch.object(messaging, 'send') as send:
identifier = str(uuid4())
sender.send('synthetic-token', title, body,
{'notification_id': identifier, 'session_tag': 'a' * 64}, identifier)
payload = send.call_args.args[0]
self.assertEqual(payload.notification.title, title)
self.assertEqual(payload.notification.body, body)
self.assertEqual(set(payload.data), {'notification_id', 'session_tag'})
self.assertEqual(payload.android.notification.tag, identifier)
self.assertIsNone(payload.android.notification.channel_id)
self.assertIsNone(payload.android.notification.click_action)
self.assertEqual(payload.android.priority, 'high')
self.assertEqual(payload.android.notification.sound, 'default')
self.assertEqual(payload.android.notification.icon, 'ic_notification')
tags.add(identifier)
self.assertEqual(len(tags), 3)
def test_sender_missing_credentials_is_safe(self):
with patch.dict(os.environ, {'GOOGLE_APPLICATION_CREDENTIALS':'', 'FIREBASE_PROJECT_ID':''}):
@@ -166,6 +191,20 @@ class NotificationDatabaseTests(unittest.TestCase):
response = self.clients[1].get('/notifications/'+args[3]['notification_id'], follow_redirects=False)
self.assertEqual(response.headers['location'], '/messages/sender#latest')
def test_opening_chat_before_delivery_drops_push_and_read_tap_returns_home(self):
self.message()
self.assertEqual(self.clients[1].get('/messages/sender').status_code, 200)
self.worker.deliver_one()
self.sender.send.assert_not_called()
self.assertEqual(self.scalar('SELECT state FROM push_notifications'), 'dropped')
self.message()
self.worker.deliver_one()
self.sender.send.assert_called_once()
identifier = self.sender.send.call_args.args[3]['notification_id']
self.clients[1].get('/messages/sender')
response = self.clients[1].get('/notifications/' + identifier, follow_redirects=False)
self.assertEqual(response.headers['location'], '/')
def test_invitation_route_and_removed_invitation(self):
concert = self.invitation()
self.worker.deliver_one()