Skip to content

Commit

Permalink
Test set_editable_flag_on_interfaces()
Browse files Browse the repository at this point in the history
  • Loading branch information
lunkwill42 committed Dec 13, 2023
1 parent d727a48 commit 2e73fd7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Empty file.
39 changes: 39 additions & 0 deletions tests/unittests/web/portadmin/utils_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from unittest.mock import patch, Mock

from nav.web.portadmin.utils import set_editable_flag_on_interfaces


class TestSetEditableFlagOnInterfaces:
def test_when_user_is_admin_it_should_set_all_interfaces_to_editable(self):
with patch(
"nav.web.portadmin.utils.should_check_access_rights", return_value=False
):
mock_admin = Mock()
mock_interfaces = [Mock(iseditable=False)] * 3
set_editable_flag_on_interfaces(mock_interfaces, [], mock_admin)

assert all(ifc.iseditable for ifc in mock_interfaces)

def test_when_user_is_not_admin_it_should_set_only_matching_interfaces_to_editable(
self,
):
with patch(
"nav.web.portadmin.utils.should_check_access_rights", return_value=True
):
mock_user = Mock()
mock_vlans = [Mock(vlan=42), Mock(vlan=69), Mock(vlan=666)]
editable_interface = Mock(vlan=666, iseditable=False)
mock_interfaces = [
Mock(vlan=99, iseditable=False),
editable_interface,
Mock(vlan=27, iseditable=False),
]

set_editable_flag_on_interfaces(mock_interfaces, mock_vlans, mock_user)

assert editable_interface.iseditable
assert all(
not ifc.iseditable
for ifc in mock_interfaces
if ifc is not editable_interface
)

0 comments on commit 2e73fd7

Please sign in to comment.