def Run(self): with test_lib.FakeTime(42): self.CreateUser("approver") cron_manager = aff4_cronjobs.CronManager() cron_args = aff4_cronjobs.CreateCronJobFlowArgs(periodicity="1d", allow_overruns=False) cron_urn = cron_manager.ScheduleFlow(cron_args=cron_args, token=self.token) cron_id = cron_urn.Basename() def ReplaceCronAndApprovalIds(): approvals = self.ListCronJobApprovals() return { approvals[0].id: "approval:112233", cron_id: "CronJob_123456" } with test_lib.FakeTime(126): self.Check("CreateCronJobApproval", args=user_plugin.ApiCreateCronJobApprovalArgs( cron_job_id=cron_id, approval=user_plugin.ApiCronJobApproval( reason="really important reason!", notified_users=["approver1", "approver2"], email_cc_addresses=["*****@*****.**"])), replace=ReplaceCronAndApprovalIds)
def RequestCronJobApproval(self, cron_job_id, requestor=None, reason=None, email_cc_address=None, approver="approver"): """Request cron job approval for a given cron job.""" if not requestor: requestor = self.token.username if not reason: reason = self.token.reason self.CreateUser(requestor) self.CreateUser(approver) args = api_user.ApiCreateCronJobApprovalArgs( cron_job_id=cron_job_id, approval=api_user.ApiCronJobApproval( reason=reason, notified_users=[approver], email_cc_addresses=([email_cc_address] if email_cc_address else []))) handler = api_user.ApiCreateCronJobApprovalHandler() result = handler.Handle( args, token=access_control.ACLToken(username=requestor)) return result.id
def setUp(self): super(ApiCreateCronJobApprovalHandlerTest, self).setUp() self.SetUpApprovalTest() cron_manager = aff4_cronjobs.GetCronManager() cron_args = rdf_cronjobs.CreateCronJobFlowArgs( periodicity="1d", allow_overruns=False) cron_id = cron_manager.CreateJob(cron_args=cron_args, token=self.token) self.handler = user_plugin.ApiCreateCronJobApprovalHandler() self.args = user_plugin.ApiCreateCronJobApprovalArgs(cron_job_id=cron_id) self.args.approval.reason = self.token.reason self.args.approval.notified_users = ["approver"] self.args.approval.email_cc_addresses = ["*****@*****.**"]