Skip to content

Commit 58b23d6

Browse files
yt-msMidnighter
authored andcommitted
test(DeploymentView): improve code coverage
1 parent 4fe8f5f commit 58b23d6

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

src/structurizr/view/deployment_view.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
from ..mixin.model_ref_mixin import ModelRefMixin
2222
from ..model.container_instance import ContainerInstance
23+
from ..model.deployment_element import DeploymentElement
2324
from ..model.deployment_node import DeploymentNode
24-
from ..model.element import Element
2525
from ..model.infrastructure_node import InfrastructureNode
2626
from ..model.relationship import Relationship
2727
from ..model.software_system_instance import SoftwareSystemInstance
@@ -205,9 +205,7 @@ def add_animation(
205205
deployment_node = deployment_node.parent
206206

207207
if element_ids_in_this_step == set():
208-
raise ValueError(
209-
"None of the specified container instances exist in this view."
210-
)
208+
raise ValueError("None of the specified instances exist in this view.")
211209

212210
for relationship_view in self.relationship_views:
213211
relationship = relationship_view.relationship
@@ -228,13 +226,14 @@ def add_animation(
228226
)
229227
)
230228

231-
def _find_deployment_node(self, element: Element) -> DeploymentNode:
229+
def _find_deployment_node(self, element: DeploymentElement) -> DeploymentNode:
232230
all_deployment_nodes = [
233231
e for e in self.model.get_elements() if isinstance(e, DeploymentNode)
234232
]
235233
for node in all_deployment_nodes:
236234
if (
237235
element in node.container_instances
236+
or element in node.software_system_instances
238237
or element in node.infrastructure_nodes
239238
):
240239
return node

tests/unit/view/test_deployment_view.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from structurizr import Workspace
1919
from structurizr.model import SoftwareSystem
20+
from structurizr.model.container_instance import ContainerInstance
2021
from structurizr.view.deployment_view import DeploymentView, DeploymentViewIO
2122

2223

@@ -224,6 +225,22 @@ def test_deployment_view_add_relationship(empty_workspace: Workspace):
224225
assert len(deployment_view.relationship_views) == 1
225226

226227

228+
def test_deployment_view_adding_system_instance(empty_workspace: Workspace):
229+
"""Test that `SoftwareSystemInstance` is supported within deployment view."""
230+
model = empty_workspace.model
231+
software_system = model.add_software_system("Software System")
232+
deployment_node = model.add_deployment_node("Deployment Node")
233+
software_system_instance = deployment_node.add_software_system(software_system)
234+
235+
deployment_view = empty_workspace.views.create_deployment_view(
236+
software_system=software_system, key="deployment", description="Description"
237+
)
238+
deployment_view.add_default_elements()
239+
240+
views = deployment_view.element_views
241+
assert any([x.element is software_system_instance for x in views])
242+
243+
227244
def test_add_animation_step_raises_if_no_elements(empty_workspace: Workspace):
228245
"""Check error handling if no elements passed."""
229246
deployment_view = empty_workspace.views.create_deployment_view(
@@ -233,6 +250,26 @@ def test_add_animation_step_raises_if_no_elements(empty_workspace: Workspace):
233250
deployment_view.add_animation()
234251

235252

253+
def test_deployment_view_find_deployment_node(empty_workspace: Workspace):
254+
"""Test _find_deployment_node."""
255+
model = empty_workspace.model
256+
software_system = model.add_software_system("Software System")
257+
container1 = software_system.add_container("Container 1")
258+
node1 = model.add_deployment_node("Deployment Node 1")
259+
container_instance1 = node1.add_container(container1)
260+
container2 = software_system.add_container("Container 2")
261+
container_instance2 = ContainerInstance(container=container2, instance_id=1)
262+
# Explicitly we don't add container_instance2 to a deployment node
263+
264+
deployment_view = empty_workspace.views.create_deployment_view(
265+
software_system=software_system, key="deployment", description="Description"
266+
)
267+
deployment_view += node1
268+
269+
assert deployment_view._find_deployment_node(container_instance1) is node1
270+
assert deployment_view._find_deployment_node(container_instance2) is None
271+
272+
236273
def test_add_animation_step(empty_workspace: Workspace):
237274
"""Check happy path."""
238275
model = empty_workspace.model

0 commit comments

Comments
 (0)