summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-08-02 23:04:40 +0000
committerGerrit Code Review <review@openstack.org>2012-08-02 23:04:40 +0000
commitb8bae714f402c90ce78da7be80d4dad1d4285d3b (patch)
tree30c7023a747ca20110de285a3cb8d9737a603b82
parent3924e32c9920e476210dec9f15c11f6e96206cb9 (diff)
parentaec2b668b554362700cf0c2b016e74fb1b7184f7 (diff)
downloadnova-b8bae714f402c90ce78da7be80d4dad1d4285d3b.tar.gz
nova-b8bae714f402c90ce78da7be80d4dad1d4285d3b.tar.xz
nova-b8bae714f402c90ce78da7be80d4dad1d4285d3b.zip
Merge "Simple refactor of some db api tests."
-rw-r--r--nova/tests/test_db_api.py29
1 files changed, 15 insertions, 14 deletions
diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py
index f2500667d..b2b1cf9e2 100644
--- a/nova/tests/test_db_api.py
+++ b/nova/tests/test_db_api.py
@@ -39,28 +39,29 @@ class DbApiTestCase(test.TestCase):
self.project_id = 'fake'
self.context = context.RequestContext(self.user_id, self.project_id)
+ def create_instances_with_args(self, **kwargs):
+ args = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1',
+ 'project_id': self.project_id}
+ args.update(kwargs)
+ return db.instance_create(self.context, args)
+
def test_instance_get_all_by_filters(self):
- args = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
- db.instance_create(self.context, args)
- db.instance_create(self.context, args)
- result = db.instance_get_all_by_filters(self.context.elevated(), {})
+ self.create_instances_with_args()
+ self.create_instances_with_args()
+ result = db.instance_get_all_by_filters(self.context, {})
self.assertEqual(2, len(result))
def test_instance_get_all_by_filters_unicode_value(self):
- args = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1',
- 'display_name': u'test♥'}
- db.instance_create(self.context, args)
- result = db.instance_get_all_by_filters(self.context.elevated(),
+ self.create_instances_with_args(display_name=u'test♥')
+ result = db.instance_get_all_by_filters(self.context,
{'display_name': u'test'})
self.assertEqual(1, len(result))
def test_instance_get_all_by_filters_deleted(self):
- args1 = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
- inst1 = db.instance_create(self.context, args1)
- args2 = {'reservation_id': 'b', 'image_ref': 1, 'host': 'host1'}
- inst2 = db.instance_create(self.context, args2)
- db.instance_destroy(self.context.elevated(), inst1['uuid'])
- result = db.instance_get_all_by_filters(self.context.elevated(), {})
+ inst1 = self.create_instances_with_args()
+ inst2 = self.create_instances_with_args(reservation_id='b')
+ db.instance_destroy(self.context, inst1['uuid'])
+ result = db.instance_get_all_by_filters(self.context, {})
self.assertEqual(2, len(result))
self.assertIn(inst1.id, [result[0].id, result[1].id])
self.assertIn(inst2.id, [result[0].id, result[1].id])