summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Santa Barbara <justin@fathomdb.com>2011-03-15 10:42:32 -0700
committerJustin Santa Barbara <justin@fathomdb.com>2011-03-15 10:42:32 -0700
commit56ff68056254610c4f0eb5cd5c5432a68ed30b2f (patch)
tree33be36b1843a53a988783b2eb5eba280d6e00b89
parentcc0340d7f9d9ab9b082af35df9b486c1e9a5a967 (diff)
downloadnova-56ff68056254610c4f0eb5cd5c5432a68ed30b2f.tar.gz
nova-56ff68056254610c4f0eb5cd5c5432a68ed30b2f.tar.xz
nova-56ff68056254610c4f0eb5cd5c5432a68ed30b2f.zip
Support testing the OpenStack API without key_pairs
-rw-r--r--nova/tests/api/openstack/fakes.py11
-rw-r--r--nova/tests/api/openstack/test_servers.py9
2 files changed, 17 insertions, 3 deletions
diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py
index e50d11a3d..ccc853360 100644
--- a/nova/tests/api/openstack/fakes.py
+++ b/nova/tests/api/openstack/fakes.py
@@ -85,10 +85,17 @@ def wsgi_app(inner_application=None):
return mapper
-def stub_out_key_pair_funcs(stubs):
+def stub_out_key_pair_funcs(stubs, have_key_pair=True):
def key_pair(context, user_id):
return [dict(name='key', public_key='public_key')]
- stubs.Set(nova.db, 'key_pair_get_all_by_user', key_pair)
+
+ def no_key_pair(context, user_id):
+ return []
+
+ if have_key_pair:
+ stubs.Set(nova.db, 'key_pair_get_all_by_user', key_pair)
+ else:
+ stubs.Set(nova.db, 'key_pair_get_all_by_user', no_key_pair)
def stub_out_image_service(stubs):
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index 5d7a208e9..40026a615 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -216,7 +216,7 @@ class ServersTest(test.TestCase):
servers = json.loads(res.body)['servers']
self.assertEqual([s['id'] for s in servers], [1, 2])
- def test_create_instance(self):
+ def _test_create_instance_helper(self, with_key_pair):
def instance_create(context, inst):
return {'id': '1', 'display_name': 'server_test'}
@@ -271,6 +271,13 @@ class ServersTest(test.TestCase):
self.assertEqual(res.status_int, 200)
+ def test_create_instance(self):
+ self._test_create_instance_helper(True)
+
+ def test_create_instance_no_key_pair(self):
+ fakes.stub_out_key_pair_funcs(self.stubs, False)
+ self._test_create_instance_helper(False)
+
def test_update_no_body(self):
req = webob.Request.blank('/v1.0/servers/1')
req.method = 'PUT'