コード例 #1
0
ファイル: exemptions.py プロジェクト: tonynotears/upvote
    def post(self, host_id):

        if not self.exm:
            self.abort(httplib.NOT_FOUND, explanation='Exemption not found')

        # Humans should never trigger the transition from PENDING to DENIED, only
        # api.Process() should.
        if self.exm.key.get().state == constants.EXEMPTION_STATE.PENDING:
            self.abort(httplib.FORBIDDEN,
                       explanation='Cannot deny a pending request')

        justification = self.request.get('justification')
        if not justification:
            self.abort(httplib.BAD_REQUEST,
                       explanation='No justification for denial provided')

        try:
            exemption_api.Deny(self.exm.key, details=[justification])
        except Exception:  # pylint: disable=broad-except
            logging.exception(
                'Error encountered while denying Exemption for host %s',
                host_id)
            self.abort(httplib.INTERNAL_SERVER_ERROR,
                       explanation='Error while denying exemption')

        self.respond_json(self.exm.key.get())
コード例 #2
0
ファイル: api_test.py プロジェクト: tonynotears/upvote
  def testInvalidStateChangeError(self):

    host_key = test_utils.CreateBit9Host().key
    exm_key = test_utils.CreateExemption(
        host_key.id(), initial_state=_STATE.APPROVED)

    with self.assertRaises(api.InvalidStateChangeError):
      api.Deny(exm_key)
    self.assertEqual(_STATE.APPROVED, exm_key.get().state)
    self.mock_send.assert_not_called()
コード例 #3
0
ファイル: api_test.py プロジェクト: tonynotears/upvote
  def testSuccess(self):

    host_key = test_utils.CreateBit9Host().key
    exm_key = test_utils.CreateExemption(
        host_key.id(), initial_state=_STATE.PENDING)

    api.Deny(exm_key)
    exm = exm_key.get()

    self.assertEqual(_STATE.DENIED, exm.state)
    self.assertBigQueryInsertion(constants.BIGQUERY_TABLE.EXEMPTION)
    self.DrainTaskQueue(constants.TASK_QUEUE.EXEMPTIONS)
    self.mock_send.assert_called_once()