Commit b36dc101 by Bach Dániel

dashboard: update change_password tests

parent f2ad812f
...@@ -7,6 +7,7 @@ from vm.models import Instance, InstanceTemplate, Lease, Node ...@@ -7,6 +7,7 @@ from vm.models import Instance, InstanceTemplate, Lease, Node
from ..models import Profile from ..models import Profile
from storage.models import Disk from storage.models import Disk
from firewall.models import Vlan from firewall.models import Vlan
from mock import Mock
class LoginMixin(object): class LoginMixin(object):
...@@ -17,9 +18,10 @@ class LoginMixin(object): ...@@ -17,9 +18,10 @@ class LoginMixin(object):
class VmDetailTest(LoginMixin, TestCase): class VmDetailTest(LoginMixin, TestCase):
fixtures = ['test-vm-fixture.json'] fixtures = ['test-vm-fixture.json', 'node.json']
def setUp(self): def setUp(self):
Instance.get_remote_queue_name = Mock(return_value='test')
self.u1 = User.objects.create(username='user1') self.u1 = User.objects.create(username='user1')
self.u1.set_password('password') self.u1.set_password('password')
self.u1.save() self.u1.save()
...@@ -111,6 +113,19 @@ class VmDetailTest(LoginMixin, TestCase): ...@@ -111,6 +113,19 @@ class VmDetailTest(LoginMixin, TestCase):
response = c.post('/dashboard/vm/mass-delete/', {'vms': [1]}) response = c.post('/dashboard/vm/mass-delete/', {'vms': [1]})
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
def test_permitted_password_change(self):
c = Client()
self.login(c, "user2")
inst = Instance.objects.get(pk=1)
inst.set_level(self.u2, 'owner')
inst.node = Node.objects.all()[0]
inst.save()
password = inst.pw
response = c.post("/dashboard/vm/1/", {'change_password': True})
self.assertTrue(Instance.get_remote_queue_name.called)
self.assertEqual(response.status_code, 302)
self.assertNotEqual(password, Instance.objects.get(pk=1).pw)
def test_unpermitted_password_change(self): def test_unpermitted_password_change(self):
c = Client() c = Client()
self.login(c, "user2") self.login(c, "user2")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment