def create(self, req, body): """Creates a new verification.""" LOG.debug('Create verification request body: %s', body) context = req.environ['karbor.context'] context.can(verification_policy.CREATE_POLICY) verification = body['verification'] LOG.debug('Create verification request : %s', verification) parameters = verification.get("parameters") verification_properties = { 'project_id': context.project_id, 'provider_id': verification.get('provider_id'), 'checkpoint_id': verification.get('checkpoint_id'), 'parameters': parameters, 'status': constants.VERIFICATION_STATUS_IN_PROGRESS, } verification_obj = objects.Verification(context=context, **verification_properties) verification_obj.create() try: self.protection_api.verification(context, verification_obj) except Exception: update_dict = {"status": constants.VERIFICATION_STATUS_FAILURE} verification_obj = self._verification_update( context, verification_obj.get("id"), update_dict) retval = self._view_builder.detail(req, verification_obj) return retval
def test_destroy(self, verification_destroy): db_verification = fake_verification.fake_db_verification() verification = objects.Verification._from_db_object( self.context, objects.Verification(), db_verification) verification.destroy() self.assertTrue(verification_destroy.called) admin_context = verification_destroy.call_args[0][0] self.assertTrue(admin_context.is_admin)
def test_save(self, verification_update): db_verification = fake_verification.fake_db_verification() verification = objects.Verification._from_db_object( self.context, objects.Verification(), db_verification) verification.status = 'FAILED' verification.save() verification_update.assert_called_once_with(self.context, verification.id, {'status': 'FAILED'})
def create(self, req, body): """Creates a new verification.""" if not self.is_valid_body(body, 'verification'): raise exc.HTTPUnprocessableEntity() LOG.debug('Create verification request body: %s', body) context = req.environ['karbor.context'] context.can(verification_policy.CREATE_POLICY) verification = body['verification'] LOG.debug('Create verification request : %s', verification) if not verification.get("provider_id"): msg = _("provider_id must be provided when creating " "a verification.") raise exception.InvalidInput(reason=msg) if not verification.get("checkpoint_id"): msg = _("checkpoint_id must be provided when creating " "a verification.") raise exception.InvalidInput(reason=msg) parameters = verification.get("parameters") if not isinstance(parameters, dict): msg = _("parameters must be a dict when creating" " a verification.") raise exception.InvalidInput(reason=msg) verification_properties = { 'project_id': context.project_id, 'provider_id': verification.get('provider_id'), 'checkpoint_id': verification.get('checkpoint_id'), 'parameters': parameters, 'status': constants.VERIFICATION_STATUS_IN_PROGRESS, } verification_obj = objects.Verification(context=context, **verification_properties) verification_obj.create() try: self.protection_api.verification(context, verification_obj) except Exception: update_dict = {"status": constants.VERIFICATION_STATUS_FAILURE} verification_obj = self._verification_update( context, verification_obj.get("id"), update_dict) retval = self._view_builder.detail(req, verification_obj) return retval
def test_obj_field_status(self): verification = objects.Verification(context=self.context, status='FAILED') self.assertEqual('FAILED', verification.status)
def test_create(self, verification_create): db_verification = fake_verification.fake_db_verification() verification_create.return_value = db_verification verification = objects.Verification(context=self.context) verification.create() self.assertEqual(db_verification['id'], verification.id)