53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
"""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()
|