Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/624.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed nested object template range expansion.
3 changes: 2 additions & 1 deletion infrahub_sdk/spec/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ async def process(self, client: InfrahubClient, branch: str | None = None) -> No
position=[idx + 1],
branch=branch,
default_schema_kind=self.kind,
parameters=self.parameters,
)

@classmethod
Expand Down Expand Up @@ -509,7 +510,7 @@ async def create_node(
context=context,
branch=branch,
default_schema_kind=default_schema_kind,
parameters=parameters,
parameters=InfrahubObjectParameters(**data[rel].get("parameters")),
)

return node
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/sdk/spec/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ def location_expansion_multiple_ranges_bad_syntax(root_location: dict) -> dict:
return location


@pytest.fixture
def location_with_non_dict_parameters(root_location: dict) -> dict:
data = [{"name": "Mexico", "type": "Country"}]
location = root_location.copy()
location["spec"]["data"] = data
location["spec"]["parameters"] = "not_a_dict"
return location


@pytest.fixture
def location_with_empty_parameters(root_location: dict) -> dict:
data = [{"name": "Mexico", "type": "Country"}]
location = root_location.copy()
location["spec"]["data"] = data
location["spec"]["parameters"] = {}
return location


async def test_validate_object(client: InfrahubClient, schema_query_01_data: dict, location_mexico_01) -> None:
client.schema.set_cache(schema=schema_query_01_data, branch="main")
obj = ObjectFile(location="some/path", content=location_mexico_01)
Expand Down Expand Up @@ -221,3 +239,27 @@ async def test_get_relationship_info_tags(
rel_info = await get_relationship_info(client_with_schema_01, location_schema, "tags", data)
assert rel_info.is_valid == is_valid
assert rel_info.format == format


async def test_parameters_top_level(client_with_schema_01: InfrahubClient, location_expansion) -> None:
obj = ObjectFile(location="some/path", content=location_expansion)
await obj.validate_format(client=client_with_schema_01)
assert obj.spec.parameters.expand_range is True


async def test_parameters_missing(client_with_schema_01: InfrahubClient, location_mexico_01) -> None:
obj = ObjectFile(location="some/path", content=location_mexico_01)
await obj.validate_format(client=client_with_schema_01)
assert hasattr(obj.spec.parameters, "expand_range")


async def test_parameters_empty_dict(client_with_schema_01: InfrahubClient, location_with_empty_parameters) -> None:
obj = ObjectFile(location="some/path", content=location_with_empty_parameters)
await obj.validate_format(client=client_with_schema_01)
assert hasattr(obj.spec.parameters, "expand_range")


async def test_parameters_non_dict(client_with_schema_01: InfrahubClient, location_with_non_dict_parameters) -> None:
obj = ObjectFile(location="some/path", content=location_with_non_dict_parameters)
with pytest.raises(ValidationError):
await obj.validate_format(client=client_with_schema_01)
Loading