0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-10 15:37:30 +00:00
healthchecks_healthchecks/hc/front/tests/test_oncalendar_preview.py
Pēteris Caune d65f41d192
Add support for systemd's OnCalendar schedules
(work-in-progress)

cc: 
2023-12-06 15:42:57 +02:00

26 lines
942 B
Python

from __future__ import annotations
from datetime import datetime, timezone
from unittest.mock import Mock, patch
from hc.test import BaseTestCase
CURRENT_TIME = datetime(2020, 1, 1, tzinfo=timezone.utc)
MOCK_NOW = Mock(return_value=CURRENT_TIME)
@patch("hc.front.views.now", MOCK_NOW)
class OnCalendarPreviewTestCase(BaseTestCase):
url = "/checks/oncalendar_preview/"
def test_it_works(self) -> None:
payload = {"schedule": "*:*", "tz": "UTC"}
r = self.client.post(self.url, payload)
self.assertContains(r, "oncalendar-preview-title", status_code=200)
self.assertContains(r, "2020-01-01 00:01:00 UTC")
def test_it_handles_single_result(self) -> None:
payload = {"schedule": "2020-02-01", "tz": "UTC"}
r = self.client.post(self.url, payload)
self.assertContains(r, "oncalendar-preview-title", status_code=200)
self.assertContains(r, "2020-02-01 00:00:00 UTC")