def test_save_metadata(self): add_meta = {'add_meta': 'addval'} del_meta = {'del_meta': 'delval'} id = self.fake_aggregate['id'] with mock.patch.object(self.dbapi, 'aggregate_update', autospec=True) as mock_aggregate_update: with mock.patch.object(self.dbapi, 'aggregate_metadata_update_or_create', autospec=True) as mock_aggregate_upcreate: with mock.patch.object(self.dbapi, 'aggregate_metadata_delete', autospec=True) as mock_aggregate_delete: aggregate = objects.Aggregate(self.context, **self.fake_aggregate) aggregate._orig_metadata = del_meta aggregate.metadata = add_meta updates = aggregate.obj_get_changes() del updates['metadata'] aggregate.save(self.context) mock_aggregate_update.return_value = self.fake_aggregate mock_aggregate_upcreate.assert_called_once_with( self.context, id, add_meta) mock_aggregate_delete.assert_called_once_with( self.context, id, 'del_meta') mock_aggregate_update.assert_called_once_with( self.context, id, updates)
def test_create(self): with mock.patch.object(self.dbapi, 'aggregate_create', autospec=True) as mock_aggregate_create: mock_aggregate_create.return_value = self.fake_aggregate aggregate = objects.Aggregate(self.context, **self.fake_aggregate) values = aggregate.obj_get_changes() aggregate.create(self.context) mock_aggregate_create.assert_called_once_with(self.context, values) self.assertEqual(self.fake_aggregate['uuid'], aggregate['uuid'])
def test_destroy(self): agg_id = self.fake_aggregate['id'] with mock.patch.object(self.dbapi, 'aggregate_destroy', autospec=True) as mock_aggregate_destroy: mock_aggregate_destroy.return_value = self.fake_aggregate aggregate = objects.Aggregate(self.context, **self.fake_aggregate) aggregate.destroy(self.context) mock_aggregate_destroy.assert_called_once_with( self.context, agg_id)
def test_save(self): id = self.fake_aggregate['id'] with mock.patch.object(self.dbapi, 'aggregate_update', autospec=True) as mock_aggregate_update: aggregate = objects.Aggregate(self.context, **self.fake_aggregate) aggregate.name = 'changed_name' updates = aggregate.obj_get_changes() aggregate.save(self.context) mock_aggregate_update.return_value = self.fake_aggregate mock_aggregate_update.assert_called_once_with( self.context, id, updates)
def post(self, aggregate): """Create a new aggregate. :param aggregate: an aggregate within the request body. """ validation.check_schema(aggregate, agg_schema.create_aggregate) metadata = aggregate.get('metadata') if metadata and 'availability_zone' in metadata: if not metadata['availability_zone']: msg = _("Aggregate %s does not support empty named " "availability zone") % aggregate['name'] raise wsme.exc.ClientSideError( msg, status_code=http_client.BAD_REQUEST) new_aggregate = objects.Aggregate(pecan.request.context, **aggregate) new_aggregate.create() # Set the HTTP Location Header pecan.response.location = link.build_url('aggregates', new_aggregate.uuid) return Aggregate.convert_with_links(new_aggregate)