Skip to content

Commit

Permalink
test(backup): Add monitor tests
Browse files Browse the repository at this point in the history
Issue: getsentry/team-ospo/#156
  • Loading branch information
azaslavsky committed Jul 11, 2023
1 parent 0dec276 commit c1b9df4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/sentry/backup/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c1b9df4

Please sign in to comment.