Normalize conference redirect URLs

This commit is contained in:
Edward Betts 2026-08-30 14:04:30 +01:00
parent 92243863d7
commit e2847966d5
2 changed files with 91 additions and 16 deletions

53
test_check.py Normal file
View file

@ -0,0 +1,53 @@
"""Tests for conference website checks."""
import unittest
from unittest.mock import patch
from check import Conference, normalize_url, remove_hostname_dot
class UrlTests(unittest.TestCase):
"""URL cleanup and comparison tests."""
def test_remove_hostname_dot(self) -> None:
self.assertEqual(
remove_hostname_dot("https://fosdem.org./2027/"),
"https://fosdem.org/2027/",
)
def test_remove_hostname_dot_before_port(self) -> None:
self.assertEqual(
remove_hostname_dot("https://fosdem.org.:8443/2027/"),
"https://fosdem.org:8443/2027/",
)
def test_normalize_ignores_hostname_dot_and_trailing_slash(self) -> None:
self.assertEqual(
normalize_url("https://fosdem.org/2027"),
normalize_url("https://FOSDEM.org./2027/"),
)
class NotificationTests(unittest.TestCase):
"""Email notification tests."""
@patch("check.send_mail")
@patch.object(
Conference,
"check",
return_value=(True, "FOSDEM 2027", "https://fosdem.org./2027/"),
)
def test_slash_only_redirect_is_not_reported(self, _check, send_mail) -> None:
conference = Conference("FOSDEM", "https://fosdem.org/{year}", 2027)
self.assertTrue(conference.check_web_site())
send_mail.assert_called_once_with(
"Conference site live: FOSDEM - 2027",
"FOSDEM\nhttps://fosdem.org/2027\nWeb page title: FOSDEM 2027",
)
self.assertIsNone(conference.redirect_to_url)
if __name__ == "__main__":
unittest.main()