Skip to content

Commit 645c7e6

Browse files
committed
fix test include
1 parent 1cadd6f commit 645c7e6

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

infrahub_sdk/client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,9 @@ async def _process_nodes_and_relationships(
558558
- 'related_nodes': A list of InfrahubNode objects representing the related nodes
559559
"""
560560

561+
# Ideally, include and relationships wouldn't be parameters of this method, they should only
562+
# be used to build the request for the server, and this method would build node according to the response.
563+
561564
nodes: list[InfrahubNode] = []
562565
related_nodes: list[InfrahubNode] = []
563566

@@ -571,7 +574,6 @@ async def _process_nodes_and_relationships(
571574
branch=branch,
572575
related_nodes=related_nodes,
573576
timeout=timeout,
574-
include=include,
575577
)
576578

577579
return ProcessRelationsNode(nodes=nodes, related_nodes=related_nodes)
@@ -1837,6 +1839,7 @@ def _process_nodes_and_relationships(
18371839
schema_kind: str,
18381840
branch: str,
18391841
prefetch_relationships: bool,
1842+
include: list[str] | None,
18401843
timeout: int | None = None,
18411844
) -> ProcessRelationsNodeSync:
18421845
"""Processes InfrahubNodeSync and their Relationships from the GraphQL query response.
@@ -1861,7 +1864,7 @@ def _process_nodes_and_relationships(
18611864
node = InfrahubNodeSync.from_graphql(client=self, branch=branch, data=item, timeout=timeout)
18621865
nodes.append(node)
18631866

1864-
if prefetch_relationships:
1867+
if prefetch_relationships or include is not None:
18651868
node._process_relationships(node_data=item, branch=branch, related_nodes=related_nodes, timeout=timeout)
18661869

18671870
return ProcessRelationsNodeSync(nodes=nodes, related_nodes=related_nodes)
@@ -1986,6 +1989,7 @@ def process_page(page_offset: int, page_number: int) -> tuple[dict, ProcessRelat
19861989
branch=branch,
19871990
prefetch_relationships=prefetch_relationships,
19881991
timeout=timeout,
1992+
include=include,
19891993
)
19901994
return response, process_result
19911995

infrahub_sdk/node/node.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,6 @@ async def _process_relationships(
890890
branch: str,
891891
related_nodes: list[InfrahubNode],
892892
timeout: int | None = None,
893-
include: list[str] | None = None,
894893
) -> None:
895894
"""Processes the Relationships of a InfrahubNode and add Related Nodes to a list.
896895
@@ -901,8 +900,6 @@ async def _process_relationships(
901900
timeout (int, optional): Overrides default timeout used when querying the graphql API. Specified in seconds.
902901
"""
903902
for rel_name in self._relationships:
904-
if include is not None and rel_name not in include:
905-
continue
906903
rel = getattr(self, rel_name)
907904
if rel and isinstance(rel, RelatedNode):
908905
relation = node_data["node"].get(rel_name, None)
@@ -1369,7 +1366,8 @@ def generate_query_data_node(
13691366
continue
13701367

13711368
peer_data: dict[str, Any] = {}
1372-
if rel_schema and prefetch_relationships:
1369+
should_fetch_relationship = prefetch_relationships or (include is not None and rel_name in include)
1370+
if rel_schema and should_fetch_relationship:
13731371
peer_schema = self._client.schema.get(kind=rel_schema.peer, branch=self._branch)
13741372
peer_node = InfrahubNodeSync(client=self._client, schema=peer_schema, branch=self._branch)
13751373
peer_data = peer_node.generate_query_data_node(include=include, exclude=exclude, property=property)

tests/unit/sdk/conftest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,3 +2641,21 @@ async def mock_query_tasks_05(httpx_mock: HTTPXMock) -> HTTPXMock:
26412641
is_reusable=True,
26422642
)
26432643
return httpx_mock
2644+
2645+
2646+
@pytest.fixture
2647+
async def set_builtin_tag_schema_cache(client) -> None:
2648+
# Set tag schema in cache to avoid needed to request the server.
2649+
builtin_tag_schema = {
2650+
"version": "1.0",
2651+
"nodes": [
2652+
{
2653+
"name": "Tag",
2654+
"namespace": "Builtin",
2655+
"default_filter": "name__value",
2656+
"display_label": "name__value",
2657+
"branch": "aware",
2658+
}
2659+
],
2660+
}
2661+
client.schema.set_cache(builtin_tag_schema)

tests/unit/sdk/test_node.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,9 @@ async def test_query_data_generic_fragment(clients, mock_schema_query_02, client
10551055

10561056

10571057
@pytest.mark.parametrize("client_type", client_types)
1058-
async def test_query_data_include_property(client, location_schema: NodeSchemaAPI, client_type) -> None:
1058+
async def test_query_data_include_property(
1059+
client, location_schema: NodeSchemaAPI, client_type, set_builtin_tag_schema_cache
1060+
) -> None:
10591061
if client_type == "standard":
10601062
node = InfrahubNode(client=client, schema=location_schema)
10611063
data = await node.generate_query_data(include=["tags"], property=True)
@@ -1178,7 +1180,9 @@ async def test_query_data_include_property(client, location_schema: NodeSchemaAP
11781180

11791181

11801182
@pytest.mark.parametrize("client_type", client_types)
1181-
async def test_query_data_include(client, location_schema: NodeSchemaAPI, client_type) -> None:
1183+
async def test_query_data_include(
1184+
client, location_schema: NodeSchemaAPI, client_type, set_builtin_tag_schema_cache
1185+
) -> None:
11821186
if client_type == "standard":
11831187
node = InfrahubNode(client=client, schema=location_schema)
11841188
data = await node.generate_query_data(include=["tags"])

0 commit comments

Comments
 (0)