19
19
from structurizr .model import Container , Relationship , SoftwareSystem
20
20
from structurizr .model .deployment_node import DeploymentNode , DeploymentNodeIO
21
21
from structurizr .model .infrastructure_node import InfrastructureNode
22
+ from structurizr .model .tags import Tags
22
23
23
24
24
25
class MockModel :
@@ -78,6 +79,7 @@ def test_deployment_node_init(attributes):
78
79
node = DeploymentNode (** attributes )
79
80
for attr , expected in attributes .items ():
80
81
assert getattr (node , attr ) == expected
82
+ assert Tags .DEPLOYMENT_NODE in node .tags
81
83
82
84
83
85
def test_deployment_node_adds_to_children (model_with_node ):
@@ -99,6 +101,25 @@ def test_deployment_node_adding_same_child_twice_is_ok(model_with_node):
99
101
assert len (top_node .children ) == 1
100
102
101
103
104
+ def test_deployment_node_child_picks_up_environment (model_with_node ):
105
+ """Ensure that the environment of the child matches the parent."""
106
+ top_node = model_with_node .empty_node
107
+ child = top_node .add_deployment_node (name = "child" )
108
+ assert child .environment == "Live"
109
+
110
+
111
+ def test_deployment_node_cant_add_child_in_different_environment (model_with_node ):
112
+ """Ensure that the environment of the child matches the parent."""
113
+ top_node = model_with_node .empty_node
114
+ child = DeploymentNode (name = "child" , environment = "Dev" )
115
+ with pytest .raises (
116
+ ValueError ,
117
+ match = r"DeploymentNode .* cannot be in a different environment \(Dev\) from "
118
+ + r"its parent \(Live\)\." ,
119
+ ):
120
+ top_node += child
121
+
122
+
102
123
def test_deployment_node_add_child_with_existing_parent (model_with_node : MockModel ):
103
124
"""Check that adding a node with an existing parent fails."""
104
125
top_node = model_with_node .empty_node
@@ -156,7 +177,7 @@ def test_deployment_node_add_with_iadd(model_with_node: MockModel):
156
177
model_with_node += system
157
178
container = Container (name = "container" )
158
179
system += container
159
- child_node = DeploymentNode (name = "child" )
180
+ child_node = DeploymentNode (name = "child" , environment = "Live" )
160
181
infra_node = InfrastructureNode (name = "infra" )
161
182
162
183
node += child_node
0 commit comments