1919from structurizr .model import Container , Relationship , SoftwareSystem
2020from structurizr .model .deployment_node import DeploymentNode , DeploymentNodeIO
2121from structurizr .model .infrastructure_node import InfrastructureNode
22+ from structurizr .model .tags import Tags
2223
2324
2425class MockModel :
@@ -78,6 +79,7 @@ def test_deployment_node_init(attributes):
7879 node = DeploymentNode (** attributes )
7980 for attr , expected in attributes .items ():
8081 assert getattr (node , attr ) == expected
82+ assert Tags .DEPLOYMENT_NODE in node .tags
8183
8284
8385def 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):
99101 assert len (top_node .children ) == 1
100102
101103
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+
102123def test_deployment_node_add_child_with_existing_parent (model_with_node : MockModel ):
103124 """Check that adding a node with an existing parent fails."""
104125 top_node = model_with_node .empty_node
@@ -156,7 +177,7 @@ def test_deployment_node_add_with_iadd(model_with_node: MockModel):
156177 model_with_node += system
157178 container = Container (name = "container" )
158179 system += container
159- child_node = DeploymentNode (name = "child" )
180+ child_node = DeploymentNode (name = "child" , environment = "Live" )
160181 infra_node = InfrastructureNode (name = "infra" )
161182
162183 node += child_node
0 commit comments