|
5 | 5 |
|
6 | 6 | from sentry.models.environment import Environment
|
7 | 7 | from sentry.models.group import Group
|
8 |
| -from sentry.monitors.models import CheckInStatus, MonitorCheckIn, MonitorStatus |
| 8 | +from sentry.monitors.models import CheckInStatus, MonitorCheckIn, MonitorStatus, ScheduleType |
9 | 9 | from sentry.testutils.cases import MonitorTestCase
|
10 | 10 | from sentry.testutils.helpers.datetime import freeze_time
|
11 | 11 | from sentry.testutils.skips import requires_snuba
|
@@ -225,3 +225,42 @@ def test_trace_ids(self):
|
225 | 225 | assert resp.data[0]["groups"] == []
|
226 | 226 | assert resp.data[1]["id"] == str(checkin1.guid)
|
227 | 227 | assert resp.data[1]["groups"] == [{"id": group.id, "shortId": group.qualified_short_id}]
|
| 228 | + |
| 229 | + def test_serializes_monitor_config_correctly(self): |
| 230 | + monitor = self.create_monitor(project=self.project) |
| 231 | + config = { |
| 232 | + "schedule": "0 0 * * *", |
| 233 | + "schedule_type": ScheduleType.CRONTAB, |
| 234 | + "timezone": "US/Arizona", |
| 235 | + "max_runtime": None, |
| 236 | + "checkin_margin": None, |
| 237 | + } |
| 238 | + monitor_environment = self._create_monitor_environment(monitor) |
| 239 | + self.create_monitor_checkin( |
| 240 | + monitor=monitor, |
| 241 | + monitor_environment=monitor_environment, |
| 242 | + project_id=self.project.id, |
| 243 | + date_added=monitor.date_added - timedelta(minutes=2), |
| 244 | + status=CheckInStatus.OK, |
| 245 | + monitor_config=config, |
| 246 | + ) |
| 247 | + # Mutating the monitor config to test that the check-in config is used |
| 248 | + monitor.config = { |
| 249 | + "schedule": "0 * * * *", |
| 250 | + "schedule_type": ScheduleType.INTERVAL, |
| 251 | + "timezone": "CA/Toronto", |
| 252 | + "max_runtime": 1000, |
| 253 | + "checkin_margin": 100, |
| 254 | + } |
| 255 | + monitor.save() |
| 256 | + response = self.get_success_response( |
| 257 | + self.project.organization.slug, |
| 258 | + monitor.slug, |
| 259 | + ) |
| 260 | + assert response.data[0]["monitorConfig"]["schedule_type"] == ScheduleType.get_name( |
| 261 | + config["schedule_type"] |
| 262 | + ) |
| 263 | + assert response.data[0]["monitorConfig"]["schedule"] == config["schedule"] |
| 264 | + assert response.data[0]["monitorConfig"]["timezone"] == config["timezone"] |
| 265 | + assert response.data[0]["monitorConfig"]["max_runtime"] == config["max_runtime"] |
| 266 | + assert response.data[0]["monitorConfig"]["checkin_margin"] == config["checkin_margin"] |
0 commit comments