@base.remotable
def destroy(self):
- db.backup_destroy(self._context, self.id)
+ with self.obj_as_admin():
+ db.backup_destroy(self._context, self.id)
@base.CinderObjectRegistry.register
import mock
+from cinder import context
from cinder import objects
from cinder.tests.unit import fake_volume
from cinder.tests.unit import objects as test_objects
class TestBackup(test_objects.BaseObjectsTestCase):
+ def setUp(self):
+ super(TestBackup, self).setUp()
+ # NOTE (e0ne): base tests contains original RequestContext from
+ # oslo_context. We change it to our RequestContext implementation
+ # to have 'elevated' method
+ self.context = context.RequestContext(self.user_id, self.project_id,
+ is_admin=False)
+
@staticmethod
def _compare(test, db, obj):
for field, value in db.items():
def test_destroy(self, backup_destroy):
backup = objects.Backup(context=self.context, id=1)
backup.destroy()
- backup_destroy.assert_called_once_with(self.context, '1')
+ self.assertTrue(backup_destroy.called)
+ admin_context = backup_destroy.call_args[0][0]
+ self.assertTrue(admin_context.is_admin)
class TestBackupList(test_objects.BaseObjectsTestCase):