3 from django
.contrib
.auth
.models
import User
5 from ganeti
import models
6 from ganeti
.tests
.rapi_proxy
import JOB_RUNNING
7 from ganeti
.tests
.views
.virtual_machine
.base
import TestVirtualMachineViewsBase
8 from ganeti
.utilities
import cluster_os_list
10 __all__
= ['TestVirtualMachineEditViews',
11 'TestVirtualMachineDeleteViews',
12 'TestVirtualMachineReinstallViews',
13 'TestVirtualMachineRenameViews',
14 'TestVirtualMachineReparentViews']
16 VirtualMachine
= models
.VirtualMachine
19 global user
, user1
, superuser
, cluster_admin
, vm_admin
, vm_modify
, cluster_migrate
22 class TestVirtualMachineEditViews(TestVirtualMachineViewsBase
):
26 def test_view_modify(self
):
28 Test modifying an instance
31 args
= (cluster
.slug
, vm
.hostname
)
32 url
= '/cluster/%s/%s/edit' % args
34 user
= User(id=52, username
='modifier')
35 user
.set_password('secret2')
41 self
.assertEqual(302, response
.status_code
)
43 # User with Modify Permissions
44 user
.grant('modify', vm
)
45 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
46 self
.assertFalse(user
.is_superuser
)
47 self
.assertTrue(user
.has_perm('modify', vm
))
48 self
.assertFalse(user
.has_perm('admin', vm
))
50 self
.assertEqual(200, response
.status_code
)
51 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
52 self
.assertTemplateUsed(response
, 'virtual_machine/edit.html')
56 # User with Admin Permissions
57 user
.grant('admin', vm
)
58 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
59 self
.assertFalse(user
.is_superuser
)
61 self
.assertEqual(200, response
.status_code
)
62 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
63 self
.assertTemplateUsed(response
, 'virtual_machine/edit.html')
68 user
.is_superuser
= True
70 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
72 self
.assertEqual(200, response
.status_code
)
73 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
74 self
.assertTemplateUsed(response
, 'virtual_machine/edit.html')
76 user
.is_superuser
= False
80 os_list
= cluster_os_list(cluster
)
88 migration_downtime
=30,
90 security_model
='none',
94 vnc_bind_addres
='0.0.0.0',
97 vnc_x509_verify
=False,
99 os_name
='image+debian-osgeo',
100 disk_type
='paravirtual',
102 nic_type
='paravirtual',
104 nic_mac
='aa:bb:00:00:33:d2',
105 root_path
='/dev/vda1',
106 kernel_path
='/boot/vmlinuz-2.32.6-27-generic',
111 user
.grant('modify', vm
)
112 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
114 session
['os_list'] = os_list
116 for property in ['vcpus', 'memory', 'disk_type', 'boot_order',
120 self
.assertFalse(user
.is_superuser
)
121 response
= c
.post(url
, data_
)
122 # If failure then a field that is not required by the model, but
123 # should be required by the form, is not being required by
124 # the form. See the ModifyVirtualMachineForm.required field.
125 self
.assertNotEqual(response
.context
['form'][property].errors
, [], msg
=property)
126 self
.assertEqual(200, response
.status_code
) # 302 if success (BAD)
127 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
128 self
.assertTemplateUsed(response
, 'virtual_machine/edit.html')
134 response
= c
.post(url
, data
)
135 self
.assertEqual(302, response
.status_code
)
138 user
.is_superuser
= True
140 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
141 self
.assertTrue(user
.is_superuser
)
143 session
['os_list'] = os_list
145 response
= c
.post(url
, data
)
146 self
.assertEqual(302, response
.status_code
)
147 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
149 user
.is_superuser
= False
152 # User without Permissions
153 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
154 self
.assertFalse(user
.is_superuser
)
156 session
['os_list'] = os_list
158 response
= c
.post(url
, data
)
159 self
.assertEqual(403, response
.status_code
)
160 self
.assertTrue(response
.context
['message'])
161 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
162 self
.assertTemplateUsed(response
, '403.html')
165 # User with Modify Permissions
166 user
.grant('modify', vm
)
167 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
168 self
.assertFalse(user
.is_superuser
)
170 session
['os_list'] = os_list
172 response
= c
.post(url
, data
)
173 self
.assertEqual(302, response
.status_code
)
174 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
178 # User with Admin Permissions
179 user
.grant('admin', vm
)
180 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
181 self
.assertFalse(user
.is_superuser
)
183 session
['os_list'] = os_list
185 response
= c
.post(url
, data
)
186 self
.assertEqual(302, response
.status_code
)
187 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
191 def test_view_modify_confirm(self
):
193 Test confirm page for modifying an instance
196 args
= (cluster
.slug
, vm
.hostname
)
197 url
= '/cluster/%s/%s/edit/confirm' % args
199 user
= User(id=52, username
='modifier')
200 user
.set_password('secret2')
203 vm
.owner
= user
.get_profile()
206 os_list
= cluster_os_list(cluster
)
207 edit_form
= dict(vcpus
=2,
209 disk_cache
='default',
214 migration_downtime
=30,
216 security_model
='none',
220 vnc_bind_addres
='0.0.0.0',
223 vnc_x509_verify
=False,
225 os_name
='image+debian-osgeo',
226 disk_type
='paravirtual',
228 nic_type
='paravirtual',
230 nic_mac
='aa:bb:00:00:33:d2',
231 root_path
='/dev/vda1',
232 kernel_path
='/boot/vmlinuz-2.32.6-27-generic',
237 # Make sure session variables are set
238 user
.is_superuser
= True
240 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
243 response
= c
.get(url
)
244 self
.assertEqual(400, response
.status_code
)
245 session
['edit_form'] = edit_form
247 response
= c
.get(url
)
248 self
.assertEqual(200, response
.status_code
)
249 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
250 self
.assertTemplateUsed(response
, 'virtual_machine/edit_confirm.html')
252 #session['os_list'] = os_list
255 user
.is_superuser
= False
261 response
= c
.get(url
)
262 self
.assertEqual(302, response
.status_code
)
264 # User with Modify Permissions
265 user
.grant('modify', vm
)
266 self
.assertFalse(user
.is_superuser
)
267 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
269 session
['edit_form'] = edit_form
270 session
['os_list'] = os_list
272 response
= c
.get(url
)
273 self
.assertEqual(200, response
.status_code
)
274 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
275 self
.assertTemplateUsed(response
, 'virtual_machine/edit_confirm.html')
279 # User with Admin Permissions
280 user
.grant('admin', vm
)
281 self
.assertFalse(user
.is_superuser
)
282 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
284 session
['edit_form'] = edit_form
285 session
['os_list'] = os_list
287 response
= c
.get(url
)
288 self
.assertEqual(200, response
.status_code
)
289 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
290 self
.assertTemplateUsed(response
, 'virtual_machine/edit_confirm.html')
295 user
.is_superuser
= True
297 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
299 session
['edit_form'] = edit_form
300 session
['os_list'] = os_list
302 response
= c
.get(url
)
303 self
.assertEqual(200, response
.status_code
)
304 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
305 self
.assertTemplateUsed(response
, 'virtual_machine/edit_confirm.html')
307 user
.is_superuser
= False
311 data
= {'rapi_dict':json
.dumps(edit_form
)}
313 response
= c
.post(url
, data
)
314 self
.assertEqual(302, response
.status_code
)
316 for i
in ('cancel', 'edit', 'save', 'reboot'):
320 user
.is_superuser
= True
322 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
324 session
['edit_form'] = edit_form
325 session
['os_list'] = os_list
327 self
.assertTrue(user
.is_superuser
)
328 response
= c
.post(url
, data
)
329 self
.assertEqual(302, response
.status_code
)
330 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
332 user
.is_superuser
= False
335 # User without Permissions
336 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
337 self
.assertFalse(user
.is_superuser
)
338 response
= c
.post(url
, data
)
339 self
.assertEqual(403, response
.status_code
)
340 self
.assertTrue(response
.context
['message'])
341 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
342 self
.assertTemplateUsed(response
, '403.html')
345 # User with Modify Permissions
346 user
.grant('modify', vm
)
347 user
.grant('power', vm
)
348 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
350 session
['edit_form'] = edit_form
351 session
['os_list'] = os_list
353 self
.assertFalse(user
.is_superuser
)
354 response
= c
.post(url
, data
)
355 self
.assertEqual(302, response
.status_code
)
356 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
360 # User with Admin Permissions
361 user
.grant('admin', vm
)
362 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
364 session
['edit_form'] = edit_form
365 session
['os_list'] = os_list
367 self
.assertFalse(user
.is_superuser
)
368 response
= c
.post(url
, data
)
369 self
.assertEqual(302, response
.status_code
)
370 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
376 def test_view_modify_quota_over(self
):
378 args
= (cluster
.slug
, vm
.hostname
)
379 url
= '/cluster/%s/%s/edit' % args
381 user
= User(id=52, username
='modifier')
382 user
.set_password('secret2')
384 user
.grant('modify', vm
)
385 profile
= user
.get_profile()
389 cluster
.set_quota(profile
, dict(ram
=1000, disk
=2000, virtual_cpus
=10))
392 os_list
= cluster_os_list(cluster
)
393 data
= dict(vcpus
=2000,
395 disk_cache
='default',
400 migration_downtime
=30,
402 security_model
='none',
406 vnc_bind_addres
='0.0.0.0',
409 vnc_x509_verify
=False,
411 os
='image+debian-osgeo',
412 disk_type
='paravirtual',
414 nic_type
='paravirtual',
416 nic_mac
='aa:bb:00:00:33:d2',
417 root_path
='/dev/vda1',
418 kernel_path
='/boot/vmlinuz-2.32.6-27-generic',
422 user
.grant('modify', vm
)
423 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
424 self
.assertFalse(user
.is_superuser
)
426 session
['os_list'] = os_list
428 response
= c
.post(url
, data
)
429 self
.assertEqual(200, response
.status_code
) # 302 if success (BAD)
430 self
.assertTemplateUsed(response
, 'virtual_machine/edit.html')
434 def test_view_modify_confirm_quota_over(self
):
436 args
= (cluster
.slug
, vm
.hostname
)
437 url
= '/cluster/%s/%s/edit/confirm' % args
439 user
= User(id=52, username
='modifier')
440 user
.set_password('secret2')
442 user
.grant('modify', vm
)
443 profile
= user
.get_profile()
447 cluster
.set_quota(profile
, dict(ram
=1000, disk
=2000, virtual_cpus
=10))
449 os_list
= cluster_os_list(cluster
)
450 edit_form
= dict(vcpus
=2000,
452 disk_cache
='default',
457 migration_downtime
=30,
459 security_model
='none',
463 vnc_bind_addres
='0.0.0.0',
466 vnc_x509_verify
=False,
468 os
='image+debian-osgeo',
469 disk_type
='paravirtual',
471 nic_type
='paravirtual',
473 nic_mac
='aa:bb:00:00:33:d2',
474 root_path
='/dev/vda1',
475 kernel_path
='/boot/vmlinuz-2.32.6-27-generic',
478 data
= {'rapi_dict':json
.dumps(edit_form
), 'save':True}
481 self
.assertTrue(c
.login(username
=user
.username
, password
='secret2'))
483 session
['edit_form'] = edit_form
484 session
['os_list'] = os_list
486 response
= c
.post(url
, data
)
487 self
.assertEqual(200, response
.status_code
)
488 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
489 self
.assertTemplateUsed(response
, 'virtual_machine/edit_confirm.html')
493 class TestVirtualMachineDeleteViews(TestVirtualMachineViewsBase
):
496 def test_view_delete(self
):
498 Tests view for deleting virtual machines
500 url
= '/cluster/%s/%s/delete'
501 args
= (cluster
.slug
, vm
.hostname
)
504 response
= c
.get(url
% args
, follow
=True)
505 self
.assertEqual(200, response
.status_code
)
506 self
.assertTemplateUsed(response
, 'registration/login.html')
509 self
.assert_(c
.login(username
=user
.username
, password
='secret'))
510 response
= c
.post(url
% args
)
511 self
.assertEqual(403, response
.status_code
)
514 response
= c
.get(url
% (cluster
.slug
, "DoesNotExist"))
515 self
.assertEqual(404, response
.status_code
)
517 # authorized GET (vm remove permissions)
518 user
.grant('remove', vm
)
519 response
= c
.get(url
% args
)
520 self
.assertEqual(200, response
.status_code
)
521 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
522 self
.assertTemplateUsed(response
, 'virtual_machine/delete.html')
523 self
.assert_(VirtualMachine
.objects
.filter(id=vm
.id).exists())
526 # authorized GET (vm admin permissions)
527 user
.grant('admin', vm
)
528 response
= c
.get(url
% args
)
529 self
.assertEqual(200, response
.status_code
)
530 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
531 self
.assertTemplateUsed(response
, 'virtual_machine/delete.html')
532 self
.assert_(VirtualMachine
.objects
.filter(id=vm
.id).exists())
533 user
.revoke_all(cluster
)
535 # authorized GET (cluster admin permissions)
536 user
.grant('admin', cluster
)
537 response
= c
.get(url
% args
)
538 self
.assertEqual(200, response
.status_code
)
539 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
540 self
.assertTemplateUsed(response
, 'virtual_machine/delete.html')
541 self
.assert_(VirtualMachine
.objects
.filter(id=vm
.id).exists())
542 user
.revoke_all(cluster
)
544 # authorized GET (superuser)
545 user
.is_superuser
= True
547 response
= c
.get(url
% args
)
548 self
.assertEqual(200, response
.status_code
)
549 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
550 self
.assertTemplateUsed(response
, 'virtual_machine/delete.html')
551 self
.assert_(VirtualMachine
.objects
.filter(id=vm
.id).exists())
553 #authorized POST (superuser)
554 user1
.grant('power', vm
)
555 vm
.rapi
.GetJobStatus
.response
= JOB_RUNNING
556 response
= c
.post(url
% args
, follow
=True)
557 self
.assertEqual(200, response
.status_code
)
558 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
559 self
.assertTemplateUsed(response
, 'virtual_machine/delete_status.html')
560 self
.assert_(VirtualMachine
.objects
.filter(id=vm
.id).exists())
561 pending_delete
, job_id
= VirtualMachine
.objects
.filter(id=vm
.id).values('pending_delete','last_job_id')[0]
562 self
.assert_(pending_delete
)
564 user
.is_superuser
= False
568 #authorized POST (cluster admin)
569 user
.grant('admin', cluster
)
570 user1
.grant('power', vm
)
571 response
= c
.post(url
% args
, follow
=True)
572 self
.assertEqual(200, response
.status_code
)
573 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
574 self
.assertTemplateUsed(response
, 'virtual_machine/delete_status.html')
575 self
.assert_(VirtualMachine
.objects
.filter(id=vm
.id).exists())
576 pending_delete
, job_id
= VirtualMachine
.objects
.filter(id=vm
.id).values('pending_delete','last_job_id')[0]
577 self
.assert_(pending_delete
)
579 user
.revoke_all(cluster
)
581 #authorized POST (vm admin)
583 user
.grant('admin', vm
)
584 user1
.grant('power', vm
)
585 response
= c
.post(url
% args
, follow
=True)
586 self
.assertEqual(200, response
.status_code
)
587 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
588 self
.assertTemplateUsed(response
, 'virtual_machine/delete_status.html')
589 self
.assert_(VirtualMachine
.objects
.filter(id=vm
.id).exists())
590 pending_delete
, job_id
= VirtualMachine
.objects
.filter(id=vm
.id).values('pending_delete','last_job_id')[0]
591 self
.assert_(pending_delete
)
596 #authorized POST (cluster admin)
598 user
.grant('remove', vm
)
599 user1
.grant('power', vm
)
600 response
= c
.post(url
% args
, follow
=True)
601 self
.assertEqual(200, response
.status_code
)
602 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
603 self
.assertTemplateUsed(response
, 'virtual_machine/delete_status.html')
604 self
.assert_(VirtualMachine
.objects
.filter(id=vm
.id).exists())
605 pending_delete
, job_id
= VirtualMachine
.objects
.filter(id=vm
.id).values('pending_delete','last_job_id')[0]
606 self
.assert_(pending_delete
)
612 class TestVirtualMachineReinstallViews(TestVirtualMachineViewsBase
):
616 def test_view_reinstall(self
):
618 Tests view for reinstalling virtual machines
620 url
= '/cluster/%s/%s/reinstall'
621 args
= (cluster
.slug
, vm
.hostname
)
624 response
= c
.get(url
% args
, follow
=True)
625 self
.assertEqual(200, response
.status_code
)
626 self
.assertTemplateUsed(response
, 'registration/login.html')
629 self
.assert_(c
.login(username
=user
.username
, password
='secret'))
630 response
= c
.post(url
% args
)
631 self
.assertEqual(403, response
.status_code
)
634 response
= c
.get(url
% (cluster
.slug
, "DoesNotExist"))
635 self
.assertEqual(404, response
.status_code
)
637 # authorized GET (vm remove permissions)
638 user
.grant('remove', vm
)
639 response
= c
.get(url
% args
)
640 self
.assertEqual(200, response
.status_code
)
641 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
642 self
.assertTemplateUsed(response
, 'virtual_machine/reinstall.html')
643 self
.assert_(VirtualMachine
.objects
.filter(id=vm
.id).exists())
646 # authorized GET (vm admin permissions)
647 user
.grant('admin', vm
)
648 response
= c
.get(url
% args
)
649 self
.assertEqual(200, response
.status_code
)
650 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
651 self
.assertTemplateUsed(response
, 'virtual_machine/reinstall.html')
652 self
.assert_(VirtualMachine
.objects
.filter(id=vm
.id).exists())
653 user
.revoke_all(cluster
)
655 # authorized GET (cluster admin permissions)
656 user
.grant('admin', cluster
)
657 response
= c
.get(url
% args
)
658 self
.assertEqual(200, response
.status_code
)
659 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
660 self
.assertTemplateUsed(response
, 'virtual_machine/reinstall.html')
661 self
.assert_(VirtualMachine
.objects
.filter(id=vm
.id).exists())
662 user
.revoke_all(cluster
)
664 # authorized GET (superuser)
665 user
.is_superuser
= True
667 response
= c
.get(url
% args
)
668 self
.assertEqual(200, response
.status_code
)
669 self
.assertEqual('text/html; charset=utf-8', response
['content-type'])
670 self
.assertTemplateUsed(response
, 'virtual_machine/reinstall.html')
671 self
.assert_(VirtualMachine
.objects
.filter(id=vm
.id).exists())
673 #authorized POST (superuser)
674 response
= c
.post(url
% args
)
675 self
.assertEqual(302, response
.status_code
)
676 user
.is_superuser
= False
680 #authorized POST (cluster admin)
681 user
.grant('admin', cluster
)
682 response
= c
.post(url
% args
)
683 self
.assertEqual(302, response
.status_code
)
684 user
.revoke_all(cluster
)
686 #authorized POST (vm admin)
688 user
.grant('admin', vm
)
689 response
= c
.post(url
% args
)
690 self
.assertEqual(302, response
.status_code
)
694 #authorized POST (cluster admin)
696 user
.grant('remove', vm
)
697 response
= c
.post(url
% args
)
698 self
.assertEqual(302, response
.status_code
)
703 class TestVirtualMachineRenameViews(TestVirtualMachineViewsBase
):
707 def test_view_rename_get(self
):
709 VM rename GET requests should have the standard responses.
712 url
= "/cluster/%s/%s/rename/"
713 args
= (cluster
.slug
, vm
.hostname
)
714 template
= 'virtual_machine/rename.html'
715 users
=[superuser
, cluster_admin
, vm_admin
, vm_modify
]
716 denied
= [cluster_migrate
]
719 self
.assert_standard_fails(url
, args
)
720 self
.assert_200(url
, args
, users
, template
=template
)
721 self
.assert_403(url
, args
, denied
)
723 def test_view_rename_post(self
):
725 VM rename POST requests should have the standard responses.
728 url
= "/cluster/%s/%s/rename/"
729 args
= (cluster
.slug
, vm
.hostname
)
730 template_success
= 'virtual_machine/detail.html'
731 users
= [superuser
, cluster_admin
, vm_admin
, vm_modify
]
732 denied
= [cluster_migrate
]
733 data
= {'hostname':'foo.arg.different', 'ip_check':False, 'name_check':False}
735 #noinspection PyUnusedLocal
736 def tests(user
, response
):
737 updated_vm
= VirtualMachine
.objects
.get(pk
=vm
.pk
)
738 self
.assertEqual('foo.arg.different', updated_vm
.hostname
)
741 self
.assert_standard_fails(url
, args
, data
, method
='post')
742 self
.assert_200(url
, args
, users
, template_success
, data
=data
, follow
=True, method
="post", tests
=tests
)
743 self
.assert_403(url
, args
, denied
, data
=data
, method
="post")
745 def test_view_rename_form(self
):
747 Tests that form validation is working properly
750 url
= "/cluster/%s/%s/rename/"
751 args
= (cluster
.slug
, vm
.hostname
)
752 template
= 'virtual_machine/rename.html'
753 data
= {'hostname':'foo.arg.different', 'ip_check':False, 'name_check':False}
754 errors
= ({'hostname':vm
.hostname
},)
756 #noinspection PyUnusedLocal
757 def tests(user
, response
):
758 updated_vm
= VirtualMachine
.objects
.get(pk
=vm
.pk
)
759 self
.assertEqual(vm
.hostname
, updated_vm
.hostname
)
761 self
.assert_view_missing_fields(url
, args
, data
, fields
=['hostname'], template
=template
, tests
=tests
)
762 self
.assert_view_values(url
, args
, data
, errors
, template
, tests
=tests
)
765 class TestVirtualMachineReparentViews(TestVirtualMachineViewsBase
):
769 def test_view_rename_get(self
):
771 VM reparent GET requests should have the standard responses.
774 url
= "/cluster/%s/%s/reparent/"
775 args
= (cluster
.slug
, vm
.hostname
)
776 template
= 'virtual_machine/reparent.html'
777 users
=[superuser
, cluster_admin
]
778 denied
= [vm_admin
, vm_modify
, cluster_migrate
]
781 self
.assert_standard_fails(url
, args
)
782 self
.assert_200(url
, args
, users
, template
=template
)
783 self
.assert_403(url
, args
, denied
)
785 def test_view_rename_post(self
):
787 VM reparent POST requests should have the standard responses.
790 vm
.owner
= vm_admin
.get_profile()
793 url
= "/cluster/%s/%s/reparent/"
794 args
= (cluster
.slug
, vm
.hostname
)
795 template_success
= 'virtual_machine/detail.html'
796 users
= [superuser
, cluster_admin
]
797 denied
= [vm_admin
, vm_modify
, cluster_migrate
]
798 data
= {'owner':vm_modify
.get_profile().pk
}
800 #noinspection PyUnusedLocal
801 def tests(user
, response
):
802 updated_vm
= VirtualMachine
.objects
.get(pk
=vm
.pk
)
803 self
.assertEqual(vm_modify
.get_profile().clusteruser_ptr
, updated_vm
.owner
)
805 self
.assert_standard_fails(url
, args
, data
, method
='post')
806 self
.assert_200(url
, args
, users
, template_success
, data
=data
, follow
=True, method
="post", tests
=tests
)
807 self
.assert_403(url
, args
, denied
, data
=data
, method
="post")