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 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