Skip to content

Commit f2094a7

Browse files
committed
Validate with unit test
1 parent 254f8ef commit f2094a7

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

tests/unit/sdk/conftest.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,15 @@ async def simple_device_schema() -> NodeSchema:
821821
"optional": True,
822822
"cardinality": "one",
823823
"kind": "Attribute",
824-
}
824+
},
825+
{
826+
"name": "ip_address_pool",
827+
"peer": "CoreIPAddressPool",
828+
"label": "Address allocator",
829+
"optional": True,
830+
"cardinality": "one",
831+
"kind": "Attribute",
832+
},
825833
],
826834
}
827835
return NodeSchema(**data) # type: ignore

tests/unit/sdk/test_node.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,9 @@ async def test_create_input_data_with_resource_pool_relationship(
14871487
},
14881488
)
14891489
device = InfrahubNode(
1490-
client=client, schema=simple_device_schema, data={"name": "device-01", "primary_address": ip_pool}
1490+
client=client,
1491+
schema=simple_device_schema,
1492+
data={"name": "device-01", "primary_address": ip_pool, "ip_address_pool": ip_pool},
14911493
)
14921494
else:
14931495
ip_prefix = InfrahubNodeSync(client=client, schema=ipam_ipprefix_schema, data=ipam_ipprefix_data)
@@ -1504,13 +1506,16 @@ async def test_create_input_data_with_resource_pool_relationship(
15041506
},
15051507
)
15061508
device = InfrahubNode(
1507-
client=client, schema=simple_device_schema, data={"name": "device-01", "primary_address": ip_pool}
1509+
client=client,
1510+
schema=simple_device_schema,
1511+
data={"name": "device-01", "primary_address": ip_pool, "ip_address_pool": ip_pool},
15081512
)
15091513

15101514
assert device._generate_input_data()["data"] == {
15111515
"data": {
15121516
"name": {"value": "device-01"},
15131517
"primary_address": {"from_pool": {"id": "pppppppp-pppp-pppp-pppp-pppppppppppp"}},
1518+
"ip_address_pool": {"id": "pppppppp-pppp-pppp-pppp-pppppppppppp"},
15141519
},
15151520
}
15161521

@@ -1534,7 +1539,9 @@ async def test_create_mutation_query_with_resource_pool_relationship(
15341539
},
15351540
)
15361541
device = InfrahubNode(
1537-
client=client, schema=simple_device_schema, data={"name": "device-01", "primary_address": ip_pool}
1542+
client=client,
1543+
schema=simple_device_schema,
1544+
data={"name": "device-01", "primary_address": ip_pool, "ip_address_pool": ip_pool},
15381545
)
15391546
else:
15401547
ip_prefix = InfrahubNodeSync(client=client, schema=ipam_ipprefix_schema, data=ipam_ipprefix_data)
@@ -1551,11 +1558,17 @@ async def test_create_mutation_query_with_resource_pool_relationship(
15511558
},
15521559
)
15531560
device = InfrahubNode(
1554-
client=client, schema=simple_device_schema, data={"name": "device-01", "primary_address": ip_pool}
1561+
client=client,
1562+
schema=simple_device_schema,
1563+
data={"name": "device-01", "primary_address": ip_pool, "ip_address_pool": ip_pool},
15551564
)
15561565

15571566
assert device._generate_mutation_query() == {
1558-
"object": {"id": None, "primary_address": {"node": {"__typename": None, "display_label": None, "id": None}}},
1567+
"object": {
1568+
"id": None,
1569+
"primary_address": {"node": {"__typename": None, "display_label": None, "id": None}},
1570+
"ip_address_pool": {"node": {"__typename": None, "display_label": None, "id": None}},
1571+
},
15591572
"ok": None,
15601573
}
15611574

0 commit comments

Comments
 (0)