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>
68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
"""Tests for the cron result formatter."""
|
|
|
|
from cron.formatter import format_search_results, format_listings
|
|
|
|
|
|
class TestFormatSearchResults:
|
|
def test_single_result(self):
|
|
results = [
|
|
{"title": "BMW X3 2018", "url": "https://example.com/1", "description": "Unfallwagen"}
|
|
]
|
|
msg = format_search_results("BMW Scan", results)
|
|
assert "BMW Scan" in msg
|
|
assert "1 new result" in msg
|
|
assert "BMW X3 2018" in msg
|
|
assert "https://example.com/1" in msg
|
|
assert "Unfallwagen" in msg
|
|
assert "matrixhost.eu/settings/automations" in msg
|
|
|
|
def test_multiple_results(self):
|
|
results = [
|
|
{"title": "Result 1", "url": "https://a.com", "description": "Desc 1"},
|
|
{"title": "Result 2", "url": "https://b.com", "description": "Desc 2"},
|
|
{"title": "Result 3", "url": "https://c.com", "description": ""},
|
|
]
|
|
msg = format_search_results("Test Search", results)
|
|
assert "3 new results" in msg
|
|
assert "1." in msg
|
|
assert "2." in msg
|
|
assert "3." in msg
|
|
|
|
def test_result_without_description(self):
|
|
results = [{"title": "No Desc", "url": "https://x.com"}]
|
|
msg = format_search_results("Search", results)
|
|
assert "No Desc" in msg
|
|
# Should not have empty description line
|
|
|
|
|
|
class TestFormatListings:
|
|
def test_single_listing(self):
|
|
listings = [
|
|
{
|
|
"title": "BMW X3 2.0i",
|
|
"price": "\u20ac4,500",
|
|
"location": "Limassol",
|
|
"url": "https://fb.com/123",
|
|
"age": "2h ago",
|
|
}
|
|
]
|
|
msg = format_listings("Car Scan", listings)
|
|
assert "Car Scan" in msg
|
|
assert "1 new listing" in msg
|
|
assert "BMW X3 2.0i" in msg
|
|
assert "\u20ac4,500" in msg
|
|
assert "Limassol" in msg
|
|
assert "2h ago" in msg
|
|
assert "https://fb.com/123" in msg
|
|
|
|
def test_listing_without_optional_fields(self):
|
|
listings = [{"title": "Bare Listing"}]
|
|
msg = format_listings("Scan", listings)
|
|
assert "Bare Listing" in msg
|
|
assert "1 new listing" in msg
|
|
|
|
def test_multiple_listings_plural(self):
|
|
listings = [{"title": f"Item {i}"} for i in range(5)]
|
|
msg = format_listings("Multi", listings)
|
|
assert "5 new listings" in msg
|