Use real context for db test
Using real context makes the test case more clear and easy to understand Change-Id: Ife8473decae25c4dceda3eb5158d127a654e554d
This commit is contained in:
parent
4b3712bddd
commit
8c22e3a006
|
@ -50,7 +50,18 @@ class TestCase(base.BaseTestCase):
|
|||
os.path.dirname(__file__),
|
||||
'config.py'
|
||||
))
|
||||
self.context = magnum_context.RequestContext()
|
||||
token_info = {
|
||||
'token': {
|
||||
'project': {
|
||||
'id': 'fake_project'
|
||||
},
|
||||
'user': {
|
||||
'id': 'fake_user'
|
||||
}
|
||||
}
|
||||
}
|
||||
self.context = magnum_context.RequestContext(
|
||||
auth_token_info=token_info)
|
||||
self.useFixture(conf_fixture.ConfFixture(cfg.CONF))
|
||||
|
||||
self._base_test_obj_backup = copy.copy(
|
||||
|
|
|
@ -15,10 +15,8 @@
|
|||
|
||||
"""Tests for manipulating Bays via the DB API"""
|
||||
|
||||
from mock import patch
|
||||
import six
|
||||
|
||||
from magnum.common import context
|
||||
from magnum.common import exception
|
||||
from magnum.common import utils as magnum_utils
|
||||
from magnum.tests.db import base
|
||||
|
@ -27,15 +25,6 @@ from magnum.tests.db import utils
|
|||
|
||||
class DbBayTestCase(base.DbTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(DbBayTestCase, self).setUp()
|
||||
p = patch.object(context, 'RequestContext')
|
||||
self.mock_context = p.start()
|
||||
mock_auth_token = self.mock_context.auth_token_info['token']
|
||||
mock_auth_token['project']['id'].return_value = 'fake_project'
|
||||
mock_auth_token['user']['id'].return_value = 'fake_user'
|
||||
self.addCleanup(p.stop)
|
||||
|
||||
def test_create_bay(self):
|
||||
utils.create_test_bay()
|
||||
|
||||
|
@ -55,7 +44,7 @@ class DbBayTestCase(base.DbTestCase):
|
|||
|
||||
def test_get_bay_by_uuid(self):
|
||||
bay = utils.create_test_bay()
|
||||
res = self.dbapi.get_bay_by_uuid(self.mock_context, bay.uuid)
|
||||
res = self.dbapi.get_bay_by_uuid(self.context, bay.uuid)
|
||||
self.assertEqual(bay.id, res.id)
|
||||
self.assertEqual(bay.uuid, res.uuid)
|
||||
|
||||
|
@ -64,7 +53,7 @@ class DbBayTestCase(base.DbTestCase):
|
|||
self.dbapi.get_bay_by_id, 999)
|
||||
self.assertRaises(exception.BayNotFound,
|
||||
self.dbapi.get_bay_by_uuid,
|
||||
self.mock_context,
|
||||
self.context,
|
||||
'12345678-9999-0000-aaaa-123456789012')
|
||||
|
||||
def test_get_bayinfo_list_defaults(self):
|
||||
|
@ -194,11 +183,11 @@ class DbBayTestCase(base.DbTestCase):
|
|||
|
||||
def test_destroy_bay_by_uuid(self):
|
||||
bay = utils.create_test_bay()
|
||||
self.assertIsNotNone(self.dbapi.get_bay_by_uuid(self.mock_context,
|
||||
self.assertIsNotNone(self.dbapi.get_bay_by_uuid(self.context,
|
||||
bay.uuid))
|
||||
self.dbapi.destroy_bay(bay.uuid)
|
||||
self.assertRaises(exception.BayNotFound,
|
||||
self.dbapi.get_bay_by_uuid, self.mock_context,
|
||||
self.dbapi.get_bay_by_uuid, self.context,
|
||||
bay.uuid)
|
||||
|
||||
def test_destroy_bay_that_does_not_exist(self):
|
||||
|
|
|
@ -21,8 +21,8 @@ from magnum.db import api as db_api
|
|||
def get_test_baymodel(**kw):
|
||||
return {
|
||||
'id': kw.get('id', 32),
|
||||
'project_id': kw.get('project_id', 'fake-project'),
|
||||
'user_id': kw.get('user_id', 'fake-user'),
|
||||
'project_id': kw.get('project_id', 'fake_project'),
|
||||
'user_id': kw.get('user_id', 'fake_user'),
|
||||
'uuid': kw.get('uuid', 'e74c40e0-d825-11e2-a28f-0800200c9a66'),
|
||||
'name': kw.get('name', 'baymodel1'),
|
||||
'image_id': kw.get('image_id', 'ubuntu'),
|
||||
|
@ -42,8 +42,8 @@ def get_test_bay(**kw):
|
|||
'id': kw.get('id', 42),
|
||||
'uuid': kw.get('uuid', '5d12f6fd-a196-4bf0-ae4c-1f639a523a52'),
|
||||
'name': kw.get('name', 'bay1'),
|
||||
'project_id': kw.get('project_id', 'fake-project'),
|
||||
'user_id': kw.get('user_id', 'fake-user'),
|
||||
'project_id': kw.get('project_id', 'fake_project'),
|
||||
'user_id': kw.get('user_id', 'fake_user'),
|
||||
'baymodel_id': kw.get('baymodel_id',
|
||||
'e74c40e0-d825-11e2-a28f-0800200c9a66'),
|
||||
'stack_id': kw.get('stack_id', '047c6319-7abd-4bd9-a033-8c6af0173cd0'),
|
||||
|
@ -132,8 +132,8 @@ def get_test_node(**kw):
|
|||
'id': kw.get('id', 42),
|
||||
'uuid': kw.get('uuid', 'ea8e2a25-2901-438d-8157-de7ffd68d051'),
|
||||
'type': kw.get('type', 'virt'),
|
||||
'project_id': kw.get('project_id', 'fake-project'),
|
||||
'user_id': kw.get('user_id', 'fake-user'),
|
||||
'project_id': kw.get('project_id', 'fake_project'),
|
||||
'user_id': kw.get('user_id', 'fake_user'),
|
||||
'image_id': kw.get('image_id', 'ubuntu'),
|
||||
'ironic_node_id': kw.get('ironic_node_id'),
|
||||
'created_at': kw.get('created_at'),
|
||||
|
@ -160,8 +160,8 @@ def get_test_container(**kw):
|
|||
'id': kw.get('id', 42),
|
||||
'uuid': kw.get('uuid', 'ea8e2a25-2901-438d-8157-de7ffd68d051'),
|
||||
'name': kw.get('name', 'container1'),
|
||||
'project_id': kw.get('project_id', 'fake-project'),
|
||||
'user_id': kw.get('user_id', 'fake-user'),
|
||||
'project_id': kw.get('project_id', 'fake_project'),
|
||||
'user_id': kw.get('user_id', 'fake_user'),
|
||||
'image_id': kw.get('image_id', 'ubuntu'),
|
||||
'created_at': kw.get('created_at'),
|
||||
'updated_at': kw.get('updated_at'),
|
||||
|
|
Loading…
Reference in New Issue