aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJason McCormick <jason@mfamily.org>2026-11-05 18:37:48 -0500
committerJason McCormick <jason@mfamily.org>2026-11-05 18:37:48 -0500
commitc2382d8b4cf93489614c5fe70a604ab698b9f613 (patch)
tree8a8b28d010292271b24b9c3cd6bc175fc58e2a95 /tests
parent75719aa37f7317f3a8feeb516f1444edb4274410 (diff)
feat: 1-minute watcher and per-stanza email subject/header
Run the notification timer every minute and shrink the scan window to match. Each upload URI stanza may now set subject and body_header to override the default notification text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_server.py40
1 files changed, 39 insertions, 1 deletions
diff --git a/tests/test_server.py b/tests/test_server.py
index 4644ecc..888568f 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -225,7 +225,7 @@ class ServerTests(unittest.TestCase):
encoding="utf-8",
)
config = load_config(config_file)
- for target, mtime in (("alpha", 1990), ("beta", 1700), ("gamma", 2000)):
+ for target, mtime in (("alpha", 1990), ("beta", 1940), ("gamma", 2000)):
directory = self.upload_dir / target
directory.mkdir(parents=True)
(directory / "x.png").write_bytes(PNG)
@@ -287,6 +287,44 @@ class ServerTests(unittest.TestCase):
with self.subTest(prefix=prefix), self.assertRaises(ValueError):
load_config(config_file)
+ def test_watcher_uses_per_stanza_subject_and_body_header(self):
+ config_file = Path(self.temp.name) / "watcher.toml"
+ config_file.write_text(
+ '[GLOBAL]\nsend_as = "uploads@example.com"\nsmtp_server = "localhost"\n'
+ "smtp_port = 25\ntls = false\nstarttls = false\n\n"
+ '[custom]\nrecipient = "a@example.com"\nsubject = "Logo entry"\n'
+ 'body_header = """\nHello reviewers,\nA new entry arrived.\n"""\n\n'
+ '[plain]\nrecipient = "b@example.com"\n',
+ encoding="utf-8",
+ )
+ config = load_config(config_file)
+ for target in ("custom", "plain"):
+ directory = self.upload_dir / target
+ directory.mkdir(parents=True)
+ (directory / "x.png").write_bytes(PNG)
+ os.utime(directory / "x.png", (1990, 1990))
+ smtp_context = MagicMock()
+ with patch("watcher.smtplib.SMTP", return_value=smtp_context):
+ send_recent_upload_notifications(config, self.upload_dir, now=2000)
+
+ custom, plain = (call.args[0] for call in smtp_context.__enter__.return_value.send_message.call_args_list)
+ self.assertEqual(custom["Subject"], "Logo entry")
+ self.assertTrue(custom.get_content().startswith("Hello reviewers,\nA new entry arrived.\n\n---"))
+ self.assertEqual(plain["Subject"], "New upload received")
+ self.assertTrue(plain.get_content().startswith("A new file has been uploaded to your private drop."))
+
+ def test_rejects_invalid_subject_and_body_header(self):
+ config_file = Path(self.temp.name) / "config.toml"
+ for setting in ('subject = "two\\nlines"', 'subject = " "', 'body_header = "bell\\u0007"', "subject = 5"):
+ config_file.write_text(
+ '[GLOBAL]\nsend_as = "uploads@example.com"\nsmtp_server = "localhost"\n'
+ "smtp_port = 25\ntls = false\nstarttls = false\n\n"
+ f'[logo-contest]\nrecipient = "reviewer@example.com"\n{setting}\n',
+ encoding="utf-8",
+ )
+ with self.subTest(setting=setting), self.assertRaises(ValueError):
+ load_config(config_file)
+
def test_watcher_skips_smtp_when_nothing_is_new(self):
config_file = Path(self.temp.name) / "watcher.toml"
config_file.write_text(