|
15 | 15 | parse_human_friendly_id, |
16 | 16 | ) |
17 | 17 | from infrahub_sdk.node.constants import SAFE_VALUE |
| 18 | +from infrahub_sdk.node.related_node import RelatedNode, RelatedNodeSync |
18 | 19 | from infrahub_sdk.schema import GenericSchema, NodeSchemaAPI |
19 | 20 |
|
20 | 21 | if TYPE_CHECKING: |
@@ -194,6 +195,50 @@ async def test_init_node_data_user_with_relationships(client, location_schema: N |
194 | 195 | assert "get_kind" in keys |
195 | 196 |
|
196 | 197 |
|
| 198 | +@pytest.mark.parametrize("client_type", client_types) |
| 199 | +@pytest.mark.parametrize("rel_data", [{"id": "pppppppp"}, {"hfid": ["pppp", "pppp"]}]) |
| 200 | +async def test_init_node_data_user_with_relationships_using_related_node( |
| 201 | + client, location_schema: NodeSchemaAPI, client_type, rel_data |
| 202 | +): |
| 203 | + rel_schema = location_schema.get_relationship(name="primary_tag") |
| 204 | + if client_type == "standard": |
| 205 | + primary_tag = RelatedNode(name="primary_tag", branch="main", client=client, schema=rel_schema, data=rel_data) |
| 206 | + else: |
| 207 | + primary_tag = RelatedNodeSync( |
| 208 | + name="primary_tag", branch="main", client=client, schema=rel_schema, data=rel_data |
| 209 | + ) |
| 210 | + |
| 211 | + data = { |
| 212 | + "name": {"value": "JFK1"}, |
| 213 | + "description": {"value": "JFK Airport"}, |
| 214 | + "type": {"value": "SITE"}, |
| 215 | + "primary_tag": primary_tag, |
| 216 | + "tags": [{"id": "aaaaaa"}, {"id": "bbbb"}], |
| 217 | + } |
| 218 | + if client_type == "standard": |
| 219 | + node = InfrahubNode(client=client, schema=location_schema, data=data) |
| 220 | + else: |
| 221 | + node = InfrahubNodeSync(client=client, schema=location_schema, data=data) |
| 222 | + |
| 223 | + assert node.name.value == "JFK1" |
| 224 | + assert node.name.is_protected is None |
| 225 | + assert node.description.value == "JFK Airport" |
| 226 | + assert node.type.value == "SITE" |
| 227 | + |
| 228 | + assert isinstance(node.tags, RelationshipManagerBase) |
| 229 | + assert len(node.tags.peers) == 2 |
| 230 | + assert isinstance(node.tags.peers[0], RelatedNodeBase) |
| 231 | + assert isinstance(node.primary_tag, RelatedNodeBase) |
| 232 | + assert node.primary_tag.id == rel_data.get("id") |
| 233 | + assert node.primary_tag.hfid == rel_data.get("hfid") |
| 234 | + |
| 235 | + keys = dir(node) |
| 236 | + assert "name" in keys |
| 237 | + assert "type" in keys |
| 238 | + assert "tags" in keys |
| 239 | + assert "get_kind" in keys |
| 240 | + |
| 241 | + |
197 | 242 | @pytest.mark.parametrize("property_test", property_tests) |
198 | 243 | @pytest.mark.parametrize("client_type", client_types) |
199 | 244 | async def test_init_node_data_graphql( |
|
0 commit comments