def test_destroy(self, plan_destroy): db_plan = fake_plan.fake_db_plan() plan = objects.Plan._from_db_object(self.context, objects.Plan(), db_plan) plan.destroy() self.assertTrue(plan_destroy.called) admin_context = plan_destroy.call_args[0][0] self.assertTrue(admin_context.is_admin)
def test_save(self, plan_update): db_plan = fake_plan.fake_db_plan() plan = objects.Plan._from_db_object(self.context, objects.Plan(), db_plan) plan.name = 'planname' plan.save() plan_update.assert_called_once_with(self.context, plan.id, {'name': 'planname'})
def create(self, req, body): """Creates a new plan.""" if not self.is_valid_body(body, 'plan'): raise exc.HTTPUnprocessableEntity() LOG.debug('Create plan request body: %s', body) context = req.environ['smaug.context'] check_policy(context, 'create') plan = body['plan'] LOG.debug('Create plan request plan: %s', plan) if not plan.get("provider_id"): msg = _("provider_id must be provided when creating " "a plan.") raise exception.InvalidInput(reason=msg) if not plan.get("parameters"): msg = _("parameters must be provided when creating " "a plan.") raise exception.InvalidInput(reason=msg) parameters = plan.get("parameters") if not isinstance(parameters, dict): msg = _("parameters must be a dict when creating a plan.") raise exception.InvalidInput(reason=msg) self.validate_name_and_description(plan) self.validate_plan_resources(plan) plan_properties = { 'name': plan.get('name', None), 'provider_id': plan.get('provider_id', None), 'project_id': context.project_id, 'status': 'suspended', 'resources': plan.get('resources', None), 'parameters': parameters, } plan = objects.Plan(context=context, **plan_properties) plan.create() retval = self._view_builder.detail(req, plan) return retval
def test_save_with_resource(self, plan_update, resource_update): db_plan = fake_plan.fake_db_plan() plan = objects.Plan._from_db_object(self.context, objects.Plan(), db_plan) plan.name = 'planname' plan.resources = [{'id': 'key1', "type": "value1"}] self.assertEqual( { 'name': 'planname', 'resources': [{ 'id': 'key1', "type": "value1" }] }, plan.obj_get_changes()) plan.save() plan_update.assert_called_once_with(self.context, plan.id, {'name': 'planname'}) resource_update.assert_called_once_with(self.context, plan.id, [{ 'id': 'key1', "type": "value1" }])
def test_parameters(self): db_plan = fake_plan.fake_db_plan() plan = objects.Plan._from_db_object(self.context, objects.Plan(), db_plan) self.assertEqual(plan.parameters, jsonutils.loads(fake_plan.db_plan['parameters']))
def test_create(self, plan_create): db_plan = fake_plan.fake_db_plan() plan_create.return_value = db_plan plan = objects.Plan(context=self.context) plan.create() self.assertEqual(db_plan['id'], plan.id)
def test_obj_field_status(self): plan = objects.Plan(context=self.context, status='suspending') self.assertEqual('suspending', plan.status)
def test_obj_fields(self): plan = objects.Plan(context=self.context, id="2", name="testname") self.assertEqual(['plan_resources'], plan.obj_extra_fields) self.assertEqual('testname', plan.name) self.assertEqual('2', plan.id)