AC-1114 Mark schedules inactive when their parent unified job template is marked inactive.

This commit is contained in:
Chris Church 2014-04-01 16:17:29 -04:00
parent 1c649a0752
commit 9479068cda
2 changed files with 27 additions and 1 deletions

View File

@ -182,6 +182,15 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique):
self.next_job_run = related_schedules[0].next_run
self.save(update_fields=['next_schedule', 'next_job_run'])
def mark_inactive(self, save=True):
'''
When marking a unified job template inactive, also mark its schedules
inactive.
'''
for schedule in self.schedules.filter(active=True):
schedule.mark_inactive()
super(UnifiedJobTemplate, self).mark_inactive(save=save)
def save(self, *args, **kwargs):
# If update_fields has been specified, add our field names to it,
# if it hasn't been specified, then we're just doing a normal save.

View File

@ -259,9 +259,26 @@ class ProjectsTest(BaseTest):
self.get(project, expect=200, auth=self.get_other_credentials())
self.get(project, expect=403, auth=self.get_nobody_credentials())
# can delete projects
# can create a schedule for a project (doesn't matter if the project
# has SCM for this test).
project_schedules = reverse('api:project_schedules_list', args=(self.projects[3].pk,))
with self.current_user(self.super_django_user):
response = self.get(project_schedules, expect=200)
self.assertEqual(response['count'], 0)
dtstart = now().replace(microsecond=0).strftime('%Y%m%dT%H%M%SZ')
data = {
'name': 'test schedule',
'rrule': 'DTSTART:%s RRULE:FREQ=DAILY;INTERVAL=1' % dtstart,
}
response = self.post(project_schedules, data, expect=201)
schedule_url = response['url']
response = self.get(schedule_url, expect=200)
# can delete projects, schedule should be "deleted" along with project.
self.delete(project, expect=204, auth=self.get_normal_credentials())
self.get(project, expect=404, auth=self.get_normal_credentials())
with self.current_user(self.super_django_user):
self.get(schedule_url, expect=404)
# can list playbooks for projects
proj_playbooks = reverse('api:project_playbooks', args=(self.projects[2].pk,))