Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_on_post_inserts_correct_data(self):
self.mock_json_body.return_value = fake_data_0_backup_metadata
self.mock_db.add_backup.return_value = fake_data_0_wrapped_backup_metadata['backup_id']
self.resource.on_post(self.mock_req, self.mock_req)
expected_result = {'backup_id': fake_data_0_wrapped_backup_metadata['backup_id']}
self.assertEqual(self.mock_req.status, falcon.HTTP_201)
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(self.mock_req.status, falcon.HTTP_201)
def _prepare_messages(self, count):
doc = json.dumps([{'body': 239, 'ttl': 300}] * count)
self.simulate_post(self.messages_path, body=doc,
headers={'Client-ID': str(uuid.uuid4())})
self.assertEqual(self.srmock.status, falcon.HTTP_201)
def test_create_a_dup_user(self):
self.simulate_post(USER_RESOURCE_ROUTE, VALID_DATA)
self.assertEqual(self.srmock.status, falcon.HTTP_201)
self.simulate_post(USER_RESOURCE_ROUTE, VALID_DATA)
self.assertEqual(self.srmock.status, falcon.HTTP_409)
(user_id, roster, team))
# subscribe user to notifications
subscribe_notifications(team, user_name, cursor)
create_audit({'roster': roster, 'user': user_name, 'request_body': data}, team,
ROSTER_USER_ADDED, req, cursor)
connection.commit()
except db.IntegrityError:
raise HTTPError('422 Unprocessable Entity',
'IntegrityError',
'user "%(name)s" is already in the roster' % data)
finally:
cursor.close()
connection.close()
resp.status = HTTP_201
resp.body = json_dumps(get_user_data(None, {'name': user_name})[0])
create_audit({'user': user_name}, team, ADMIN_CREATED, req, cursor)
connection.commit()
except db.IntegrityError as e:
err_msg = str(e.args[1])
if err_msg == "Column 'team_id' cannot be null":
err_msg = 'team %s not found' % team
if err_msg == "Column 'user_id' cannot be null":
err_msg = 'user %s not found' % data['name']
else:
err_msg = 'user name "%s" is already an admin of team %s' % (data['name'], team)
raise HTTPError('422 Unprocessable Entity', 'IntegrityError', err_msg)
finally:
cursor.close()
connection.close()
resp.status = HTTP_201
resp.body = json_dumps(get_user_data(None, {'name': user_name})[0])
def on_post(self, req, resp, project_id, action_id):
# PUT /v2/{project_id}/actions/{action_id}
# Creates/Replaces the specified action
user_id = req.get_header('X-User-ID') or ''
doc = self.json_body(req)
new_version = self.db.replace_action(project_id=project_id,
user_id=user_id,
action_id=action_id,
doc=doc)
resp.status = falcon.HTTP_201
resp.body = {'action_id': action_id, 'version': new_version}
raise falcon.HTTPBadRequest(_('Unable to create'), 'Bad Request')
# NOTE(gengchc2): Check if pools in the pool_list exist.
try:
self._check_pools_exists(pool_list)
except errors.PoolDoesNotExist as ex:
LOG.exception(ex)
description = (_(u'Flavor %(flavor)s could not be created, '
'error:%(msg)s') %
dict(flavor=flavor, msg=str(ex)))
raise falcon.HTTPBadRequest(_('Unable to create'), description)
capabilities = self._pools_ctrl.capabilities(name=pool_list[0])
try:
self._ctrl.create(flavor,
project=project_id,
capabilities=capabilities)
response.status = falcon.HTTP_201
response.location = request.path
except errors.ConnectionError as ex:
LOG.exception(ex)
description = (_(u'Flavor %(flavor)s could not be created, '
'error:%(msg)s') %
dict(flavor=flavor, msg=str(ex)))
raise falcon.HTTPBadRequest(_('Unable to create'), description)
# NOTE(gengchc2): Update the 'flavor' field in pools tables.
try:
self._update_pools_by_flavor(flavor, pool_list)
except errors.ConnectionError as ex:
LOG.exception(ex)
description = (_(u'Flavor %(flavor)s could not be created, '
'error:%(msg)s') %
dict(flavor=flavor, msg=str(ex)))
raise falcon.HTTPBadRequest(_('Unable to create'), description)
raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
try:
created = self._topic_controller.create(topic_name,
metadata=metadata,
project=project_id)
except storage_errors.FlavorDoesNotExist as ex:
LOG.exception('Flavor "%s" does not exist', topic_name)
raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
except Exception:
description = _(u'Topic could not be created.')
LOG.exception(description)
raise wsgi_errors.HTTPServiceUnavailable(description)
resp.status = falcon.HTTP_201 if created else falcon.HTTP_204
resp.location = req.path
}],
retry=False, )
document_data = req.stream.read(content_length)
buffer_mode = req.get_param('buffermode')
helper = ConfigdocsHelper(req.context)
validations = self.post_collection(
helper=helper,
collection_id=collection_id,
document_data=document_data,
buffer_mode_param=buffer_mode)
resp.location = '/api/v1.0/configdocs/{}'.format(collection_id)
resp.body = self.to_json(validations)
resp.status = falcon.HTTP_201
def on_post(self, req, resp, job_id):
# PUT /v1/jobs/{job_id} creates/replaces the specified job
user_id = req.get_header('X-User-ID') or ''
job = Job(self.json_body(req))
self.update_actions_in_job(user_id, job.doc)
new_version = self.db.replace_job(user_id=user_id,
job_id=job_id,
doc=job.doc)
resp.status = falcon.HTTP_201
resp.body = {'job_id': job_id, 'version': new_version}