|
@@ -16,6 +16,7 @@ from sentry.monitors.models import (
|
|
|
MonitorType,
|
|
|
ScheduleType,
|
|
|
)
|
|
|
+from sentry.monitors.validators import ConfigValidator
|
|
|
from sentry.testutils import TestCase
|
|
|
from sentry.testutils.silo import region_silo_test
|
|
|
|
|
@@ -304,3 +305,35 @@ class MonitorEnvironmentTestCase(TestCase):
|
|
|
MonitorEnvironment.objects.ensure_environment(
|
|
|
self.project, monitor, f"space-{settings.MAX_ENVIRONMENTS_PER_MONITOR}"
|
|
|
)
|
|
|
+
|
|
|
+ def test_update_config(self):
|
|
|
+ monitor = Monitor.objects.create(
|
|
|
+ organization_id=self.organization.id,
|
|
|
+ project_id=self.project.id,
|
|
|
+ type=MonitorType.CRON_JOB,
|
|
|
+ name="Unicron",
|
|
|
+ slug="unicron",
|
|
|
+ config={
|
|
|
+ "schedule": [1, "month"],
|
|
|
+ "schedule_type": ScheduleType.INTERVAL,
|
|
|
+ "alert_rule_id": 1,
|
|
|
+ },
|
|
|
+ )
|
|
|
+
|
|
|
+ new_config = {
|
|
|
+ "schedule": [2, "month"],
|
|
|
+ "schedule_type": "interval",
|
|
|
+ "max_runtime": 10,
|
|
|
+ "garbage": "data",
|
|
|
+ }
|
|
|
+ validator = ConfigValidator(data=new_config)
|
|
|
+ assert validator.is_valid()
|
|
|
+ validated_config = validator.validated_data
|
|
|
+ monitor.update_config(new_config, validated_config)
|
|
|
+
|
|
|
+ assert monitor.config == {
|
|
|
+ "schedule": [2, "month"],
|
|
|
+ "schedule_type": ScheduleType.INTERVAL,
|
|
|
+ "max_runtime": 10,
|
|
|
+ "alert_rule_id": 1,
|
|
|
+ }
|