Merge lp:~devcamcar/django-nova/improve_unittests into lp:django-nova
- improve_unittests
- Merge into trunk
Proposed by
Devin Carlen
Status: | Merged |
---|---|
Approved by: | Devin Carlen |
Approved revision: | 21 |
Merged at revision: | 16 |
Proposed branch: | lp:~devcamcar/django-nova/improve_unittests |
Merge into: | lp:django-nova |
Diff against target: |
615 lines (+427/-29) 11 files modified
src/django_nova/tests/urls.py (+5/-1) src/django_nova/tests/view_tests/__init__.py (+6/-2) src/django_nova/tests/view_tests/base.py (+54/-15) src/django_nova/tests/view_tests/credential_tests.py (+70/-0) src/django_nova/tests/view_tests/image_tests.py (+22/-0) src/django_nova/tests/view_tests/instance_tests.py (+22/-0) src/django_nova/tests/view_tests/keypair_tests.py (+25/-3) src/django_nova/tests/view_tests/region_tests.py (+43/-0) src/django_nova/tests/view_tests/volume_tests.py (+170/-0) src/django_nova/views/credentials.py (+4/-2) src/django_nova/views/volumes.py (+6/-6) |
To merge this branch: | bzr merge lp:~devcamcar/django-nova/improve_unittests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Devin Carlen | Approve | ||
Review via email: mp+49529@code.launchpad.net |
Commit message
Description of the change
Improved unit tests for views
To post a comment you must log in.
Revision history for this message
Jesse Andrews (anotherjesse) wrote : | # |
u can do merge?
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/django_nova/tests/urls.py' | |||
2 | --- src/django_nova/tests/urls.py 2011-01-18 02:09:01 +0000 | |||
3 | +++ src/django_nova/tests/urls.py 2011-02-13 02:22:10 +0000 | |||
4 | @@ -29,4 +29,8 @@ | |||
5 | 29 | url(r'^region/', include('django_nova.urls.region')), | 29 | url(r'^region/', include('django_nova.urls.region')), |
6 | 30 | url(r'^admin/projects/', include('django_nova.urls.admin_project')), | 30 | url(r'^admin/projects/', include('django_nova.urls.admin_project')), |
7 | 31 | url(r'^admin/roles/', include('django_nova.urls.admin_roles')), | 31 | url(r'^admin/roles/', include('django_nova.urls.admin_roles')), |
8 | 32 | ) | ||
9 | 33 | \ No newline at end of file | 32 | \ No newline at end of file |
10 | 33 | url(r'^credentials/download/(?P<auth_token>\w+)/$', | ||
11 | 34 | 'django_nova.views.credentials.authorize_credentials', | ||
12 | 35 | name='nova_credentials_authorize'), | ||
13 | 36 | ) | ||
14 | 37 | |||
15 | 34 | 38 | ||
16 | === modified file 'src/django_nova/tests/view_tests/__init__.py' | |||
17 | --- src/django_nova/tests/view_tests/__init__.py 2011-01-21 22:38:42 +0000 | |||
18 | +++ src/django_nova/tests/view_tests/__init__.py 2011-02-13 02:22:10 +0000 | |||
19 | @@ -1,3 +1,7 @@ | |||
20 | 1 | from credential_tests import * | ||
21 | 2 | from image_tests import * | ||
22 | 3 | from instance_tests import * | ||
23 | 1 | from keypair_tests import * | 4 | from keypair_tests import * |
24 | 2 | from image_tests import * | ||
25 | 3 | from instance_tests import * | ||
26 | 4 | \ No newline at end of file | 5 | \ No newline at end of file |
27 | 6 | from region_tests import * | ||
28 | 7 | from volume_tests import * | ||
29 | 8 | |||
30 | 5 | 9 | ||
31 | === modified file 'src/django_nova/tests/view_tests/base.py' | |||
32 | --- src/django_nova/tests/view_tests/base.py 2011-01-22 22:27:53 +0000 | |||
33 | +++ src/django_nova/tests/view_tests/base.py 2011-02-13 02:22:10 +0000 | |||
34 | @@ -1,3 +1,25 @@ | |||
35 | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
36 | 2 | |||
37 | 3 | # Copyright 2010 United States Government as represented by the | ||
38 | 4 | # Administrator of the National Aeronautics and Space Administration. | ||
39 | 5 | # All Rights Reserved. | ||
40 | 6 | # | ||
41 | 7 | # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
42 | 8 | # not use this file except in compliance with the License. You may obtain | ||
43 | 9 | # a copy of the License at | ||
44 | 10 | # | ||
45 | 11 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
46 | 12 | # | ||
47 | 13 | # Unless required by applicable law or agreed to in writing, software | ||
48 | 14 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
49 | 15 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
50 | 16 | # License for the specific language governing permissions and limitations | ||
51 | 17 | # under the License. | ||
52 | 18 | |||
53 | 19 | """ | ||
54 | 20 | Base classes for view based unit tests. | ||
55 | 21 | """ | ||
56 | 22 | |||
57 | 1 | import mox | 23 | import mox |
58 | 2 | 24 | ||
59 | 3 | from django import test | 25 | from django import test |
60 | @@ -13,19 +35,36 @@ | |||
61 | 13 | TEST_REGION = 'test' | 35 | TEST_REGION = 'test' |
62 | 14 | 36 | ||
63 | 15 | 37 | ||
65 | 16 | class BaseProjectViewTests(test.TestCase): | 38 | class BaseViewTests(test.TestCase): |
66 | 17 | def setUp(self): | 39 | def setUp(self): |
67 | 18 | project = adminclient.ProjectInfo() | ||
68 | 19 | project.projectname = TEST_PROJECT | ||
69 | 20 | project.projectManagerId = TEST_USER | ||
70 | 21 | |||
71 | 22 | self.mox = mox.Mox() | 40 | self.mox = mox.Mox() |
73 | 23 | self.user = auth_models.User.objects.create_user(TEST_USER, | 41 | |
74 | 42 | def tearDown(self): | ||
75 | 43 | self.mox.UnsetStubs() | ||
76 | 44 | |||
77 | 45 | def assertRedirectsNoFollow(self, response, expected_url): | ||
78 | 46 | self.assertEqual(response._headers['location'], | ||
79 | 47 | ('Location', settings.TESTSERVER + expected_url)) | ||
80 | 48 | self.assertEqual(response.status_code, 302) | ||
81 | 49 | |||
82 | 50 | def authenticateTestUser(self): | ||
83 | 51 | user = auth_models.User.objects.create_user(TEST_USER, | ||
84 | 24 | 'test@test.com', | 52 | 'test@test.com', |
85 | 25 | password='test') | 53 | password='test') |
86 | 26 | login = self.client.login(username=TEST_USER, password='test') | 54 | login = self.client.login(username=TEST_USER, password='test') |
87 | 27 | self.failUnless(login, 'Unable to login') | 55 | self.failUnless(login, 'Unable to login') |
89 | 28 | 56 | return user | |
90 | 57 | |||
91 | 58 | |||
92 | 59 | class BaseProjectViewTests(BaseViewTests): | ||
93 | 60 | def setUp(self): | ||
94 | 61 | super(BaseProjectViewTests, self).setUp() | ||
95 | 62 | |||
96 | 63 | project = adminclient.ProjectInfo() | ||
97 | 64 | project.projectname = TEST_PROJECT | ||
98 | 65 | project.projectManagerId = TEST_USER | ||
99 | 66 | |||
100 | 67 | self.user = self.authenticateTestUser() | ||
101 | 29 | self.region = adminclient.RegionInfo(name=TEST_REGION, | 68 | self.region = adminclient.RegionInfo(name=TEST_REGION, |
102 | 30 | endpoint='http://test:8773/') | 69 | endpoint='http://test:8773/') |
103 | 31 | self.project = manager.ProjectManager(self.user.username, | 70 | self.project = manager.ProjectManager(self.user.username, |
104 | @@ -35,17 +74,17 @@ | |||
105 | 35 | shortcuts.get_project_or_404(mox.IgnoreArg(), | 74 | shortcuts.get_project_or_404(mox.IgnoreArg(), |
106 | 36 | 'test').AndReturn(self.project) | 75 | 'test').AndReturn(self.project) |
107 | 37 | 76 | ||
108 | 38 | def tearDown(self): | ||
109 | 39 | self.mox.UnsetStubs() | ||
110 | 40 | |||
111 | 41 | def assertRedirectsNoFollow(self, response, expected_url): | ||
112 | 42 | self.assertEqual(response._headers['location'], | ||
113 | 43 | ('Location', settings.TESTSERVER + expected_url)) | ||
114 | 44 | self.assertEqual(response.status_code, 302) | ||
115 | 45 | |||
116 | 46 | def create_key_pair_choices(self, key_names): | 77 | def create_key_pair_choices(self, key_names): |
117 | 47 | return [(k, k) for k in key_names] | 78 | return [(k, k) for k in key_names] |
118 | 48 | 79 | ||
119 | 49 | def create_instance_type_choices(self): | 80 | def create_instance_type_choices(self): |
120 | 50 | return [('m1.medium', 'm1.medium'), | 81 | return [('m1.medium', 'm1.medium'), |
121 | 51 | ('m1.large', 'm1.large')] | 82 | ('m1.large', 'm1.large')] |
122 | 83 | |||
123 | 84 | def create_instance_choices(self, instance_ids): | ||
124 | 85 | return [(id, id) for id in instance_ids] | ||
125 | 86 | |||
126 | 87 | def create_available_volume_choices(self, volumes): | ||
127 | 88 | return [(v.id, '%s %s - %dGB' % (v.id, v.displayName, v.size)) \ | ||
128 | 89 | for v in volumes] | ||
129 | 90 | |||
130 | 52 | 91 | ||
131 | === added file 'src/django_nova/tests/view_tests/credential_tests.py' | |||
132 | --- src/django_nova/tests/view_tests/credential_tests.py 1970-01-01 00:00:00 +0000 | |||
133 | +++ src/django_nova/tests/view_tests/credential_tests.py 2011-02-13 02:22:10 +0000 | |||
134 | @@ -0,0 +1,70 @@ | |||
135 | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
136 | 2 | |||
137 | 3 | # Copyright 2010 United States Government as represented by the | ||
138 | 4 | # Administrator of the National Aeronautics and Space Administration. | ||
139 | 5 | # All Rights Reserved. | ||
140 | 6 | # | ||
141 | 7 | # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
142 | 8 | # not use this file except in compliance with the License. You may obtain | ||
143 | 9 | # a copy of the License at | ||
144 | 10 | # | ||
145 | 11 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
146 | 12 | # | ||
147 | 13 | # Unless required by applicable law or agreed to in writing, software | ||
148 | 14 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
149 | 15 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
150 | 16 | # License for the specific language governing permissions and limitations | ||
151 | 17 | # under the License. | ||
152 | 18 | |||
153 | 19 | """ | ||
154 | 20 | Unit tests for credential views. | ||
155 | 21 | """ | ||
156 | 22 | |||
157 | 23 | import mox | ||
158 | 24 | from django.conf import settings | ||
159 | 25 | from django.core.urlresolvers import reverse | ||
160 | 26 | from django_nova import models | ||
161 | 27 | from django_nova.tests.view_tests.base import BaseViewTests | ||
162 | 28 | |||
163 | 29 | |||
164 | 30 | class CredentialViewTests(BaseViewTests): | ||
165 | 31 | def test_download_expired_credentials(self): | ||
166 | 32 | auth_token = 'expired' | ||
167 | 33 | self.mox.StubOutWithMock(models.CredentialsAuthorization, | ||
168 | 34 | 'get_by_token') | ||
169 | 35 | models.CredentialsAuthorization.get_by_token(auth_token) \ | ||
170 | 36 | .AndReturn(None) | ||
171 | 37 | self.mox.ReplayAll() | ||
172 | 38 | |||
173 | 39 | res = self.client.get(reverse('nova_credentials_authorize', | ||
174 | 40 | args=[auth_token])) | ||
175 | 41 | self.assertTemplateUsed(res, 'django_nova/credentials/expired.html') | ||
176 | 42 | |||
177 | 43 | self.mox.VerifyAll() | ||
178 | 44 | |||
179 | 45 | def test_download_good_credentials(self): | ||
180 | 46 | auth_token = 'good' | ||
181 | 47 | |||
182 | 48 | creds = models.CredentialsAuthorization() | ||
183 | 49 | creds.username = 'test' | ||
184 | 50 | creds.project = 'test' | ||
185 | 51 | creds.auth_token = auth_token | ||
186 | 52 | |||
187 | 53 | self.mox.StubOutWithMock(models.CredentialsAuthorization, | ||
188 | 54 | 'get_by_token') | ||
189 | 55 | self.mox.StubOutWithMock(creds, 'get_zip') | ||
190 | 56 | models.CredentialsAuthorization.get_by_token(auth_token) \ | ||
191 | 57 | .AndReturn(creds) | ||
192 | 58 | creds.get_zip().AndReturn('zip') | ||
193 | 59 | |||
194 | 60 | self.mox.ReplayAll() | ||
195 | 61 | |||
196 | 62 | res = self.client.get(reverse('nova_credentials_authorize', | ||
197 | 63 | args=[auth_token])) | ||
198 | 64 | self.assertEqual(res.status_code, 200) | ||
199 | 65 | self.assertEqual(res['Content-Disposition'], | ||
200 | 66 | 'attachment; filename=%s-test-test-x509.zip' % | ||
201 | 67 | settings.SITE_NAME) | ||
202 | 68 | self.assertContains(res, 'zip') | ||
203 | 69 | |||
204 | 70 | self.mox.VerifyAll() | ||
205 | 0 | 71 | ||
206 | === modified file 'src/django_nova/tests/view_tests/image_tests.py' | |||
207 | --- src/django_nova/tests/view_tests/image_tests.py 2011-01-25 23:51:20 +0000 | |||
208 | +++ src/django_nova/tests/view_tests/image_tests.py 2011-02-13 02:22:10 +0000 | |||
209 | @@ -1,3 +1,25 @@ | |||
210 | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
211 | 2 | |||
212 | 3 | # Copyright 2010 United States Government as represented by the | ||
213 | 4 | # Administrator of the National Aeronautics and Space Administration. | ||
214 | 5 | # All Rights Reserved. | ||
215 | 6 | # | ||
216 | 7 | # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
217 | 8 | # not use this file except in compliance with the License. You may obtain | ||
218 | 9 | # a copy of the License at | ||
219 | 10 | # | ||
220 | 11 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
221 | 12 | # | ||
222 | 13 | # Unless required by applicable law or agreed to in writing, software | ||
223 | 14 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
224 | 15 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
225 | 16 | # License for the specific language governing permissions and limitations | ||
226 | 17 | # under the License. | ||
227 | 18 | |||
228 | 19 | """ | ||
229 | 20 | Unit tests for image views. | ||
230 | 21 | """ | ||
231 | 22 | |||
232 | 1 | import boto.ec2.image | 23 | import boto.ec2.image |
233 | 2 | import boto.ec2.instance | 24 | import boto.ec2.instance |
234 | 3 | import mox | 25 | import mox |
235 | 4 | 26 | ||
236 | === modified file 'src/django_nova/tests/view_tests/instance_tests.py' | |||
237 | --- src/django_nova/tests/view_tests/instance_tests.py 2011-01-22 01:04:51 +0000 | |||
238 | +++ src/django_nova/tests/view_tests/instance_tests.py 2011-02-13 02:22:10 +0000 | |||
239 | @@ -1,3 +1,25 @@ | |||
240 | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
241 | 2 | |||
242 | 3 | # Copyright 2010 United States Government as represented by the | ||
243 | 4 | # Administrator of the National Aeronautics and Space Administration. | ||
244 | 5 | # All Rights Reserved. | ||
245 | 6 | # | ||
246 | 7 | # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
247 | 8 | # not use this file except in compliance with the License. You may obtain | ||
248 | 9 | # a copy of the License at | ||
249 | 10 | # | ||
250 | 11 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
251 | 12 | # | ||
252 | 13 | # Unless required by applicable law or agreed to in writing, software | ||
253 | 14 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
254 | 15 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
255 | 16 | # License for the specific language governing permissions and limitations | ||
256 | 17 | # under the License. | ||
257 | 18 | |||
258 | 19 | """ | ||
259 | 20 | Unit tests for instance views. | ||
260 | 21 | """ | ||
261 | 22 | |||
262 | 1 | import boto.ec2.instance | 23 | import boto.ec2.instance |
263 | 2 | import mox | 24 | import mox |
264 | 3 | 25 | ||
265 | 4 | 26 | ||
266 | === modified file 'src/django_nova/tests/view_tests/keypair_tests.py' | |||
267 | --- src/django_nova/tests/view_tests/keypair_tests.py 2011-01-22 01:04:51 +0000 | |||
268 | +++ src/django_nova/tests/view_tests/keypair_tests.py 2011-02-13 02:22:10 +0000 | |||
269 | @@ -1,8 +1,31 @@ | |||
270 | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
271 | 2 | |||
272 | 3 | # Copyright 2010 United States Government as represented by the | ||
273 | 4 | # Administrator of the National Aeronautics and Space Administration. | ||
274 | 5 | # All Rights Reserved. | ||
275 | 6 | # | ||
276 | 7 | # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
277 | 8 | # not use this file except in compliance with the License. You may obtain | ||
278 | 9 | # a copy of the License at | ||
279 | 10 | # | ||
280 | 11 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
281 | 12 | # | ||
282 | 13 | # Unless required by applicable law or agreed to in writing, software | ||
283 | 14 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
284 | 15 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
285 | 16 | # License for the specific language governing permissions and limitations | ||
286 | 17 | # under the License. | ||
287 | 18 | |||
288 | 19 | """ | ||
289 | 20 | Unit tests for key pair views. | ||
290 | 21 | """ | ||
291 | 22 | |||
292 | 1 | import boto.ec2.keypair | 23 | import boto.ec2.keypair |
293 | 2 | import mox | 24 | import mox |
294 | 3 | 25 | ||
295 | 4 | from django.core.urlresolvers import reverse | 26 | from django.core.urlresolvers import reverse |
297 | 5 | from django_nova.tests.view_tests.base import BaseProjectViewTests, TEST_PROJECT | 27 | from django_nova.tests.view_tests.base import (BaseProjectViewTests, |
298 | 28 | TEST_PROJECT) | ||
299 | 6 | 29 | ||
300 | 7 | 30 | ||
301 | 8 | TEST_KEY = 'test_key' | 31 | TEST_KEY = 'test_key' |
302 | @@ -36,8 +59,7 @@ | |||
303 | 36 | 59 | ||
304 | 37 | url = reverse('nova_keypairs_add', args=[TEST_PROJECT]) | 60 | url = reverse('nova_keypairs_add', args=[TEST_PROJECT]) |
305 | 38 | data = {'js': '0', 'name': key.name} | 61 | data = {'js': '0', 'name': key.name} |
308 | 39 | res = self.client.post(url, | 62 | res = self.client.post(url, data) |
307 | 40 | data) | ||
309 | 41 | self.assertEqual(res.status_code, 200) | 63 | self.assertEqual(res.status_code, 200) |
310 | 42 | self.assertEqual(res['Content-Type'], 'application/binary') | 64 | self.assertEqual(res['Content-Type'], 'application/binary') |
311 | 43 | 65 | ||
312 | 44 | 66 | ||
313 | === added file 'src/django_nova/tests/view_tests/region_tests.py' | |||
314 | --- src/django_nova/tests/view_tests/region_tests.py 1970-01-01 00:00:00 +0000 | |||
315 | +++ src/django_nova/tests/view_tests/region_tests.py 2011-02-13 02:22:10 +0000 | |||
316 | @@ -0,0 +1,43 @@ | |||
317 | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
318 | 2 | |||
319 | 3 | # Copyright 2010 United States Government as represented by the | ||
320 | 4 | # Administrator of the National Aeronautics and Space Administration. | ||
321 | 5 | # All Rights Reserved. | ||
322 | 6 | # | ||
323 | 7 | # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
324 | 8 | # not use this file except in compliance with the License. You may obtain | ||
325 | 9 | # a copy of the License at | ||
326 | 10 | # | ||
327 | 11 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
328 | 12 | # | ||
329 | 13 | # Unless required by applicable law or agreed to in writing, software | ||
330 | 14 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
331 | 15 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
332 | 16 | # License for the specific language governing permissions and limitations | ||
333 | 17 | # under the License. | ||
334 | 18 | |||
335 | 19 | """ | ||
336 | 20 | Unit tests for region views. | ||
337 | 21 | """ | ||
338 | 22 | |||
339 | 23 | from django.core.urlresolvers import reverse | ||
340 | 24 | from django_nova.tests.view_tests.base import BaseViewTests | ||
341 | 25 | from django_nova import shortcuts | ||
342 | 26 | |||
343 | 27 | |||
344 | 28 | TEST_REGION = 'one' | ||
345 | 29 | |||
346 | 30 | |||
347 | 31 | class RegionViewTests(BaseViewTests): | ||
348 | 32 | def test_change(self): | ||
349 | 33 | self.authenticateTestUser() | ||
350 | 34 | session = self.client.session | ||
351 | 35 | session['region'] = 'two' | ||
352 | 36 | session.save() | ||
353 | 37 | |||
354 | 38 | data = {'redirect_url': '/', | ||
355 | 39 | 'region': TEST_REGION} | ||
356 | 40 | res = self.client.post(reverse('region_change'), data) | ||
357 | 41 | self.assertEqual(self.client.session['region'], TEST_REGION) | ||
358 | 42 | self.assertRedirectsNoFollow(res, '/') | ||
359 | 43 | |||
360 | 0 | 44 | ||
361 | === added file 'src/django_nova/tests/view_tests/volume_tests.py' | |||
362 | --- src/django_nova/tests/view_tests/volume_tests.py 1970-01-01 00:00:00 +0000 | |||
363 | +++ src/django_nova/tests/view_tests/volume_tests.py 2011-02-13 02:22:10 +0000 | |||
364 | @@ -0,0 +1,170 @@ | |||
365 | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
366 | 2 | |||
367 | 3 | # Copyright 2010 United States Government as represented by the | ||
368 | 4 | # Administrator of the National Aeronautics and Space Administration. | ||
369 | 5 | # All Rights Reserved. | ||
370 | 6 | # | ||
371 | 7 | # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
372 | 8 | # not use this file except in compliance with the License. You may obtain | ||
373 | 9 | # a copy of the License at | ||
374 | 10 | # | ||
375 | 11 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
376 | 12 | # | ||
377 | 13 | # Unless required by applicable law or agreed to in writing, software | ||
378 | 14 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
379 | 15 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
380 | 16 | # License for the specific language governing permissions and limitations | ||
381 | 17 | # under the License. | ||
382 | 18 | |||
383 | 19 | """ | ||
384 | 20 | Unit tests for volume views. | ||
385 | 21 | """ | ||
386 | 22 | |||
387 | 23 | import boto.ec2.volume | ||
388 | 24 | import mox | ||
389 | 25 | |||
390 | 26 | from django.core.urlresolvers import reverse | ||
391 | 27 | from django_nova import forms | ||
392 | 28 | from django_nova.tests.view_tests.base import (BaseProjectViewTests, | ||
393 | 29 | TEST_PROJECT) | ||
394 | 30 | |||
395 | 31 | |||
396 | 32 | TEST_VOLUME = 'vol-0000001' | ||
397 | 33 | |||
398 | 34 | |||
399 | 35 | class VolumeTests(BaseProjectViewTests): | ||
400 | 36 | def test_index(self): | ||
401 | 37 | instance_id = 'i-abcdefgh' | ||
402 | 38 | |||
403 | 39 | volume = boto.ec2.volume.Volume() | ||
404 | 40 | volume.id = TEST_VOLUME | ||
405 | 41 | volume.displayName = TEST_VOLUME | ||
406 | 42 | volume.size = 1 | ||
407 | 43 | |||
408 | 44 | self.mox.StubOutWithMock(self.project, 'get_volumes') | ||
409 | 45 | self.mox.StubOutWithMock(forms, 'get_available_volume_choices') | ||
410 | 46 | self.mox.StubOutWithMock(forms, 'get_instance_choices') | ||
411 | 47 | self.project.get_volumes().AndReturn([]) | ||
412 | 48 | forms.get_available_volume_choices(mox.IgnoreArg()).AndReturn( | ||
413 | 49 | self.create_available_volume_choices([volume])) | ||
414 | 50 | forms.get_instance_choices(mox.IgnoreArg()).AndReturn( | ||
415 | 51 | self.create_instance_choices([instance_id])) | ||
416 | 52 | |||
417 | 53 | self.mox.ReplayAll() | ||
418 | 54 | |||
419 | 55 | response = self.client.get(reverse('nova_volumes', | ||
420 | 56 | args=[TEST_PROJECT])) | ||
421 | 57 | self.assertEqual(response.status_code, 200) | ||
422 | 58 | self.assertTemplateUsed(response, 'django_nova/volumes/index.html') | ||
423 | 59 | self.assertEqual(len(response.context['volumes']), 0) | ||
424 | 60 | |||
425 | 61 | self.mox.VerifyAll() | ||
426 | 62 | |||
427 | 63 | def test_add_get(self): | ||
428 | 64 | self.mox.ReplayAll() | ||
429 | 65 | |||
430 | 66 | res = self.client.get(reverse('nova_volumes_add', args=[TEST_PROJECT])) | ||
431 | 67 | self.assertRedirectsNoFollow(res, reverse('nova_volumes', | ||
432 | 68 | args=[TEST_PROJECT])) | ||
433 | 69 | self.mox.VerifyAll() | ||
434 | 70 | |||
435 | 71 | def test_add_post(self): | ||
436 | 72 | vol = boto.ec2.volume.Volume() | ||
437 | 73 | vol.name = TEST_VOLUME | ||
438 | 74 | vol.displayName = TEST_VOLUME | ||
439 | 75 | vol.size = 1 | ||
440 | 76 | |||
441 | 77 | self.mox.StubOutWithMock(self.project, 'create_volume') | ||
442 | 78 | self.project.create_volume(vol.size, vol.name, vol.name).AndReturn(vol) | ||
443 | 79 | |||
444 | 80 | self.mox.ReplayAll() | ||
445 | 81 | |||
446 | 82 | url = reverse('nova_volumes_add', args=[TEST_PROJECT]) | ||
447 | 83 | data = {'size': '1', | ||
448 | 84 | 'nickname': TEST_VOLUME, | ||
449 | 85 | 'description': TEST_VOLUME} | ||
450 | 86 | res = self.client.post(url, data) | ||
451 | 87 | self.assertRedirectsNoFollow(res, reverse('nova_volumes', | ||
452 | 88 | args=[TEST_PROJECT])) | ||
453 | 89 | self.mox.VerifyAll() | ||
454 | 90 | |||
455 | 91 | def test_delete_get(self): | ||
456 | 92 | self.mox.ReplayAll() | ||
457 | 93 | |||
458 | 94 | res = self.client.get(reverse('nova_volumes_delete', | ||
459 | 95 | args=[TEST_PROJECT, TEST_VOLUME])) | ||
460 | 96 | self.assertRedirectsNoFollow(res, reverse('nova_volumes', | ||
461 | 97 | args=[TEST_PROJECT])) | ||
462 | 98 | self.mox.VerifyAll() | ||
463 | 99 | |||
464 | 100 | def test_delete_post(self): | ||
465 | 101 | self.mox.StubOutWithMock(self.project, 'delete_volume') | ||
466 | 102 | self.project.delete_volume(TEST_VOLUME).AndReturn(True) | ||
467 | 103 | |||
468 | 104 | self.mox.ReplayAll() | ||
469 | 105 | |||
470 | 106 | res = self.client.post(reverse('nova_volumes_delete', | ||
471 | 107 | args=[TEST_PROJECT, TEST_VOLUME])) | ||
472 | 108 | self.assertRedirectsNoFollow(res, reverse('nova_volumes', | ||
473 | 109 | args=[TEST_PROJECT])) | ||
474 | 110 | self.mox.VerifyAll() | ||
475 | 111 | |||
476 | 112 | def test_attach_get(self): | ||
477 | 113 | self.mox.ReplayAll() | ||
478 | 114 | |||
479 | 115 | res = self.client.get(reverse('nova_volumes_attach', | ||
480 | 116 | args=[TEST_PROJECT])) | ||
481 | 117 | self.assertRedirectsNoFollow(res, reverse('nova_volumes', | ||
482 | 118 | args=[TEST_PROJECT])) | ||
483 | 119 | self.mox.VerifyAll() | ||
484 | 120 | |||
485 | 121 | def test_attach_post(self): | ||
486 | 122 | volume = boto.ec2.volume.Volume() | ||
487 | 123 | volume.id = TEST_VOLUME | ||
488 | 124 | volume.displayName = TEST_VOLUME | ||
489 | 125 | volume.size = 1 | ||
490 | 126 | |||
491 | 127 | instance_id = 'i-abcdefgh' | ||
492 | 128 | device = '/dev/vdb' | ||
493 | 129 | |||
494 | 130 | self.mox.StubOutWithMock(self.project, 'attach_volume') | ||
495 | 131 | self.mox.StubOutWithMock(forms, 'get_available_volume_choices') | ||
496 | 132 | self.mox.StubOutWithMock(forms, 'get_instance_choices') | ||
497 | 133 | self.project.attach_volume(TEST_VOLUME, instance_id, device) \ | ||
498 | 134 | .AndReturn(True) | ||
499 | 135 | forms.get_available_volume_choices(mox.IgnoreArg()).AndReturn( | ||
500 | 136 | self.create_available_volume_choices([volume])) | ||
501 | 137 | forms.get_instance_choices(mox.IgnoreArg()).AndReturn( | ||
502 | 138 | self.create_instance_choices([instance_id])) | ||
503 | 139 | |||
504 | 140 | self.mox.ReplayAll() | ||
505 | 141 | |||
506 | 142 | url = reverse('nova_volumes_attach', args=[TEST_PROJECT]) | ||
507 | 143 | data = {'volume': TEST_VOLUME, | ||
508 | 144 | 'instance': instance_id, | ||
509 | 145 | 'device': device} | ||
510 | 146 | res = self.client.post(url, data) | ||
511 | 147 | self.assertRedirectsNoFollow(res, reverse('nova_volumes', | ||
512 | 148 | args=[TEST_PROJECT])) | ||
513 | 149 | self.mox.VerifyAll() | ||
514 | 150 | |||
515 | 151 | def test_detach_get(self): | ||
516 | 152 | self.mox.ReplayAll() | ||
517 | 153 | |||
518 | 154 | res = self.client.get(reverse('nova_volumes_detach', | ||
519 | 155 | args=[TEST_PROJECT, TEST_VOLUME])) | ||
520 | 156 | self.assertRedirectsNoFollow(res, reverse('nova_volumes', | ||
521 | 157 | args=[TEST_PROJECT])) | ||
522 | 158 | self.mox.VerifyAll() | ||
523 | 159 | |||
524 | 160 | def test_detach_post(self): | ||
525 | 161 | self.mox.StubOutWithMock(self.project, 'detach_volume') | ||
526 | 162 | self.project.detach_volume(TEST_VOLUME).AndReturn(True) | ||
527 | 163 | |||
528 | 164 | self.mox.ReplayAll() | ||
529 | 165 | |||
530 | 166 | res = self.client.post(reverse('nova_volumes_detach', | ||
531 | 167 | args=[TEST_PROJECT, TEST_VOLUME])) | ||
532 | 168 | self.assertRedirectsNoFollow(res, reverse('nova_volumes', | ||
533 | 169 | args=[TEST_PROJECT])) | ||
534 | 170 | self.mox.VerifyAll() | ||
535 | 0 | 171 | ||
536 | === modified file 'src/django_nova/views/credentials.py' | |||
537 | --- src/django_nova/views/credentials.py 2011-01-31 20:08:02 +0000 | |||
538 | +++ src/django_nova/views/credentials.py 2011-02-13 02:22:10 +0000 | |||
539 | @@ -17,7 +17,8 @@ | |||
540 | 17 | # under the License. | 17 | # under the License. |
541 | 18 | 18 | ||
542 | 19 | """ | 19 | """ |
544 | 20 | Views for downloading X509 credentials. | 20 | Views for downloading X509 credentials. Useful when using an invitation |
545 | 21 | style system for configuring first time users. | ||
546 | 21 | """ | 22 | """ |
547 | 22 | 23 | ||
548 | 23 | from django import http | 24 | from django import http |
549 | @@ -26,7 +27,8 @@ | |||
550 | 26 | from django_nova import models | 27 | from django_nova import models |
551 | 27 | 28 | ||
552 | 28 | 29 | ||
554 | 29 | def download_credentials(request, auth_token): | 30 | def authorize_credentials(request, auth_token): |
555 | 31 | """Sends X509 credentials to user if their auth token is valid.""" | ||
556 | 30 | auth_token = auth_token.lower() | 32 | auth_token = auth_token.lower() |
557 | 31 | credentials = models.CredentialsAuthorization.get_by_token(auth_token) | 33 | credentials = models.CredentialsAuthorization.get_by_token(auth_token) |
558 | 32 | 34 | ||
559 | 33 | 35 | ||
560 | === modified file 'src/django_nova/views/volumes.py' | |||
561 | --- src/django_nova/views/volumes.py 2011-01-25 23:16:49 +0000 | |||
562 | +++ src/django_nova/views/volumes.py 2011-02-13 02:22:10 +0000 | |||
563 | @@ -26,14 +26,14 @@ | |||
564 | 26 | from django.shortcuts import redirect, render_to_response | 26 | from django.shortcuts import redirect, render_to_response |
565 | 27 | from django_nova import exceptions | 27 | from django_nova import exceptions |
566 | 28 | from django_nova import forms | 28 | from django_nova import forms |
567 | 29 | from django_nova import shortcuts | ||
568 | 29 | from django_nova.exceptions import handle_nova_error | 30 | from django_nova.exceptions import handle_nova_error |
569 | 30 | from django_nova.shortcuts import get_project_or_404 | ||
570 | 31 | 31 | ||
571 | 32 | 32 | ||
572 | 33 | @login_required | 33 | @login_required |
573 | 34 | @handle_nova_error | 34 | @handle_nova_error |
574 | 35 | def index(request, project_id): | 35 | def index(request, project_id): |
576 | 36 | project = get_project_or_404(request, project_id) | 36 | project = shortcuts.get_project_or_404(request, project_id) |
577 | 37 | volumes = project.get_volumes() | 37 | volumes = project.get_volumes() |
578 | 38 | 38 | ||
579 | 39 | return render_to_response('django_nova/volumes/index.html', { | 39 | return render_to_response('django_nova/volumes/index.html', { |
580 | @@ -48,7 +48,7 @@ | |||
581 | 48 | @login_required | 48 | @login_required |
582 | 49 | @handle_nova_error | 49 | @handle_nova_error |
583 | 50 | def add(request, project_id): | 50 | def add(request, project_id): |
585 | 51 | project = get_project_or_404(request, project_id) | 51 | project = shortcuts.get_project_or_404(request, project_id) |
586 | 52 | 52 | ||
587 | 53 | if request.method == 'POST': | 53 | if request.method == 'POST': |
588 | 54 | form = forms.CreateVolumeForm(request.POST) | 54 | form = forms.CreateVolumeForm(request.POST) |
589 | @@ -81,7 +81,7 @@ | |||
590 | 81 | @login_required | 81 | @login_required |
591 | 82 | @handle_nova_error | 82 | @handle_nova_error |
592 | 83 | def delete(request, project_id, volume_id): | 83 | def delete(request, project_id, volume_id): |
594 | 84 | project = get_project_or_404(request, project_id) | 84 | project = shortcuts.get_project_or_404(request, project_id) |
595 | 85 | 85 | ||
596 | 86 | if request.method == 'POST': | 86 | if request.method == 'POST': |
597 | 87 | try: | 87 | try: |
598 | @@ -100,7 +100,7 @@ | |||
599 | 100 | @login_required | 100 | @login_required |
600 | 101 | @handle_nova_error | 101 | @handle_nova_error |
601 | 102 | def attach(request, project_id): | 102 | def attach(request, project_id): |
603 | 103 | project = get_project_or_404(request, project_id) | 103 | project = shortcuts.get_project_or_404(request, project_id) |
604 | 104 | 104 | ||
605 | 105 | if request.method == 'POST': | 105 | if request.method == 'POST': |
606 | 106 | form = forms.AttachVolumeForm(project, request.POST) | 106 | form = forms.AttachVolumeForm(project, request.POST) |
607 | @@ -135,7 +135,7 @@ | |||
608 | 135 | @login_required | 135 | @login_required |
609 | 136 | @handle_nova_error | 136 | @handle_nova_error |
610 | 137 | def detach(request, project_id, volume_id): | 137 | def detach(request, project_id, volume_id): |
612 | 138 | project = get_project_or_404(request, project_id) | 138 | project = shortcuts.get_project_or_404(request, project_id) |
613 | 139 | 139 | ||
614 | 140 | if request.method == 'POST': | 140 | if request.method == 'POST': |
615 | 141 | try: | 141 | try: |
approve