raise webob.exc.HTTPBadRequest(_("Resource body required"))
LOG.debug(_("Request body: %(body)s"), {'body': body})
- prep_req_body = lambda x: Controller.prepare_request_body(
- context,
- x if resource in x else {resource: x},
- is_create,
- resource,
- attr_info,
- allow_bulk)
if collection in body:
if not allow_bulk:
raise webob.exc.HTTPBadRequest(_("Bulk operation "
"not supported"))
- bulk_body = [prep_req_body(item) for item in body[collection]]
- if not bulk_body:
+ if not body[collection]:
raise webob.exc.HTTPBadRequest(_("Resources required"))
+ bulk_body = [
+ Controller.prepare_request_body(
+ context, item if resource in item else {resource: item},
+ is_create, resource, attr_info, allow_bulk
+ ) for item in body[collection]
+ ]
return {collection: bulk_body}
res_dict = body.get(resource)
content_type='application/' + self.fmt)
self.assertEqual(res.status_int, exc.HTTPCreated.code)
- def test_create_bulk_no_networks(self):
- data = {'networks': []}
- res = self.api.post(_get_path('networks', fmt=self.fmt),
+ def _test_create_bulk_failure(self, resource, data):
+ # TODO(kevinbenton): update the rest of the failure cases to use
+ # this.
+ res = self.api.post(_get_path(resource, fmt=self.fmt),
self.serialize(data),
content_type='application/' + self.fmt,
expect_errors=True)
self.assertEqual(res.status_int, exc.HTTPBadRequest.code)
+ def test_create_bulk_networks_none(self):
+ self._test_create_bulk_failure('networks', {'networks': None})
+
+ def test_create_bulk_networks_empty_list(self):
+ self._test_create_bulk_failure('networks', {'networks': []})
+
def test_create_bulk_missing_attr(self):
data = {'ports': [{'what': 'who', 'tenant_id': _uuid()}]}
res = self.api.post(_get_path('ports', fmt=self.fmt),