Skip to content

Commit 756b85d

Browse files
yt-msMidnighter
authored andcommitted
feat(DeploymentNode): add uses() for relationships between nodes
1 parent 46f348a commit 756b85d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/structurizr/model/deployment_node.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from .deployment_element import DeploymentElement, DeploymentElementIO
2525
from .element import Element
2626
from .infrastructure_node import InfrastructureNode, InfrastructureNodeIO
27+
from .relationship import Relationship
2728
from .software_system import SoftwareSystem
2829
from .software_system_instance import SoftwareSystemInstance, SoftwareSystemInstanceIO
2930

@@ -255,6 +256,22 @@ def __iadd__(
255256
self._add_child_deployment_node(child)
256257
return self
257258

259+
def uses(
260+
self,
261+
destination: "DeploymentNode",
262+
description: str = "Uses",
263+
technology: str = "",
264+
**kwargs,
265+
) -> Optional["Relationship"]:
266+
"""Add a relationship between this and another deployment node."""
267+
return self.model.add_relationship(
268+
source=self,
269+
destination=destination,
270+
description=description,
271+
technology=technology,
272+
**kwargs,
273+
)
274+
258275
def _add_infrastructure_node(self, infra_node: InfrastructureNode):
259276
"""Add a new infrastructure node."""
260277
self._infrastructure_nodes.add(infra_node)

tests/unit/model/test_deployment_node.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import pytest
1818

19-
from structurizr.model import Container, SoftwareSystem
19+
from structurizr.model import Container, Relationship, SoftwareSystem
2020
from structurizr.model.deployment_node import DeploymentNode, DeploymentNodeIO
2121
from structurizr.model.infrastructure_node import InfrastructureNode
2222

@@ -46,6 +46,9 @@ def get_elements(self):
4646
"""Simulate get_elements."""
4747
return []
4848

49+
def add_relationship(self, **kwargs):
50+
return Relationship(**kwargs)
51+
4952

5053
class MockElement:
5154
"""Implement a mock element for testing."""
@@ -256,3 +259,15 @@ def test_deployment_node_serialising_infrastructure_nodes(model_with_node):
256259
infra_node = node2.infrastructure_nodes[0]
257260
assert infra_node.name == "infraNode"
258261
assert infra_node.parent is node2
262+
263+
264+
def test_deployment_node_uses_adds_relationship(model_with_node):
265+
node1 = model_with_node.empty_node
266+
node2 = DeploymentNode(name="node2")
267+
node2.set_model(model_with_node)
268+
rel = node1.uses(node2, "Replicates data to", technology="Some tech")
269+
270+
assert rel.source is node1
271+
assert rel.destination is node2
272+
assert rel.description == "Replicates data to"
273+
assert rel.technology == "Some tech"

0 commit comments

Comments
 (0)