Commit 1d96f59c by Chif Gergő

dashboard: Unit test for set master interface

Created a Unit test. It calls set master interface operation on an interface. Assert checks the is_master attribute is True.
parent c2cad011
Pipeline #676 passed with stage
in 0 seconds
......@@ -29,6 +29,7 @@ from common.tests.celery_mock import MockCeleryMixin
from dashboard.views import VmAddInterfaceView
from vm.models import Instance, InstanceTemplate, Lease, Node, Trait
from vm.operations import (WakeUpOperation, AddInterfaceOperation,
AddPortOperation, RemoveInterfaceOperation,
DeployOperation, RenameOperation)
from ..models import Profile
......@@ -182,6 +183,24 @@ class VmDetailTest(LoginMixin, MockCeleryMixin, TestCase):
assert mock_method.called
self.assertEqual(inst.interface_set.count(), iface_count - 1)
def test_permitted_set_master_interface(self):
c = Client()
self.login(c, "user1")
inst = Instance.objects.get(pk=1)
inst.set_level(self.u1, 'owner')
inst.status = 'STOPPED'
with patch.object(SetMasterInterfaceOperation, 'async') as mock_method:
mock_method.side_effect = inst.set_master_interface
response ="/dashboard/vm/1/op/set_master_interface/",
{'interface': 1})
self.assertEqual(response.status_code, 302)
assert mock_method.called
self.assertEqual(inst.interface_set.filter(is_master=True).count(), 1)
def test_unpermitted_network_delete(self):
c = Client()
self.login(c, "user1")
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