Skip to content

Commit

Permalink
Merge pull request #3226 from Uninett/bugfix/netmap-stub-netbox-eq-fix
Browse files Browse the repository at this point in the history
Fix broken `__eq__` implementation of Netbox stub class
  • Loading branch information
lunkwill42 authored Nov 24, 2024
2 parents cf6a25b + a92583a commit 6bc8e0a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/3225.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix spurious crashing when loading some Netmap layer 3 views
6 changes: 2 additions & 4 deletions python/nav/netmap/stubs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ def __repr__(self):
def __key(self):
return self.sysname

# Yes we know we access private variable
# pylint: disable=W0212
def __eq__(self, i):
return self.__key() == i.__key()
def __eq__(self, value):
return self.sysname == getattr(value, "sysname", None)

def __hash__(self):
return hash(self.__key())
Expand Down
18 changes: 18 additions & 0 deletions tests/unittests/netmap/stubs_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from nav.netmap.stubs import Netbox
from nav.models import manage


class TestNetboxEqWithNonStubValues:
def test_when_value_is_orm_model_with_same_sysname_it_should_return_true(self):
localhost = manage.Netbox(sysname='localhost')
stub = Netbox()
stub.sysname = localhost.sysname
assert stub == localhost

def test_when_value_is_orm_model_with_different_sysname_it_should_return_false(
self,
):
localhost = manage.Netbox(sysname='localhost')
stub = Netbox()
stub.sysname = "stubhost"
assert stub != localhost

0 comments on commit 6bc8e0a

Please sign in to comment.