Exemplo n.º 1
0
  def testErrorDuringStartFlowDoesNotBubbleUpToApprovalApiCall(self):
    flow.ScheduleFlow(
        client_id=self.client_id,
        creator=self.context.username,
        flow_name=file.CollectSingleFile.__name__,
        flow_args=rdf_file_finder.CollectSingleFileArgs(path="/foo"),
        runner_args=rdf_flow_runner.FlowRunnerArgs())

    with mock.patch.object(
        flow, "StartFlow",
        side_effect=ValueError("foobazzle")) as start_flow_mock:
      approval_id = self.RequestAndGrantClientApproval(
          self.client_id,
          reason=u"blah",
          approver=u"approver",
          requestor=self.context.username)

    args = user_plugin.ApiGetClientApprovalArgs(
        client_id=self.client_id,
        approval_id=approval_id,
        username=self.context.username)
    handler = user_plugin.ApiGetClientApprovalHandler()
    approval = handler.Handle(args, context=self.context)

    self.assertTrue(approval.is_valid)
    self.assertTrue(start_flow_mock.called)
Exemplo n.º 2
0
  def testStartsScheduledFlowsIfGrantedApprovalIsValid(self):
    with mock.patch.object(flow, "StartScheduledFlows") as start_mock:
      approval_id = self.RequestAndGrantClientApproval(
          self.client_id,
          reason=u"blah",
          approver=u"approver",
          requestor=self.context.username)

    args = user_plugin.ApiGetClientApprovalArgs(
        client_id=self.client_id,
        approval_id=approval_id,
        username=self.context.username)
    handler = user_plugin.ApiGetClientApprovalHandler()
    approval = handler.Handle(args, context=self.context)

    self.assertTrue(approval.is_valid)
    self.assertTrue(start_mock.called)
    start_mock.assert_called_with(
        client_id=self.client_id, creator=self.context.username)
Exemplo n.º 3
0
  def testDoesNotStartScheduledFlowsIfGrantedApprovalIsNotValid(self):
    with mock.patch.object(flow, "StartScheduledFlows") as start_mock:
      with mock.patch.object(
          approval_checks,
          "CheckApprovalRequest",
          side_effect=access_control.UnauthorizedAccess("foobazzle")):
        approval_id = self.RequestAndGrantClientApproval(
            self.client_id,
            reason=u"blah",
            approver=u"approver",
            requestor=self.context.username)

        args = user_plugin.ApiGetClientApprovalArgs(
            client_id=self.client_id,
            approval_id=approval_id,
            username=self.context.username)
        handler = user_plugin.ApiGetClientApprovalHandler()
        result = handler.Handle(args, context=self.context)

    self.assertFalse(result.is_valid)
    self.assertFalse(start_mock.called)
 def GetClientApproval(self, args, context=None):
     return api_user.ApiGetClientApprovalHandler()
Exemplo n.º 5
0
 def setUp(self):
   super(ApiGetClientApprovalHandlerTest, self).setUp()
   self.client_id = self.SetupClient(0)
   self.handler = user_plugin.ApiGetClientApprovalHandler()
 def GetClientApproval(self, args, token=None):
     return api_user.ApiGetClientApprovalHandler()