diff options
| author | jaypipes@gmail.com <> | 2010-10-01 14:02:51 -0400 |
|---|---|---|
| committer | jaypipes@gmail.com <> | 2010-10-01 14:02:51 -0400 |
| commit | bf22bbd2d4f4364255a306e024d1a7d316b89014 (patch) | |
| tree | 21add38739528d4995d306544bb705d8a8f5b8df | |
| parent | 4d13a8554459638387d772a23fffe6aaaab3348d (diff) | |
| download | nova-bf22bbd2d4f4364255a306e024d1a7d316b89014.tar.gz nova-bf22bbd2d4f4364255a306e024d1a7d316b89014.tar.xz nova-bf22bbd2d4f4364255a306e024d1a7d316b89014.zip | |
Cleans up the unit tests that are meant to be run with nosetests
* Renames all test modules to start with test_ so that nosetests does
not need to be run with the --all-modules flag in order to pick them up
* Renames test_helper to fakes and removes imports in unit tests that
did not reference the fakes
* Adds nose to pip-requires so that run_tests.sh -V will install nose
into the virtualenv instead of having to manually install it after running
into import errors :)
| -rw-r--r-- | nova/tests/api/__init__.py | 3 | ||||
| -rw-r--r-- | nova/tests/api/fakes.py (renamed from nova/tests/api/test_helper.py) | 0 | ||||
| -rw-r--r-- | nova/tests/api/rackspace/__init__.py | 4 | ||||
| -rw-r--r-- | nova/tests/api/rackspace/fakes.py (renamed from nova/tests/api/rackspace/test_helper.py) | 16 | ||||
| -rw-r--r-- | nova/tests/api/rackspace/test_auth.py (renamed from nova/tests/api/rackspace/auth.py) | 24 | ||||
| -rw-r--r-- | nova/tests/api/rackspace/test_faults.py (renamed from nova/tests/api/rackspace/testfaults.py) | 0 | ||||
| -rw-r--r-- | nova/tests/api/rackspace/test_flavors.py (renamed from nova/tests/api/rackspace/flavors.py) | 16 | ||||
| -rw-r--r-- | nova/tests/api/rackspace/test_images.py (renamed from nova/tests/api/rackspace/images.py) | 7 | ||||
| -rw-r--r-- | nova/tests/api/rackspace/test_servers.py (renamed from nova/tests/api/rackspace/servers.py) | 27 | ||||
| -rw-r--r-- | nova/tests/api/rackspace/test_sharedipgroups.py (renamed from nova/tests/api/rackspace/sharedipgroups.py) | 8 | ||||
| -rw-r--r-- | nova/tests/api/test_wsgi.py (renamed from nova/tests/api/wsgi_test.py) | 0 | ||||
| -rw-r--r-- | tools/pip-requires | 1 |
12 files changed, 63 insertions, 43 deletions
diff --git a/nova/tests/api/__init__.py b/nova/tests/api/__init__.py index fc1ab9ae2..ec76aa827 100644 --- a/nova/tests/api/__init__.py +++ b/nova/tests/api/__init__.py @@ -27,7 +27,8 @@ import webob.dec import nova.exception from nova import api -from nova.tests.api.test_helper import * +from nova.tests.api.fakes import APIStub + class Test(unittest.TestCase): diff --git a/nova/tests/api/test_helper.py b/nova/tests/api/fakes.py index d0a2cc027..d0a2cc027 100644 --- a/nova/tests/api/test_helper.py +++ b/nova/tests/api/fakes.py diff --git a/nova/tests/api/rackspace/__init__.py b/nova/tests/api/rackspace/__init__.py index bfd0f87a7..1834f91b1 100644 --- a/nova/tests/api/rackspace/__init__.py +++ b/nova/tests/api/rackspace/__init__.py @@ -19,7 +19,7 @@ import unittest from nova.api.rackspace import limited from nova.api.rackspace import RateLimitingMiddleware -from nova.tests.api.test_helper import * +from nova.tests.api.fakes import APIStub from webob import Request @@ -82,7 +82,7 @@ class RateLimitingMiddlewareTest(unittest.TestCase): class LimiterTest(unittest.TestCase): - def testLimiter(self): + def test_limiter(self): items = range(2000) req = Request.blank('/') self.assertEqual(limited(items, req), items[ :1000]) diff --git a/nova/tests/api/rackspace/test_helper.py b/nova/tests/api/rackspace/fakes.py index 2cf154f63..2c4447920 100644 --- a/nova/tests/api/rackspace/test_helper.py +++ b/nova/tests/api/rackspace/fakes.py @@ -12,11 +12,14 @@ import nova.api.rackspace._id_translator from nova.image import service from nova.wsgi import Router + FLAGS = flags.FLAGS + class Context(object): pass + class FakeRouter(Router): def __init__(self): pass @@ -28,12 +31,14 @@ class FakeRouter(Router): res.headers['X-Test-Success'] = 'True' return res + def fake_auth_init(self): self.db = FakeAuthDatabase() self.context = Context() self.auth = FakeAuthManager() self.host = 'foo' + @webob.dec.wsgify def fake_wsgi(self, req): req.environ['nova.context'] = dict(user=dict(id=1)) @@ -41,18 +46,21 @@ def fake_wsgi(self, req): req.environ['inst_dict'] = json.loads(req.body) return self.application + def stub_out_key_pair_funcs(stubs): def key_pair(context, user_id): return [dict(name='key', public_key='public_key')] stubs.Set(nova.db.api, 'key_pair_get_all_by_user', key_pair) + def stub_out_image_service(stubs): def fake_image_show(meh, id): return dict(kernelId=1, ramdiskId=1) stubs.Set(nova.image.service.LocalImageService, 'show', fake_image_show) + def stub_out_id_translator(stubs): class FakeTranslator(object): def __init__(self, id_type, service_name): @@ -67,6 +75,7 @@ def stub_out_id_translator(stubs): stubs.Set(nova.api.rackspace._id_translator, 'RackspaceAPIIdTranslator', FakeTranslator) + def stub_out_auth(stubs): def fake_auth_init(self, app): self.application = app @@ -76,6 +85,7 @@ def stub_out_auth(stubs): 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) @@ -87,12 +97,14 @@ def stub_out_rate_limiting(stubs): stubs.Set(nova.api.rackspace.RateLimitingMiddleware, '__call__', fake_wsgi) -def stub_for_testing(stubs): + +def stub_out_networking(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 = {} @@ -110,6 +122,7 @@ class FakeAuthDatabase(object): if FakeAuthDatabase.data.has_key(token['token_hash']): del FakeAuthDatabase.data['token_hash'] + class FakeAuthManager(object): auth_data = {} @@ -125,6 +138,7 @@ class FakeAuthManager(object): def get_user_from_access_key(self, key): return FakeAuthManager.auth_data.get(key, None) + class FakeRateLimiter(object): def __init__(self, application): self.application = application diff --git a/nova/tests/api/rackspace/auth.py b/nova/tests/api/rackspace/test_auth.py index 56677c2f4..374cfe42b 100644 --- a/nova/tests/api/rackspace/auth.py +++ b/nova/tests/api/rackspace/test_auth.py @@ -8,24 +8,24 @@ import webob.dec import nova.api import nova.api.rackspace.auth from nova import auth -from nova.tests.api.rackspace import test_helper +from nova.tests.api.rackspace import fakes class Test(unittest.TestCase): def setUp(self): self.stubs = stubout.StubOutForTesting() self.stubs.Set(nova.api.rackspace.auth.BasicApiAuthManager, - '__init__', test_helper.fake_auth_init) - test_helper.FakeAuthManager.auth_data = {} - test_helper.FakeAuthDatabase.data = {} - test_helper.stub_out_rate_limiting(self.stubs) - test_helper.stub_for_testing(self.stubs) + '__init__', fakes.fake_auth_init) + fakes.FakeAuthManager.auth_data = {} + fakes.FakeAuthDatabase.data = {} + fakes.stub_out_rate_limiting(self.stubs) + fakes.stub_out_networking(self.stubs) def tearDown(self): self.stubs.UnsetAll() - test_helper.fake_data_store = {} + fakes.fake_data_store = {} def test_authorize_user(self): - f = test_helper.FakeAuthManager() + f = fakes.FakeAuthManager() f.add_user('derp', { 'uid': 1, 'name':'herp' } ) req = webob.Request.blank('/v1.0/') @@ -39,7 +39,7 @@ class Test(unittest.TestCase): self.assertEqual(result.headers['X-Storage-Url'], "") def test_authorize_token(self): - f = test_helper.FakeAuthManager() + f = fakes.FakeAuthManager() f.add_user('derp', { 'uid': 1, 'name':'herp' } ) req = webob.Request.blank('/v1.0/') @@ -56,7 +56,7 @@ class Test(unittest.TestCase): token = result.headers['X-Auth-Token'] self.stubs.Set(nova.api.rackspace, 'APIRouter', - test_helper.FakeRouter) + fakes.FakeRouter) req = webob.Request.blank('/v1.0/fake') req.headers['X-Auth-Token'] = token result = req.get_response(nova.api.API()) @@ -74,10 +74,10 @@ class Test(unittest.TestCase): return { 'token_hash':token_hash, 'created_at':datetime.datetime(1990, 1, 1) } - self.stubs.Set(test_helper.FakeAuthDatabase, 'auth_destroy_token', + self.stubs.Set(fakes.FakeAuthDatabase, 'auth_destroy_token', destroy_token_mock) - self.stubs.Set(test_helper.FakeAuthDatabase, 'auth_get_token', + self.stubs.Set(fakes.FakeAuthDatabase, 'auth_get_token', bad_token) req = webob.Request.blank('/v1.0/') diff --git a/nova/tests/api/rackspace/testfaults.py b/nova/tests/api/rackspace/test_faults.py index b2931bc98..b2931bc98 100644 --- a/nova/tests/api/rackspace/testfaults.py +++ b/nova/tests/api/rackspace/test_faults.py diff --git a/nova/tests/api/rackspace/flavors.py b/nova/tests/api/rackspace/test_flavors.py index d25a2e2be..affdd2406 100644 --- a/nova/tests/api/rackspace/flavors.py +++ b/nova/tests/api/rackspace/test_flavors.py @@ -16,21 +16,23 @@ # under the License. import unittest + import stubout +import webob import nova.api from nova.api.rackspace import flavors -from nova.tests.api.rackspace import test_helper -from nova.tests.api.test_helper import * +from nova.tests.api.rackspace import fakes + 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) + fakes.FakeAuthManager.auth_data = {} + fakes.FakeAuthDatabase.data = {} + fakes.stub_out_networking(self.stubs) + fakes.stub_out_rate_limiting(self.stubs) + fakes.stub_out_auth(self.stubs) def tearDown(self): self.stubs.UnsetAll() diff --git a/nova/tests/api/rackspace/images.py b/nova/tests/api/rackspace/test_images.py index 4c9987e8b..489e35052 100644 --- a/nova/tests/api/rackspace/images.py +++ b/nova/tests/api/rackspace/test_images.py @@ -15,11 +15,12 @@ # License for the specific language governing permissions and limitations # under the License. -import stubout import unittest +import stubout + from nova.api.rackspace import images -from nova.tests.api.test_helper import * + class ImagesTest(unittest.TestCase): def setUp(self): @@ -36,5 +37,3 @@ class ImagesTest(unittest.TestCase): def test_create_image(self): pass - - diff --git a/nova/tests/api/rackspace/servers.py b/nova/tests/api/rackspace/test_servers.py index 69ad2c1d3..9c1860879 100644 --- a/nova/tests/api/rackspace/servers.py +++ b/nova/tests/api/rackspace/test_servers.py @@ -19,6 +19,7 @@ import json import unittest import stubout +import webob from nova import db from nova import flags @@ -27,14 +28,16 @@ from nova.api.rackspace import servers import nova.db.api from nova.db.sqlalchemy.models import Instance import nova.rpc -from nova.tests.api.test_helper import * -from nova.tests.api.rackspace import test_helper +from nova.tests.api.rackspace import fakes + FLAGS = flags.FLAGS + def return_server(context, id): return stub_instance(id) + def return_servers(context, user_id=1): return [stub_instance(i, user_id) for i in xrange(5)] @@ -45,17 +48,18 @@ def stub_instance(id, user_id=1): user_id=user_id ) + class ServersTest(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) - test_helper.stub_out_id_translator(self.stubs) - test_helper.stub_out_key_pair_funcs(self.stubs) - test_helper.stub_out_image_service(self.stubs) + fakes.FakeAuthManager.auth_data = {} + fakes.FakeAuthDatabase.data = {} + fakes.stub_out_networking(self.stubs) + fakes.stub_out_rate_limiting(self.stubs) + fakes.stub_out_auth(self.stubs) + fakes.stub_out_id_translator(self.stubs) + fakes.stub_out_key_pair_funcs(self.stubs) + fakes.stub_out_image_service(self.stubs) self.stubs.Set(nova.db.api, 'instance_get_all', return_servers) self.stubs.Set(nova.db.api, 'instance_get_by_ec2_id', return_server) self.stubs.Set(nova.db.api, 'instance_get_all_by_user', @@ -111,7 +115,7 @@ class ServersTest(unittest.TestCase): self.stubs.Set(nova.network.manager.FlatManager, 'allocate_fixed_ip', fake_method) - test_helper.stub_out_id_translator(self.stubs) + fakes.stub_out_id_translator(self.stubs) body = dict(server=dict( name='server_test', imageId=2, flavorId=2, metadata={}, personality = {} @@ -241,5 +245,6 @@ class ServersTest(unittest.TestCase): 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/sharedipgroups.py b/nova/tests/api/rackspace/test_sharedipgroups.py index 1906b54f5..31ce967d0 100644 --- a/nova/tests/api/rackspace/sharedipgroups.py +++ b/nova/tests/api/rackspace/test_sharedipgroups.py @@ -15,11 +15,12 @@ # License for the specific language governing permissions and limitations # under the License. -import stubout import unittest +import stubout + from nova.api.rackspace import sharedipgroups -from nova.tests.api.test_helper import * + class SharedIpGroupsTest(unittest.TestCase): def setUp(self): @@ -36,6 +37,3 @@ class SharedIpGroupsTest(unittest.TestCase): def test_delete_shared_ip_group(self): pass - - - diff --git a/nova/tests/api/wsgi_test.py b/nova/tests/api/test_wsgi.py index 9425b01d0..9425b01d0 100644 --- a/nova/tests/api/wsgi_test.py +++ b/nova/tests/api/test_wsgi.py diff --git a/tools/pip-requires b/tools/pip-requires index 1e2707be7..6c3940372 100644 --- a/tools/pip-requires +++ b/tools/pip-requires @@ -20,3 +20,4 @@ zope.interface==3.6.1 mox==0.5.0 -f http://pymox.googlecode.com/files/mox-0.5.0.tar.gz greenlet==0.3.1 +nose |
