def test_create(self): with mock.patch.object(self.dbapi, 'create_node', autospec=True) as mock_create_node: mock_create_node.return_value = self.fake_node node = objects.Node(self.context, **self.fake_node) node.create() mock_create_node.assert_called_once_with(self.fake_node) self.assertEqual(self.context, node._context)
def get_test_node(context, **kw): """Return a Node object with appropriate attributes. NOTE: The object leaves the attributes marked as changed, such that a create() could be used to commit it to the DB. """ db_node = db_utils.get_test_node(**kw) # Let DB generate ID if it isn't specified explicitly if 'id' not in kw: del db_node['id'] node = objects.Node(context) for key in db_node: setattr(node, key, db_node[key]) return node
def post(self, node): """Create a new node. :param node: a node within the request body. """ node_dict = node.as_dict() context = pecan.request.context node_dict['project_id'] = context.project_id node_dict['user_id'] = context.user_id new_node = objects.Node(context, **node_dict) new_node.create() # Set the HTTP Location Header pecan.response.location = link.build_url('nodes', new_node.uuid) return Node.convert_with_links(new_node)
def post(self, node): """Create a new node. :param node: a node within the request body. """ if self.from_nodes: raise exception.OperationNotPermitted node_dict = node.as_dict() context = pecan.request.context auth_token = context.auth_token_info['token'] node_dict['project_id'] = auth_token['project']['id'] node_dict['user_id'] = auth_token['user']['id'] new_node = objects.Node(context, **node_dict) new_node.create() # Set the HTTP Location Header pecan.response.location = link.build_url('nodes', new_node.uuid) return Node.convert_with_links(new_node)