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

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

    with self.assertRaises(api.InvalidStateChangeError):
      api.Revoke(exm_key, ['justification'])
    mock_enable.assert_not_called()
    self.assertEqual(_STATE.CANCELLED, exm_key.get().state)
    self.mock_send.assert_not_called()
コード例 #2
0
ファイル: api_test.py プロジェクト: tonynotears/upvote
  def testSuccess_Santa(self):

    host_key = test_utils.CreateSantaHost(primary_user='******').key
    exm_key = test_utils.CreateExemption(
        host_key.id(), initial_state=_STATE.APPROVED)

    api.Revoke(exm_key, ['reasons'])
    exm = exm_key.get()

    self.assertEqual(_STATE.REVOKED, exm.state)
    self.assertBigQueryInsertions([
        constants.BIGQUERY_TABLE.HOST, constants.BIGQUERY_TABLE.EXEMPTION])
    self.DrainTaskQueue(constants.TASK_QUEUE.EXEMPTIONS)
    self.mock_send.assert_called_once()
コード例 #3
0
    def post(self, host_id):

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

        # Extract and validate POST data fields.
        justification = self.request.get('justification')
        if not justification:
            self.abort(
                httplib.BAD_REQUEST,
                explanation='No justification for revoking exemption provided')

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