Merge lp:~jaypipes/nova/cleanup-for-nosetests into lp:~hudson-openstack/nova/trunk

Proposed by Jay Pipes
Status: Merged
Approved by: Eric Day
Approved revision: 317
Merged at revision: 325
Proposed branch: lp:~jaypipes/nova/cleanup-for-nosetests
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 379 lines (+63/-43)
9 files modified
nova/tests/api/__init__.py (+2/-1)
nova/tests/api/rackspace/__init__.py (+2/-2)
nova/tests/api/rackspace/fakes.py (+15/-1)
nova/tests/api/rackspace/test_auth.py (+12/-12)
nova/tests/api/rackspace/test_flavors.py (+9/-7)
nova/tests/api/rackspace/test_images.py (+3/-4)
nova/tests/api/rackspace/test_servers.py (+16/-11)
nova/tests/api/rackspace/test_sharedipgroups.py (+3/-5)
tools/pip-requires (+1/-0)
To merge this branch: bzr merge lp:~jaypipes/nova/cleanup-for-nosetests
Reviewer Review Type Date Requested Status
Eric Day (community) Approve
Michael Gundlach (community) Approve
Nova Core security contacts Pending
Review via email: mp+37298@code.launchpad.net

Description of the change

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

To post a comment you must log in.
Revision history for this message
Michael Gundlach (gundlach) wrote :

Great! Thanks for doing this.

lgtm, unless you think we should version nose in pip-requires.

review: Approve
Revision history for this message
Jay Pipes (jaypipes) wrote :

Nah, not unless we require a specific version, which we don't (yet) :)

Revision history for this message
Eric Day (eday) wrote :

