diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index 2a78db1719..445b7c665f 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -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. diff --git a/awx/main/tests/projects.py b/awx/main/tests/projects.py index 3bac17b93f..91ebe17b81 100644 --- a/awx/main/tests/projects.py +++ b/awx/main/tests/projects.py @@ -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,))