From c1b9df40ab9184dca4e073adbad721ea2704b133 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Fri, 7 Jul 2023 15:52:46 -0700 Subject: [PATCH] test(backup): Add monitor tests Issue: getsentry/team-ospo/#156 --- tests/sentry/backup/test_models.py | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/sentry/backup/test_models.py b/tests/sentry/backup/test_models.py index 569b065de9c9d8..2b0b42ece78a4d 100644 --- a/tests/sentry/backup/test_models.py +++ b/tests/sentry/backup/test_models.py @@ -8,6 +8,8 @@ from django.core.management import call_command from sentry.db.postgres.roles import in_test_psql_role_override +from sentry.models.environment import Environment +from sentry.monitors.models import Monitor, MonitorEnvironment, MonitorType, ScheduleType from sentry.runner.commands.backup import import_, validate from sentry.testutils import TransactionTestCase from tests.sentry.backup import ValidationError, tmp_export_to_file @@ -57,6 +59,36 @@ def import_export_then_validate(self): if res.findings: raise ValidationError(res) + def create_monitor(self): + """Re-usable monitor object for test cases.""" + + user = self.create_user() + org = self.create_organization(owner=user) + project = self.create_project(organization=org) + return Monitor.objects.create( + organization_id=project.organization.id, + project_id=project.id, + type=MonitorType.CRON_JOB, + config={"schedule": "* * * * *", "schedule_type": ScheduleType.CRONTAB}, + ) + + def test_environment(self): + self.create_environment() + self.import_export_then_validate() + + def test_monitor(self): + self.create_monitor() + self.import_export_then_validate() + + def test_monitor_environment(self): + monitor = self.create_monitor() + env = Environment.objects.create(organization_id=monitor.organization_id, name="test_env") + MonitorEnvironment.objects.create( + monitor=monitor, + environment=env, + ) + self.import_export_then_validate() + def test_organization(self): user = self.create_user() self.create_organization(owner=user)