lgtm!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/tests/api/__init__.py'
2--- nova/tests/api/__init__.py 2010-09-22 23:11:04 +0000
3+++ nova/tests/api/__init__.py 2010-10-01 18:12:48 +0000
4@@ -27,7 +27,8 @@
5
6 import nova.exception
7 from nova import api
8-from nova.tests.api.test_helper import *
9+from nova.tests.api.fakes import APIStub
10+
11
12 class Test(unittest.TestCase):
13
14
15=== renamed file 'nova/tests/api/test_helper.py' => 'nova/tests/api/fakes.py'
16=== modified file 'nova/tests/api/rackspace/__init__.py'
17--- nova/tests/api/rackspace/__init__.py 2010-09-29 15:37:26 +0000
18+++ nova/tests/api/rackspace/__init__.py 2010-10-01 18:12:48 +0000
19@@ -19,7 +19,7 @@
20
21 from nova.api.rackspace import limited
22 from nova.api.rackspace import RateLimitingMiddleware
23-from nova.tests.api.test_helper import *
24+from nova.tests.api.fakes import APIStub
25 from webob import Request
26
27
28@@ -82,7 +82,7 @@
29
30 class LimiterTest(unittest.TestCase):
31
32- def testLimiter(self):
33+ def test_limiter(self):
34 items = range(2000)
35 req = Request.blank('/')
36 self.assertEqual(limited(items, req), items[ :1000])
37
38=== renamed file 'nova/tests/api/rackspace/test_helper.py' => 'nova/tests/api/rackspace/fakes.py'
39--- nova/tests/api/rackspace/test_helper.py 2010-09-29 22:24:36 +0000
40+++ nova/tests/api/rackspace/fakes.py 2010-10-01 18:12:48 +0000
41@@ -12,11 +12,14 @@
42 from nova.image import service
43 from nova.wsgi import Router
44
45+
46 FLAGS = flags.FLAGS
47
48+
49 class Context(object):
50 pass
51
52+
53 class FakeRouter(Router):
54 def __init__(self):
55 pass
56@@ -28,12 +31,14 @@
57 res.headers['X-Test-Success'] = 'True'
58 return res
59
60+
61 def fake_auth_init(self):
62 self.db = FakeAuthDatabase()
63 self.context = Context()
64 self.auth = FakeAuthManager()
65 self.host = 'foo'
66
67+
68 @webob.dec.wsgify
69 def fake_wsgi(self, req):
70 req.environ['nova.context'] = dict(user=dict(id=1))
71@@ -41,18 +46,21 @@
72 req.environ['inst_dict'] = json.loads(req.body)
73 return self.application
74
75+
76 def stub_out_key_pair_funcs(stubs):
77 def key_pair(context, user_id):
78 return [dict(name='key', public_key='public_key')]
79 stubs.Set(nova.db.api, 'key_pair_get_all_by_user',
80 key_pair)
81
82+
83 def stub_out_image_service(stubs):
84 def fake_image_show(meh, id):
85 return dict(kernelId=1, ramdiskId=1)
86
87 stubs.Set(nova.image.service.LocalImageService, 'show', fake_image_show)
88
89+
90 def stub_out_id_translator(stubs):
91 class FakeTranslator(object):
92 def __init__(self, id_type, service_name):
93@@ -67,6 +75,7 @@
94 stubs.Set(nova.api.rackspace._id_translator,
95 'RackspaceAPIIdTranslator', FakeTranslator)
96
97+
98 def stub_out_auth(stubs):
99 def fake_auth_init(self, app):
100 self.application = app
101@@ -76,6 +85,7 @@
102 stubs.Set(nova.api.rackspace.AuthMiddleware,
103 '__call__', fake_wsgi)
104
105+
106 def stub_out_rate_limiting(stubs):
107 def fake_rate_init(self, app):
108 super(nova.api.rackspace.RateLimitingMiddleware, self).__init__(app)
109@@ -87,12 +97,14 @@
110 stubs.Set(nova.api.rackspace.RateLimitingMiddleware,
111 '__call__', fake_wsgi)
112
113-def stub_for_testing(stubs):
114+
115+def stub_out_networking(stubs):
116 def get_my_ip():
117 return '127.0.0.1'
118 stubs.Set(nova.utils, 'get_my_ip', get_my_ip)
119 FLAGS.FAKE_subdomain = 'rs'
120
121+
122 class FakeAuthDatabase(object):
123 data = {}
124
125@@ -110,6 +122,7 @@
126 if FakeAuthDatabase.data.has_key(token['token_hash']):
127 del FakeAuthDatabase.data['token_hash']
128
129+
130 class FakeAuthManager(object):
131 auth_data = {}
132
133@@ -125,6 +138,7 @@
134 def get_user_from_access_key(self, key):
135 return FakeAuthManager.auth_data.get(key, None)
136
137+
138 class FakeRateLimiter(object):
139 def __init__(self, application):
140 self.application = application
141
142=== renamed file 'nova/tests/api/rackspace/auth.py' => 'nova/tests/api/rackspace/test_auth.py'
143--- nova/tests/api/rackspace/auth.py 2010-09-29 21:21:28 +0000
144+++ nova/tests/api/rackspace/test_auth.py 2010-10-01 18:12:48 +0000
145@@ -8,24 +8,24 @@
146 import nova.api
147 import nova.api.rackspace.auth
148 from nova import auth
149-from nova.tests.api.rackspace import test_helper
150+from nova.tests.api.rackspace import fakes
151
152 class Test(unittest.TestCase):
153 def setUp(self):
154 self.stubs = stubout.StubOutForTesting()
155 self.stubs.Set(nova.api.rackspace.auth.BasicApiAuthManager,
156- '__init__', test_helper.fake_auth_init)
157- test_helper.FakeAuthManager.auth_data = {}
158- test_helper.FakeAuthDatabase.data = {}
159- test_helper.stub_out_rate_limiting(self.stubs)
160- test_helper.stub_for_testing(self.stubs)
161+ '__init__', fakes.fake_auth_init)
162+ fakes.FakeAuthManager.auth_data = {}
163+ fakes.FakeAuthDatabase.data = {}
164+ fakes.stub_out_rate_limiting(self.stubs)
165+ fakes.stub_out_networking(self.stubs)
166
167 def tearDown(self):
168 self.stubs.UnsetAll()
169- test_helper.fake_data_store = {}
170+ fakes.fake_data_store = {}
171
172 def test_authorize_user(self):
173- f = test_helper.FakeAuthManager()
174+ f = fakes.FakeAuthManager()
175 f.add_user('derp', { 'uid': 1, 'name':'herp' } )
176
177 req = webob.Request.blank('/v1.0/')
178@@ -39,7 +39,7 @@
179 self.assertEqual(result.headers['X-Storage-Url'], "")
180
181 def test_authorize_token(self):
182- f = test_helper.FakeAuthManager()
183+ f = fakes.FakeAuthManager()
184 f.add_user('derp', { 'uid': 1, 'name':'herp' } )
185
186 req = webob.Request.blank('/v1.0/')
187@@ -56,7 +56,7 @@
188
189 token = result.headers['X-Auth-Token']
190 self.stubs.Set(nova.api.rackspace, 'APIRouter',
191- test_helper.FakeRouter)
192+ fakes.FakeRouter)
193 req = webob.Request.blank('/v1.0/fake')
194 req.headers['X-Auth-Token'] = token
195 result = req.get_response(nova.api.API())
196@@ -74,10 +74,10 @@
197 return { 'token_hash':token_hash,
198 'created_at':datetime.datetime(1990, 1, 1) }
199
200- self.stubs.Set(test_helper.FakeAuthDatabase, 'auth_destroy_token',
201+ self.stubs.Set(fakes.FakeAuthDatabase, 'auth_destroy_token',
202 destroy_token_mock)
203
204- self.stubs.Set(test_helper.FakeAuthDatabase, 'auth_get_token',
205+ self.stubs.Set(fakes.FakeAuthDatabase, 'auth_get_token',
206 bad_token)
207
208 req = webob.Request.blank('/v1.0/')
209
210=== renamed file 'nova/tests/api/rackspace/testfaults.py' => 'nova/tests/api/rackspace/test_faults.py'
211=== renamed file 'nova/tests/api/rackspace/flavors.py' => 'nova/tests/api/rackspace/test_flavors.py'
212--- nova/tests/api/rackspace/flavors.py 2010-09-29 22:52:15 +0000
213+++ nova/tests/api/rackspace/test_flavors.py 2010-10-01 18:12:48 +0000
214@@ -16,21 +16,23 @@
215 # under the License.
216
217 import unittest
218+
219 import stubout
220+import webob
221
222 import nova.api
223 from nova.api.rackspace import flavors
224-from nova.tests.api.rackspace import test_helper
225-from nova.tests.api.test_helper import *
226+from nova.tests.api.rackspace import fakes
227+
228
229 class FlavorsTest(unittest.TestCase):
230 def setUp(self):
231 self.stubs = stubout.StubOutForTesting()
232- test_helper.FakeAuthManager.auth_data = {}
233- test_helper.FakeAuthDatabase.data = {}
234- test_helper.stub_for_testing(self.stubs)
235- test_helper.stub_out_rate_limiting(self.stubs)
236- test_helper.stub_out_auth(self.stubs)
237+ fakes.FakeAuthManager.auth_data = {}
238+ fakes.FakeAuthDatabase.data = {}
239+ fakes.stub_out_networking(self.stubs)
240+ fakes.stub_out_rate_limiting(self.stubs)
241+ fakes.stub_out_auth(self.stubs)
242
243 def tearDown(self):
244 self.stubs.UnsetAll()
245
246=== renamed file 'nova/tests/api/rackspace/images.py' => 'nova/tests/api/rackspace/test_images.py'
247--- nova/tests/api/rackspace/images.py 2010-09-29 19:52:02 +0000
248+++ nova/tests/api/rackspace/test_images.py 2010-10-01 18:12:48 +0000
249@@ -15,11 +15,12 @@
250 # License for the specific language governing permissions and limitations
251 # under the License.
252
253+import unittest
254+
255 import stubout
256-import unittest
257
258 from nova.api.rackspace import images
259-from nova.tests.api.test_helper import *
260+
261
262 class ImagesTest(unittest.TestCase):
263 def setUp(self):
264@@ -36,5 +37,3 @@
265
266 def test_create_image(self):
267 pass
268-
269-
270
271=== renamed file 'nova/tests/api/rackspace/servers.py' => 'nova/tests/api/rackspace/test_servers.py'
272--- nova/tests/api/rackspace/servers.py 2010-09-29 22:24:36 +0000
273+++ nova/tests/api/rackspace/test_servers.py 2010-10-01 18:12:48 +0000
274@@ -19,6 +19,7 @@
275 import unittest
276
277 import stubout
278+import webob
279
280 from nova import db
281 from nova import flags
282@@ -27,14 +28,16 @@
283 import nova.db.api
284 from nova.db.sqlalchemy.models import Instance
285 import nova.rpc
286-from nova.tests.api.test_helper import *
287-from nova.tests.api.rackspace import test_helper
288+from nova.tests.api.rackspace import fakes
289+
290
291 FLAGS = flags.FLAGS
292
293+
294 def return_server(context, id):
295 return stub_instance(id)
296
297+
298 def return_servers(context, user_id=1):
299 return [stub_instance(i, user_id) for i in xrange(5)]
300
301@@ -45,17 +48,18 @@
302 user_id=user_id
303 )
304
305+
306 class ServersTest(unittest.TestCase):
307 def setUp(self):
308 self.stubs = stubout.StubOutForTesting()
309- test_helper.FakeAuthManager.auth_data = {}
310- test_helper.FakeAuthDatabase.data = {}
311- test_helper.stub_for_testing(self.stubs)
312- test_helper.stub_out_rate_limiting(self.stubs)
313- test_helper.stub_out_auth(self.stubs)
314- test_helper.stub_out_id_translator(self.stubs)
315- test_helper.stub_out_key_pair_funcs(self.stubs)
316- test_helper.stub_out_image_service(self.stubs)
317+ fakes.FakeAuthManager.auth_data = {}
318+ fakes.FakeAuthDatabase.data = {}
319+ fakes.stub_out_networking(self.stubs)
320+ fakes.stub_out_rate_limiting(self.stubs)
321+ fakes.stub_out_auth(self.stubs)
322+ fakes.stub_out_id_translator(self.stubs)
323+ fakes.stub_out_key_pair_funcs(self.stubs)
324+ fakes.stub_out_image_service(self.stubs)
325 self.stubs.Set(nova.db.api, 'instance_get_all', return_servers)
326 self.stubs.Set(nova.db.api, 'instance_get_by_ec2_id', return_server)
327 self.stubs.Set(nova.db.api, 'instance_get_all_by_user',
328@@ -111,7 +115,7 @@
329 self.stubs.Set(nova.network.manager.FlatManager, 'allocate_fixed_ip',
330 fake_method)
331
332- test_helper.stub_out_id_translator(self.stubs)
333+ fakes.stub_out_id_translator(self.stubs)
334 body = dict(server=dict(
335 name='server_test', imageId=2, flavorId=2, metadata={},
336 personality = {}
337@@ -241,5 +245,6 @@
338 self.assertEqual(res.status, '202 Accepted')
339 self.assertEqual(self.server_delete_called, True)
340
341+
342 if __name__ == "__main__":
343 unittest.main()
344
345=== renamed file 'nova/tests/api/rackspace/sharedipgroups.py' => 'nova/tests/api/rackspace/test_sharedipgroups.py'
346--- nova/tests/api/rackspace/sharedipgroups.py 2010-09-29 19:52:02 +0000
347+++ nova/tests/api/rackspace/test_sharedipgroups.py 2010-10-01 18:12:48 +0000
348@@ -15,11 +15,12 @@
349 # License for the specific language governing permissions and limitations
350 # under the License.
351
352+import unittest
353+
354 import stubout
355-import unittest
356
357 from nova.api.rackspace import sharedipgroups
358-from nova.tests.api.test_helper import *
359+
360
361 class SharedIpGroupsTest(unittest.TestCase):
362 def setUp(self):
363@@ -36,6 +37,3 @@
364
365 def test_delete_shared_ip_group(self):
366 pass
367-
368-
369-
370
371=== renamed file 'nova/tests/api/wsgi_test.py' => 'nova/tests/api/test_wsgi.py'
372=== modified file 'tools/pip-requires'
373--- tools/pip-requires 2010-09-20 22:30:35 +0000
374+++ tools/pip-requires 2010-10-01 18:12:48 +0000
375@@ -20,3 +20,4 @@
376 mox==0.5.0
377 -f http://pymox.googlecode.com/files/mox-0.5.0.tar.gz
378 greenlet==0.3.1
379+nose