Cron package that syncs jobs from matrixhost portal API, schedules execution with timezone-aware timing, and posts results to Matrix rooms. Includes Brave Search, reminder, and browser scrape (placeholder) executors with formatter. 31 pytest tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
"""Tests for the reminder cron executor."""
|
|
|
|
from unittest.mock import AsyncMock
|
|
|
|
import pytest
|
|
|
|
from cron.reminder import execute_reminder
|
|
|
|
|
|
class TestReminderExecutor:
|
|
@pytest.mark.asyncio
|
|
async def test_sends_reminder_to_room(self):
|
|
job = {
|
|
"id": "j1",
|
|
"name": "Daily Check",
|
|
"config": {"message": "Check your portfolio"},
|
|
"targetRoom": "!room:finance",
|
|
}
|
|
send_text = AsyncMock()
|
|
result = await execute_reminder(job=job, send_text=send_text)
|
|
|
|
assert result["status"] == "success"
|
|
send_text.assert_called_once()
|
|
room_id, msg = send_text.call_args[0]
|
|
assert room_id == "!room:finance"
|
|
assert "Check your portfolio" in msg
|
|
assert "Daily Check" in msg
|
|
assert "\u23f0" in msg # alarm clock emoji
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_returns_error_without_message(self):
|
|
job = {
|
|
"id": "j1",
|
|
"name": "Empty",
|
|
"config": {},
|
|
"targetRoom": "!room:test",
|
|
}
|
|
send_text = AsyncMock()
|
|
result = await execute_reminder(job=job, send_text=send_text)
|
|
|
|
assert result["status"] == "error"
|
|
assert "message" in result["error"].lower()
|
|
send_text.assert_not_called()
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_empty_message_returns_error(self):
|
|
job = {
|
|
"id": "j1",
|
|
"name": "Empty",
|
|
"config": {"message": ""},
|
|
"targetRoom": "!room:test",
|
|
}
|
|
send_text = AsyncMock()
|
|
result = await execute_reminder(job=job, send_text=send_text)
|
|
|
|
assert result["status"] == "error"
|
|
send_text.assert_not_called()
|