Commit 9211165c by Czémán Arnold

dashboard: fix 'set name' tests

parent 58375aa9
Pipeline #179 passed with stage
in 0 seconds
...@@ -28,7 +28,7 @@ from dashboard.views import VmAddInterfaceView ...@@ -28,7 +28,7 @@ from dashboard.views import VmAddInterfaceView
from vm.models import Instance, InstanceTemplate, Lease, Node, Trait from vm.models import Instance, InstanceTemplate, Lease, Node, Trait
from vm.operations import (WakeUpOperation, AddInterfaceOperation, from vm.operations import (WakeUpOperation, AddInterfaceOperation,
AddPortOperation, RemoveInterfaceOperation, AddPortOperation, RemoveInterfaceOperation,
DeployOperation) DeployOperation, RenameOperation)
from ..models import Profile from ..models import Profile
from firewall.models import Vlan, Host, VlanGroup from firewall.models import Vlan, Host, VlanGroup
from mock import Mock, patch from mock import Mock, patch
...@@ -433,31 +433,43 @@ class VmDetailTest(LoginMixin, MockCeleryMixin, TestCase): ...@@ -433,31 +433,43 @@ class VmDetailTest(LoginMixin, MockCeleryMixin, TestCase):
def test_unpermitted_set_name(self): def test_unpermitted_set_name(self):
c = Client() c = Client()
self.login(c, "user2") self.login(c, "user2")
inst = Instance.objects.get(pk=1) with patch.object(RenameOperation, 'async') as mock_method:
inst.set_level(self.u2, 'user') inst = Instance.objects.get(pk=1)
old_name = inst.name mock_method.side_effect = inst.rename
response = c.post("/dashboard/vm/1/", {'new_name': 'test1235'}) inst.set_level(self.u2, 'user')
self.assertEqual(response.status_code, 403) old_name = inst.name
self.assertEqual(Instance.objects.get(pk=1).name, old_name) response = c.post("/dashboard/vm/1/op/rename/",
{'new_name': 'test1235'})
self.assertEqual(response.status_code, 403)
assert not mock_method.called
self.assertEqual(Instance.objects.get(pk=1).name, old_name)
def test_permitted_set_name(self): def test_permitted_set_name(self):
c = Client() c = Client()
self.login(c, "user2") self.login(c, "user2")
inst = Instance.objects.get(pk=1) with patch.object(RenameOperation, 'async') as mock_method:
inst.set_level(self.u2, 'owner') inst = Instance.objects.get(pk=1)
response = c.post("/dashboard/vm/1/", {'new_name': 'test1234'}) mock_method.side_effect = inst.rename
self.assertEqual(response.status_code, 302) inst.set_level(self.u2, 'owner')
self.assertEqual(Instance.objects.get(pk=1).name, 'test1234') response = c.post("/dashboard/vm/1/op/rename/",
{'new_name': 'test1234'})
self.assertEqual(response.status_code, 302)
assert mock_method.called
self.assertEqual(Instance.objects.get(pk=1).name, 'test1234')
def test_permitted_set_name_w_ajax(self): def test_permitted_set_name_w_ajax(self):
c = Client() c = Client()
self.login(c, "user2") self.login(c, "user2")
inst = Instance.objects.get(pk=1) inst = Instance.objects.get(pk=1)
inst.set_level(self.u2, 'owner') with patch.object(RenameOperation, 'async') as mock_method:
response = c.post("/dashboard/vm/1/", {'new_name': 'test123'}, inst.set_level(self.u2, 'owner')
HTTP_X_REQUESTED_WITH='XMLHttpRequest') mock_method.side_effect = inst.rename
self.assertEqual(response.status_code, 200) response = c.post("/dashboard/vm/1/op/rename/",
self.assertEqual(Instance.objects.get(pk=1).name, 'test123') {'new_name': 'test123'},
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(response.status_code, 200)
assert mock_method.called
self.assertEqual(Instance.objects.get(pk=1).name, 'test123')
def test_permitted_wake_up_wrong_state(self): def test_permitted_wake_up_wrong_state(self):
c = Client() c = Client()
......
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