From 9df460a5cb2de96133028949ad12ac7c16dbd7fc Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 8 Sep 2010 19:57:29 +0200 Subject: Remove tornado-related code from almost everything. Left it in api where it is still being used pending gundlach's changes. --- nova/tests/access_unittest.py | 2 +- nova/tests/auth_unittest.py | 2 +- nova/tests/cloud_unittest.py | 14 ++++++++------ nova/tests/objectstore_unittest.py | 2 +- nova/tests/rpc_unittest.py | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/access_unittest.py b/nova/tests/access_unittest.py index fa0a090a0..4cdf42091 100644 --- a/nova/tests/access_unittest.py +++ b/nova/tests/access_unittest.py @@ -30,7 +30,7 @@ FLAGS = flags.FLAGS class Context(object): pass -class AccessTestCase(test.BaseTestCase): +class AccessTestCase(test.TrialTestCase): def setUp(self): super(AccessTestCase, self).setUp() FLAGS.connection_type = 'fake' diff --git a/nova/tests/auth_unittest.py b/nova/tests/auth_unittest.py index 0b404bfdc..b219d0e3c 100644 --- a/nova/tests/auth_unittest.py +++ b/nova/tests/auth_unittest.py @@ -31,7 +31,7 @@ from nova.endpoint import cloud FLAGS = flags.FLAGS -class AuthTestCase(test.BaseTestCase): +class AuthTestCase(test.TrialTestCase): flush_db = False def setUp(self): super(AuthTestCase, self).setUp() diff --git a/nova/tests/cloud_unittest.py b/nova/tests/cloud_unittest.py index 900ff5a97..0add53937 100644 --- a/nova/tests/cloud_unittest.py +++ b/nova/tests/cloud_unittest.py @@ -19,7 +19,6 @@ import logging import StringIO import time -from tornado import ioloop from twisted.internet import defer import unittest from xml.etree import ElementTree @@ -36,7 +35,7 @@ from nova.endpoint import cloud FLAGS = flags.FLAGS -class CloudTestCase(test.BaseTestCase): +class CloudTestCase(test.TrialTestCase): def setUp(self): super(CloudTestCase, self).setUp() self.flags(connection_type='fake', @@ -51,18 +50,21 @@ class CloudTestCase(test.BaseTestCase): # set up a service self.compute = service.ComputeService() self.compute_consumer = rpc.AdapterConsumer(connection=self.conn, - topic=FLAGS.compute_topic, - proxy=self.compute) - self.injected.append(self.compute_consumer.attach_to_tornado(self.ioloop)) + topic=FLAGS.compute_topic, + proxy=self.compute) + self.injected.append(self.compute_consumer.attach_to_twisted()) try: manager.AuthManager().create_user('admin', 'admin', 'admin') except: pass admin = manager.AuthManager().get_user('admin') project = manager.AuthManager().create_project('proj', 'admin', 'proj') - self.context = api.APIRequestContext(handler=None,project=project,user=admin) + self.context = api.APIRequestContext(handler=None, + project=project, + user=admin) def tearDown(self): + super(CloudTestCase, self).tearDown() manager.AuthManager().delete_project('proj') manager.AuthManager().delete_user('admin') diff --git a/nova/tests/objectstore_unittest.py b/nova/tests/objectstore_unittest.py index dece4b5d5..b5970d405 100644 --- a/nova/tests/objectstore_unittest.py +++ b/nova/tests/objectstore_unittest.py @@ -53,7 +53,7 @@ os.makedirs(os.path.join(OSS_TEMPDIR, 'images')) os.makedirs(os.path.join(OSS_TEMPDIR, 'buckets')) -class ObjectStoreTestCase(test.BaseTestCase): +class ObjectStoreTestCase(test.TrialTestCase): """Test objectstore API directly.""" def setUp(self): # pylint: disable-msg=C0103 diff --git a/nova/tests/rpc_unittest.py b/nova/tests/rpc_unittest.py index e12a28fbc..e11967987 100644 --- a/nova/tests/rpc_unittest.py +++ b/nova/tests/rpc_unittest.py @@ -30,7 +30,7 @@ from nova import test FLAGS = flags.FLAGS -class RpcTestCase(test.BaseTestCase): +class RpcTestCase(test.TrialTestCase): """Test cases for rpc""" def setUp(self): # pylint: disable-msg=C0103 super(RpcTestCase, self).setUp() @@ -40,7 +40,7 @@ class RpcTestCase(test.BaseTestCase): topic='test', proxy=self.receiver) - self.injected.append(self.consumer.attach_to_tornado(self.ioloop)) + self.injected.append(self.consumer.attach_to_twisted()) def test_call_succeed(self): """Get a value through rpc call""" -- cgit From 387671f9bc0299116ffbab7acfc47127afb989aa Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 8 Sep 2010 22:43:54 +0200 Subject: Tests turn things into inlineCallbacks. This is to duplicate the old behavior of BaseTestCase and to generally prevent the bad situation in that tests appear to be passing when in fact they haven't run because @defer.inlineCallbacks was forgotten. --- nova/tests/cloud_unittest.py | 2 +- nova/tests/rpc_unittest.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/cloud_unittest.py b/nova/tests/cloud_unittest.py index 0add53937..893717fe4 100644 --- a/nova/tests/cloud_unittest.py +++ b/nova/tests/cloud_unittest.py @@ -52,7 +52,7 @@ class CloudTestCase(test.TrialTestCase): self.compute_consumer = rpc.AdapterConsumer(connection=self.conn, topic=FLAGS.compute_topic, proxy=self.compute) - self.injected.append(self.compute_consumer.attach_to_twisted()) + self.compute_consumer.attach_to_twisted() try: manager.AuthManager().create_user('admin', 'admin', 'admin') diff --git a/nova/tests/rpc_unittest.py b/nova/tests/rpc_unittest.py index e11967987..1bb2405c7 100644 --- a/nova/tests/rpc_unittest.py +++ b/nova/tests/rpc_unittest.py @@ -39,8 +39,7 @@ class RpcTestCase(test.TrialTestCase): self.consumer = rpc.AdapterConsumer(connection=self.conn, topic='test', proxy=self.receiver) - - self.injected.append(self.consumer.attach_to_twisted()) + self.consumer.attach_to_twisted() def test_call_succeed(self): """Get a value through rpc call""" -- cgit From b68b73d08155483d19f4088baa6a4ffe73ef5f1d Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 21 Sep 2010 14:36:06 -0700 Subject: typo s/an/a --- nova/tests/rpc_unittest.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/rpc_unittest.py b/nova/tests/rpc_unittest.py index e12a28fbc..f4d7b4b28 100644 --- a/nova/tests/rpc_unittest.py +++ b/nova/tests/rpc_unittest.py @@ -67,6 +67,17 @@ class RpcTestCase(test.BaseTestCase): except rpc.RemoteError as exc: self.assertEqual(int(exc.value), value) + def test_pass_object(self): + """Test that we can pass objects through rpc""" + class x(): + pass + obj = x() + x.foo = 'bar' + x.baz = 100 + + result = yield rpc.call('test', {"method": "echo", + "args": {"value": obj}}) + print result class TestReceiver(object): """Simple Proxy class so the consumer has methods to call -- cgit From be214c0ecece6d9cffced02f397ba9ce42be6d9f Mon Sep 17 00:00:00 2001 From: Cerberus Date: Thu, 23 Sep 2010 16:45:30 -0500 Subject: whatever --- nova/tests/api/rackspace/servers.py | 13 +++++++++++-- nova/tests/api/rackspace/test_helper.py | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/rackspace/servers.py b/nova/tests/api/rackspace/servers.py index 6d628e78a..2cfb8d45f 100644 --- a/nova/tests/api/rackspace/servers.py +++ b/nova/tests/api/rackspace/servers.py @@ -16,19 +16,25 @@ # under the License. import unittest - +import stubout from nova.api.rackspace import servers +import nova.api.rackspace from nova.tests.api.test_helper import * +from nova.tests.api.rackspace import test_helper class ServersTest(unittest.TestCase): def setUp(self): self.stubs = stubout.StubOutForTesting() + test_helper.FakeAuthManager.auth_data = {} + test_helper.FakeAuthDatabase.data = {} + test_helper.stub_out_auth(self.stubs) def tearDown(self): self.stubs.UnsetAll() def test_get_server_list(self): - pass + req = webob.Request.blank('/v1.0/servers') + req.get_response(nova.api.API()) def test_create_instance(self): pass @@ -56,3 +62,6 @@ class ServersTest(unittest.TestCase): def test_delete_server_instance(self): pass + +if __name__ == "__main__": + unittest.main() diff --git a/nova/tests/api/rackspace/test_helper.py b/nova/tests/api/rackspace/test_helper.py index be14e2de8..1fb2a19cc 100644 --- a/nova/tests/api/rackspace/test_helper.py +++ b/nova/tests/api/rackspace/test_helper.py @@ -3,6 +3,7 @@ import webob.dec import datetime from nova.wsgi import Router from nova import auth +import nova.api.rackspace.auth class Context(object): pass @@ -24,6 +25,27 @@ def fake_auth_init(self): self.auth = FakeAuthManager() self.host = 'foo' +def stub_out_auth(stubs): + def fake_auth_init(self, app): + self.application = app + + def fake_rate_init(self, app): + super(nova.api.rackspace.RateLimitingMiddleware, self).__init__(app) + self.application = app + + @webob.dec.wsgify + def fake_wsgi(self, req): + return self.application + + stubs.Set(nova.api.rackspace.AuthMiddleware, + '__init__', fake_auth_init) + stubs.Set(nova.api.rackspace.RateLimitingMiddleware, + '__init__', fake_rate_init) + stubs.Set(nova.api.rackspace.AuthMiddleware, + '__call__', fake_wsgi) + stubs.Set(nova.api.rackspace.RateLimitingMiddleware, + '__call__', fake_wsgi) + class FakeAuthDatabase(object): data = {} -- cgit From 307b16447a16e438d78b8149418c0ef728c5300e Mon Sep 17 00:00:00 2001 From: Cerberus Date: Sat, 25 Sep 2010 13:00:19 -0500 Subject: Minor changes to be committed so trunk can be merged in --- nova/tests/api/rackspace/servers.py | 5 +++-- nova/tests/api/rackspace/test_helper.py | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/rackspace/servers.py b/nova/tests/api/rackspace/servers.py index 2cfb8d45f..6addc4614 100644 --- a/nova/tests/api/rackspace/servers.py +++ b/nova/tests/api/rackspace/servers.py @@ -33,8 +33,9 @@ class ServersTest(unittest.TestCase): self.stubs.UnsetAll() def test_get_server_list(self): - req = webob.Request.blank('/v1.0/servers') - req.get_response(nova.api.API()) + req = webob.Request.blank('/v1.0/servers/') + res = req.get_response(nova.api.API()) + print res def test_create_instance(self): pass diff --git a/nova/tests/api/rackspace/test_helper.py b/nova/tests/api/rackspace/test_helper.py index 1fb2a19cc..784f3e466 100644 --- a/nova/tests/api/rackspace/test_helper.py +++ b/nova/tests/api/rackspace/test_helper.py @@ -1,3 +1,4 @@ +from nova import utils import webob import webob.dec import datetime @@ -36,6 +37,9 @@ def stub_out_auth(stubs): @webob.dec.wsgify def fake_wsgi(self, req): return self.application + + def get_my_ip(): + return '127.0.0.1' stubs.Set(nova.api.rackspace.AuthMiddleware, '__init__', fake_auth_init) @@ -45,6 +49,7 @@ def stub_out_auth(stubs): '__call__', fake_wsgi) stubs.Set(nova.api.rackspace.RateLimitingMiddleware, '__call__', fake_wsgi) + stubs.Set(nova.utils, 'get_my_ip', get_my_ip) class FakeAuthDatabase(object): data = {} -- cgit From e627748aec6a4747e22975d6cd59c8f20bc00c70 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Sat, 25 Sep 2010 13:35:23 -0500 Subject: Modification of test stubbing to match new domain requirements for the router, and removal of the unnecessary rackspace base controller --- nova/tests/api/rackspace/auth.py | 4 ++-- nova/tests/api/rackspace/servers.py | 4 +++- nova/tests/api/rackspace/test_helper.py | 30 +++++++++++++++++++----------- 3 files changed, 24 insertions(+), 14 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/rackspace/auth.py b/nova/tests/api/rackspace/auth.py index 429c22ad2..a6e10970f 100644 --- a/nova/tests/api/rackspace/auth.py +++ b/nova/tests/api/rackspace/auth.py @@ -15,8 +15,8 @@ class Test(unittest.TestCase): '__init__', test_helper.fake_auth_init) test_helper.FakeAuthManager.auth_data = {} test_helper.FakeAuthDatabase.data = {} - self.stubs.Set(nova.api.rackspace, 'RateLimitingMiddleware', - test_helper.FakeRateLimiter) + test_helper.stub_out_rate_limiting(self.stubs) + test_helper.stub_for_testing(self.stubs) def tearDown(self): self.stubs.UnsetAll() diff --git a/nova/tests/api/rackspace/servers.py b/nova/tests/api/rackspace/servers.py index 6addc4614..e50581632 100644 --- a/nova/tests/api/rackspace/servers.py +++ b/nova/tests/api/rackspace/servers.py @@ -27,13 +27,15 @@ class ServersTest(unittest.TestCase): self.stubs = stubout.StubOutForTesting() test_helper.FakeAuthManager.auth_data = {} test_helper.FakeAuthDatabase.data = {} + test_helper.stub_for_testing(self.stubs) + test_helper.stub_out_rate_limiting(self.stubs) test_helper.stub_out_auth(self.stubs) def tearDown(self): self.stubs.UnsetAll() def test_get_server_list(self): - req = webob.Request.blank('/v1.0/servers/') + req = webob.Request.blank('/v1.0/servers') res = req.get_response(nova.api.API()) print res diff --git a/nova/tests/api/rackspace/test_helper.py b/nova/tests/api/rackspace/test_helper.py index 784f3e466..971eaf20a 100644 --- a/nova/tests/api/rackspace/test_helper.py +++ b/nova/tests/api/rackspace/test_helper.py @@ -5,6 +5,9 @@ import datetime from nova.wsgi import Router from nova import auth import nova.api.rackspace.auth +from nova import flags + +FLAGS = flags.FLAGS class Context(object): pass @@ -26,30 +29,35 @@ def fake_auth_init(self): self.auth = FakeAuthManager() self.host = 'foo' +@webob.dec.wsgify +def fake_wsgi(self, req): + return self.application + def stub_out_auth(stubs): def fake_auth_init(self, app): self.application = app + + stubs.Set(nova.api.rackspace.AuthMiddleware, + '__init__', fake_auth_init) + stubs.Set(nova.api.rackspace.AuthMiddleware, + '__call__', fake_wsgi) +def stub_out_rate_limiting(stubs): def fake_rate_init(self, app): super(nova.api.rackspace.RateLimitingMiddleware, self).__init__(app) self.application = app - @webob.dec.wsgify - def fake_wsgi(self, req): - return self.application - - def get_my_ip(): - return '127.0.0.1' - - stubs.Set(nova.api.rackspace.AuthMiddleware, - '__init__', fake_auth_init) stubs.Set(nova.api.rackspace.RateLimitingMiddleware, '__init__', fake_rate_init) - stubs.Set(nova.api.rackspace.AuthMiddleware, - '__call__', fake_wsgi) + stubs.Set(nova.api.rackspace.RateLimitingMiddleware, '__call__', fake_wsgi) + +def stub_for_testing(stubs): + def get_my_ip(): + return '127.0.0.1' stubs.Set(nova.utils, 'get_my_ip', get_my_ip) + FLAGS.FAKE_subdomain = 'rs' class FakeAuthDatabase(object): data = {} -- cgit From 1c978e8414b5841c4caf856c80f385026600f54e Mon Sep 17 00:00:00 2001 From: Michael Gundlach Date: Mon, 27 Sep 2010 12:50:20 -0400 Subject: Support content type detection in serializer --- nova/tests/api/wsgi_test.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/wsgi_test.py b/nova/tests/api/wsgi_test.py index 786dc1bce..145b1bfee 100644 --- a/nova/tests/api/wsgi_test.py +++ b/nova/tests/api/wsgi_test.py @@ -91,6 +91,33 @@ class Test(unittest.TestCase): result = webob.Request.blank('/test/123').get_response(Router()) self.assertNotEqual(result.body, "123") - def test_serializer(self): - # TODO(eday): Placeholder for serializer testing. - pass + +class SerializerTest(unittest.TestCase): + + def match(self, url, accept, expect): + input_dict = dict(servers=dict(a=(2,3))) + expected_xml = '(2,3)' + expected_json = '{"servers":{"a":[2,3]}}' + req = webob.Request.blank(url, headers=dict(Accept=accept)) + result = wsgi.Serializer(req.environ).to_content_type(input_dict) + result = result.replace('\n', '').replace(' ', '') + if expect == 'xml': + self.assertEqual(result, expected_xml) + elif expect == 'json': + self.assertEqual(result, expected_json) + else: + raise "Bad expect value" + + def test_basic(self): + self.match('/servers/4.json', None, expect='json') + self.match('/servers/4', 'application/json', expect='json') + self.match('/servers/4', 'application/xml', expect='xml') + self.match('/servers/4.xml', None, expect='xml') + + def test_defaults_to_json(self): + self.match('/servers/4', None, expect='json') + self.match('/servers/4', 'text/html', expect='json') + + def test_suffix_takes_precedence_over_accept_header(self): + self.match('/servers/4.xml', 'application/json', expect='xml') + self.match('/servers/4.xml.', 'application/json', expect='json') -- cgit From 1d83acca365b13319bddbd628725d7b666879091 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 27 Sep 2010 12:58:35 -0500 Subject: More re-work around the ORM changes and testing --- nova/tests/api/rackspace/flavors.py | 15 ++++++++++++++- nova/tests/api/rackspace/servers.py | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 9 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/rackspace/flavors.py b/nova/tests/api/rackspace/flavors.py index fb8ba94a5..7bd1ea1c4 100644 --- a/nova/tests/api/rackspace/flavors.py +++ b/nova/tests/api/rackspace/flavors.py @@ -16,19 +16,32 @@ # under the License. import unittest +import stubout +import nova.api from nova.api.rackspace import flavors +from nova.tests.api.rackspace import test_helper from nova.tests.api.test_helper import * class FlavorsTest(unittest.TestCase): def setUp(self): self.stubs = stubout.StubOutForTesting() + test_helper.FakeAuthManager.auth_data = {} + test_helper.FakeAuthDatabase.data = {} + test_helper.stub_for_testing(self.stubs) + test_helper.stub_out_rate_limiting(self.stubs) + test_helper.stub_out_auth(self.stubs) def tearDown(self): self.stubs.UnsetAll() def test_get_flavor_list(self): - pass + req = webob.Request.blank('/v1.0/flavors') + res = req.get_response(nova.api.API()) + print res def test_get_flavor_by_id(self): pass + +if __name__ == '__main__': + unittest.main() diff --git a/nova/tests/api/rackspace/servers.py b/nova/tests/api/rackspace/servers.py index e50581632..0f3483207 100644 --- a/nova/tests/api/rackspace/servers.py +++ b/nova/tests/api/rackspace/servers.py @@ -17,10 +17,25 @@ import unittest import stubout -from nova.api.rackspace import servers import nova.api.rackspace +import nova.db.api +from nova import flags +from nova.api.rackspace import servers +from nova.db.sqlalchemy.models import Instance from nova.tests.api.test_helper import * from nova.tests.api.rackspace import test_helper +from nova import db + +FLAGS = flags.FLAGS + +def return_server(context, id): + return stub_instance(id) + +def return_servers(context): + return [stub_instance(i) for i in xrange(5)] + +def stub_instance(id): + return Instance(id=id, state=0, ) class ServersTest(unittest.TestCase): def setUp(self): @@ -30,26 +45,32 @@ class ServersTest(unittest.TestCase): test_helper.stub_for_testing(self.stubs) test_helper.stub_out_rate_limiting(self.stubs) test_helper.stub_out_auth(self.stubs) + self.stubs.Set(nova.db.api, 'instance_get_all', return_servers) + self.stubs.Set(nova.db.api, 'instance_get', return_server) def tearDown(self): self.stubs.UnsetAll() - def test_get_server_list(self): - req = webob.Request.blank('/v1.0/servers') + def test_get_server_by_id(self): + req = webob.Request.blank('/v1.0/servers/1') res = req.get_response(nova.api.API()) print res - def test_create_instance(self): + def test_get_backup_schedule(self): pass - def test_get_server_by_id(self): - pass + def test_get_server_list(self): + req = webob.Request.blank('/v1.0/servers') + res = req.get_response(nova.api.API()) + print res - def test_get_backup_schedule(self): + def test_create_instance(self): pass def test_get_server_details(self): - pass + req = webob.Request.blank('/v1.0/servers/detail') + res = req.get_response(nova.api.API()) + print res def test_get_server_ips(self): pass -- cgit From 0e6c3b6034ef4927e381b231bf120a4980512c4e Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 27 Sep 2010 17:01:37 -0500 Subject: Power state mapping --- nova/tests/api/rackspace/servers.py | 1 + nova/tests/api/test_helper.py | 1 + 2 files changed, 2 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/api/rackspace/servers.py b/nova/tests/api/rackspace/servers.py index 0f3483207..dd54a6ac8 100644 --- a/nova/tests/api/rackspace/servers.py +++ b/nova/tests/api/rackspace/servers.py @@ -53,6 +53,7 @@ class ServersTest(unittest.TestCase): def test_get_server_by_id(self): req = webob.Request.blank('/v1.0/servers/1') + req.headers['content-type'] = 'application/json' res = req.get_response(nova.api.API()) print res diff --git a/nova/tests/api/test_helper.py b/nova/tests/api/test_helper.py index 8151a4af6..d0a2cc027 100644 --- a/nova/tests/api/test_helper.py +++ b/nova/tests/api/test_helper.py @@ -1,4 +1,5 @@ import webob.dec +from nova import wsgi class APIStub(object): """Class to verify request and mark it was called.""" -- cgit From 2f72b2a9fc9fee508b16c0b96285124279ef89ca Mon Sep 17 00:00:00 2001 From: Cerberus Date: Tue, 28 Sep 2010 00:23:49 -0500 Subject: More cleanup, backup_schedules controller, server details and the beginnings of the servers action route --- nova/tests/api/rackspace/servers.py | 85 ++++++++++++++++++++++++++++----- nova/tests/api/rackspace/test_helper.py | 1 + 2 files changed, 73 insertions(+), 13 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/rackspace/servers.py b/nova/tests/api/rackspace/servers.py index dd54a6ac8..0ef0f4256 100644 --- a/nova/tests/api/rackspace/servers.py +++ b/nova/tests/api/rackspace/servers.py @@ -15,6 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. +import json import unittest import stubout import nova.api.rackspace @@ -35,7 +36,9 @@ def return_servers(context): return [stub_instance(i) for i in xrange(5)] def stub_instance(id): - return Instance(id=id, state=0, ) + return Instance( + id=id, state=0, image_id=10, server_name='server%s'%id + ) class ServersTest(unittest.TestCase): def setUp(self): @@ -53,9 +56,10 @@ class ServersTest(unittest.TestCase): def test_get_server_by_id(self): req = webob.Request.blank('/v1.0/servers/1') - req.headers['content-type'] = 'application/json' res = req.get_response(nova.api.API()) - print res + res_dict = json.loads(res.body) + self.assertEqual(res_dict['server']['id'], '1') + self.assertEqual(res_dict['server']['name'], 'server1') def test_get_backup_schedule(self): pass @@ -63,30 +67,85 @@ class ServersTest(unittest.TestCase): def test_get_server_list(self): req = webob.Request.blank('/v1.0/servers') res = req.get_response(nova.api.API()) - print res + res_dict = json.loads(res.body) + + i = 0 + for s in res_dict['servers']: + self.assertEqual(s['id'], i) + self.assertEqual(s['name'], 'server%d'%i) + self.assertEqual(s.get('imageId', None), None) + i += 1 def test_create_instance(self): pass - def test_get_server_details(self): - req = webob.Request.blank('/v1.0/servers/detail') - res = req.get_response(nova.api.API()) - print res + def test_update_server_password(self): + pass - def test_get_server_ips(self): + def test_update_server_name(self): pass + def test_create_backup_schedules(self): + req = webob.Request.blank('/v1.0/servers/1/backup_schedules') + req.method = 'POST' + res = req.get_response(nova.api.API()) + self.assertEqual(res.status, '404 Not Found') + + def test_delete_backup_schedules(self): + req = webob.Request.blank('/v1.0/servers/1/backup_schedules') + req.method = 'DELETE' + res = req.get_response(nova.api.API()) + self.assertEqual(res.status, '404 Not Found') + + def test_get_server_backup_schedules(self): + req = webob.Request.blank('/v1.0/servers/1/backup_schedules') + res = req.get_response(nova.api.API()) + self.assertEqual(res.status, '404 Not Found') + + def test_get_all_server_details(self): + req = webob.Request.blank('/v1.0/servers/detail') + res = req.get_response(nova.api.API()) + res_dict = json.loads(res.body) + + i = 0 + for s in res_dict['servers']: + self.assertEqual(s['id'], i) + self.assertEqual(s['name'], 'server%d'%i) + self.assertEqual(s['imageId'], 10) + i += 1 + def test_server_reboot(self): - pass + req = webob.Request.blank('/v1.0/servers/1/action') + req.method = 'POST' + res = req.get_response(nova.api.API()) + res_dict = json.loads(res.body) def test_server_rebuild(self): - pass + req = webob.Request.blank('/v1.0/servers/1/action') + req.method = 'POST' + res = req.get_response(nova.api.API()) + res_dict = json.loads(res.body) def test_server_resize(self): - pass + req = webob.Request.blank('/v1.0/servers/1/action') + req.method = 'POST' + res = req.get_response(nova.api.API()) + res_dict = json.loads(res.body) def test_delete_server_instance(self): - pass + req = webob.Request.blank('/v1.0/servers/1') + req.method = 'DELETE' + + self.server_delete_called = False + def instance_destroy_mock(context, id): + self.server_delete_called = True + + self.stubs.Set(nova.db.api, 'instance_destroy', + instance_destroy_mock) + + res = req.get_response(nova.api.API()) + self.assertEqual(res.status, '202 Accepted') + self.assertEqual(self.server_delete_called, True) if __name__ == "__main__": unittest.main() diff --git a/nova/tests/api/rackspace/test_helper.py b/nova/tests/api/rackspace/test_helper.py index 971eaf20a..d44b8c30e 100644 --- a/nova/tests/api/rackspace/test_helper.py +++ b/nova/tests/api/rackspace/test_helper.py @@ -31,6 +31,7 @@ def fake_auth_init(self): @webob.dec.wsgify def fake_wsgi(self, req): + req.environ['nova.context'] = dict(user=dict(id=1)) return self.application def stub_out_auth(stubs): -- cgit From 7e25838ea1965231df09f29675fc3ab40e194483 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Tue, 28 Sep 2010 00:44:32 -0500 Subject: db api call to get instances by user and user checking in each of the server actions --- nova/tests/api/rackspace/servers.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/rackspace/servers.py b/nova/tests/api/rackspace/servers.py index 0ef0f4256..674dab0b6 100644 --- a/nova/tests/api/rackspace/servers.py +++ b/nova/tests/api/rackspace/servers.py @@ -32,12 +32,14 @@ FLAGS = flags.FLAGS def return_server(context, id): return stub_instance(id) -def return_servers(context): - return [stub_instance(i) for i in xrange(5)] +def return_servers(context, user_id=1): + return [stub_instance(i, user_id) for i in xrange(5)] -def stub_instance(id): + +def stub_instance(id, user_id=1): return Instance( - id=id, state=0, image_id=10, server_name='server%s'%id + id=id, state=0, image_id=10, server_name='server%s'%id, + user_id=user_id ) class ServersTest(unittest.TestCase): @@ -50,6 +52,8 @@ class ServersTest(unittest.TestCase): test_helper.stub_out_auth(self.stubs) self.stubs.Set(nova.db.api, 'instance_get_all', return_servers) self.stubs.Set(nova.db.api, 'instance_get', return_server) + self.stubs.Set(nova.db.api, 'instance_get_all_by_user', + return_servers) def tearDown(self): self.stubs.UnsetAll() -- cgit From fd41a784ccee500ae8a36311ad3c80963e866b31 Mon Sep 17 00:00:00 2001 From: Michael Gundlach Date: Tue, 28 Sep 2010 12:54:17 -0400 Subject: Add Serializer.deserialize(xml_or_json_string) --- nova/tests/api/wsgi_test.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/api/wsgi_test.py b/nova/tests/api/wsgi_test.py index 145b1bfee..9425b01d0 100644 --- a/nova/tests/api/wsgi_test.py +++ b/nova/tests/api/wsgi_test.py @@ -121,3 +121,27 @@ class SerializerTest(unittest.TestCase): def test_suffix_takes_precedence_over_accept_header(self): self.match('/servers/4.xml', 'application/json', expect='xml') self.match('/servers/4.xml.', 'application/json', expect='json') + + def test_deserialize(self): + xml = """ + + 123 + 1 + 1 + + """.strip() + as_dict = dict(a={ + 'a1': '1', + 'a2': '2', + 'bs': ['1', '2', '3', {'c': dict(c1='1')}], + 'd': {'e': '1'}, + 'f': '1'}) + metadata = {'application/xml': dict(plurals={'bs': 'b', 'ts': 't'})} + serializer = wsgi.Serializer({}, metadata) + self.assertEqual(serializer.deserialize(xml), as_dict) + + def test_deserialize_empty_xml(self): + xml = """""" + as_dict = {"a": {}} + serializer = wsgi.Serializer({}) + self.assertEqual(serializer.deserialize(xml), as_dict) -- cgit From 663ed27a2d7b3cb3a5290e0516eb8d602d7e65ba Mon Sep 17 00:00:00 2001 From: Cerberus Date: Tue, 28 Sep 2010 12:56:01 -0500 Subject: Testing testing testing --- nova/tests/api/rackspace/servers.py | 37 +++++++++++++++++++++++++++------ nova/tests/api/rackspace/test_helper.py | 22 ++++++++++++++++++-- 2 files changed, 51 insertions(+), 8 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/rackspace/servers.py b/nova/tests/api/rackspace/servers.py index 674dab0b6..a22736dd2 100644 --- a/nova/tests/api/rackspace/servers.py +++ b/nova/tests/api/rackspace/servers.py @@ -80,9 +80,19 @@ class ServersTest(unittest.TestCase): self.assertEqual(s.get('imageId', None), None) i += 1 - def test_create_instance(self): - pass - + #def test_create_instance(self): + # test_helper.stub_out_image_translator(self.stubs) + # body = dict(server=dict( + # name='server_test', imageId=2, flavorId=2, metadata={}, + # personality = {} + # )) + # req = webob.Request.blank('/v1.0/servers') + # req.method = 'POST' + # req.body = json.dumps(body) + + # res = req.get_response(nova.api.API()) + + # print res def test_update_server_password(self): pass @@ -119,22 +129,37 @@ class ServersTest(unittest.TestCase): i += 1 def test_server_reboot(self): + body = dict(server=dict( + name='server_test', imageId=2, flavorId=2, metadata={}, + personality = {} + )) req = webob.Request.blank('/v1.0/servers/1/action') req.method = 'POST' + req.content_type= 'application/json' + req.body = json.dumps(body) res = req.get_response(nova.api.API()) - res_dict = json.loads(res.body) def test_server_rebuild(self): + body = dict(server=dict( + name='server_test', imageId=2, flavorId=2, metadata={}, + personality = {} + )) req = webob.Request.blank('/v1.0/servers/1/action') req.method = 'POST' + req.content_type= 'application/json' + req.body = json.dumps(body) res = req.get_response(nova.api.API()) - res_dict = json.loads(res.body) def test_server_resize(self): + body = dict(server=dict( + name='server_test', imageId=2, flavorId=2, metadata={}, + personality = {} + )) req = webob.Request.blank('/v1.0/servers/1/action') req.method = 'POST' + req.content_type= 'application/json' + req.body = json.dumps(body) res = req.get_response(nova.api.API()) - res_dict = json.loads(res.body) def test_delete_server_instance(self): req = webob.Request.blank('/v1.0/servers/1') diff --git a/nova/tests/api/rackspace/test_helper.py b/nova/tests/api/rackspace/test_helper.py index d44b8c30e..09ff26ac7 100644 --- a/nova/tests/api/rackspace/test_helper.py +++ b/nova/tests/api/rackspace/test_helper.py @@ -1,10 +1,12 @@ -from nova import utils +import json import webob import webob.dec import datetime +import nova.api.rackspace.auth +import nova.api.rackspace._id_translator from nova.wsgi import Router from nova import auth -import nova.api.rackspace.auth +from nova import utils from nova import flags FLAGS = flags.FLAGS @@ -32,8 +34,24 @@ def fake_auth_init(self): @webob.dec.wsgify def fake_wsgi(self, req): req.environ['nova.context'] = dict(user=dict(id=1)) + if req.body: + req.environ['inst_dict'] = json.loads(req.body) return self.application +def stub_out_image_translator(stubs): + class FakeTranslator(object): + def __init__(self, id_type, service_name): + pass + + def to_rs_id(self, id): + return id + + def from_rs_id(self, id): + return id + + stubs.Set(nova.api.rackspace._id_translator, + 'RackspaceAPIIdTranslator', FakeTranslator) + def stub_out_auth(stubs): def fake_auth_init(self, app): self.application = app -- cgit From 641b6ee5630ed00ee3e921769cd408a8603ff62b Mon Sep 17 00:00:00 2001 From: Cerberus Date: Tue, 28 Sep 2010 16:46:21 -0500 Subject: Merge prop fixes and pylint/pep8 cleanup --- nova/tests/api/rackspace/servers.py | 8 +++++--- nova/tests/api/rackspace/test_helper.py | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/rackspace/servers.py b/nova/tests/api/rackspace/servers.py index a22736dd2..9fd8e5e88 100644 --- a/nova/tests/api/rackspace/servers.py +++ b/nova/tests/api/rackspace/servers.py @@ -17,15 +17,17 @@ import json import unittest + import stubout -import nova.api.rackspace -import nova.db.api + +from nova import db from nova import flags +import nova.api.rackspace from nova.api.rackspace import servers +import nova.db.api from nova.db.sqlalchemy.models import Instance from nova.tests.api.test_helper import * from nova.tests.api.rackspace import test_helper -from nova import db FLAGS = flags.FLAGS diff --git a/nova/tests/api/rackspace/test_helper.py b/nova/tests/api/rackspace/test_helper.py index 09ff26ac7..aa7fb382c 100644 --- a/nova/tests/api/rackspace/test_helper.py +++ b/nova/tests/api/rackspace/test_helper.py @@ -1,13 +1,15 @@ +import datetime import json + import webob import webob.dec -import datetime -import nova.api.rackspace.auth -import nova.api.rackspace._id_translator -from nova.wsgi import Router + from nova import auth from nova import utils from nova import flags +import nova.api.rackspace.auth +import nova.api.rackspace._id_translator +from nova.wsgi import Router FLAGS = flags.FLAGS -- cgit From bbc00d9eca3b874e240e50bfa9f397afc36d0bee Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 28 Sep 2010 16:34:21 -0700 Subject: removed extra code that slipped in from a test branch --- nova/tests/rpc_unittest.py | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/rpc_unittest.py b/nova/tests/rpc_unittest.py index f4d7b4b28..e12a28fbc 100644 --- a/nova/tests/rpc_unittest.py +++ b/nova/tests/rpc_unittest.py @@ -67,17 +67,6 @@ class RpcTestCase(test.BaseTestCase): except rpc.RemoteError as exc: self.assertEqual(int(exc.value), value) - def test_pass_object(self): - """Test that we can pass objects through rpc""" - class x(): - pass - obj = x() - x.foo = 'bar' - x.baz = 100 - - result = yield rpc.call('test', {"method": "echo", - "args": {"value": obj}}) - print result class TestReceiver(object): """Simple Proxy class so the consumer has methods to call -- cgit