Skip to content

Commit 7946a7d

Browse files
committed
fix(StaticView): stop add_nearest_neighbour duplicating relationships
1 parent ac39d76 commit 7946a7d

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ History
44

55
Next Release
66
------------
7+
* Fix: Don't duplicate relationships if ``add_nearest_neighbours()`` called twice (#63)
78

89
0.3.0 (2020-11-29)
910
------------------

src/structurizr/view/static_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def add_nearest_neighbours(
106106
element_type: Union[Type[Person], Type[SoftwareSystem], Type[Container]],
107107
) -> None:
108108
"""Add all permitted elements from a model to this view."""
109-
self._add_element(element, True)
109+
self._add_element(element, False)
110110

111111
# TODO(ilaif): @midnighter - Should we move to @property instead
112112
# of get_X()? More pythonic.

tests/unit/view/test_static_view.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
"""Ensure the expected behaviour of StaticView."""
1717

1818

19-
import pytest
20-
2119
from structurizr.model import Model, Person, SoftwareSystem
2220
from structurizr.view.static_view import StaticView
2321

@@ -56,13 +54,11 @@ def test_add_nearest_neighbours():
5654
assert len(view.relationship_views) == 1
5755

5856

59-
@pytest.mark.xfail(strict=True)
6057
def test_add_nearest_neighbours_doesnt_dupe_relationships():
6158
"""Test relationships aren't duplicated if neighbours added more than once.
6259
6360
See https://github.com/Midnighter/structurizr-python/issues/63.
6461
"""
65-
6662
model = Model()
6763
sys1 = model.add_software_system(name="System 1")
6864
sys2 = model.add_software_system(name="System 2")
@@ -71,6 +67,6 @@ def test_add_nearest_neighbours_doesnt_dupe_relationships():
7167
view.add_nearest_neighbours(sys1, SoftwareSystem)
7268
assert len(view.relationship_views) == 1
7369

74-
# The next line will currently dupe the relationship
70+
# The next line should not add any new relationships
7571
view.add_nearest_neighbours(sys1, Person)
76-
assert len(view.relationship_views) == 1 # This fails as it's 2
72+
assert len(view.relationship_views) == 1

0 commit comments

Comments
 (0)