diff --git a/CHANGELOG.md b/CHANGELOG.md index ba084647..50e85f26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,22 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang +## [1.12.2](https://github.com/opsmill/infrahub-sdk-python/tree/v1.12.2) - 2025-06-05 + +### Fixed + +- fix bug in Timestamp.add by @ajtmccarty in [#403](https://github.com/opsmill/infrahub-sdk-python/pull/403) +- utils.py: improve file not found exception message by @granoe668 in [#425](https://github.com/opsmill/infrahub-sdk-python/pull/425) + +### Changed + +- Add partial_match to the client.count() by @BeArchiTek in [#411](https://github.com/opsmill/infrahub-sdk-python/pull/411) + +### Housekeeping + +- Loosen pinned requirement for `whenever` to allow versions from 0.7.2 up to but not including 0.8.0. +- Bump http-proxy-middleware from 2.0.7 to 2.0.9 in /docs by @dependabot in [#418](https://github.com/opsmill/infrahub-sdk-python/pull/418) + ## [1.12.1](https://github.com/opsmill/infrahub-sdk-python/tree/v1.12.1) - 2025-05-12 ### Changed diff --git a/changelog/+26b92d23.housekeeping.md b/changelog/+26b92d23.housekeeping.md deleted file mode 100644 index 6a49d751..00000000 --- a/changelog/+26b92d23.housekeeping.md +++ /dev/null @@ -1 +0,0 @@ -Loosen pinned requirement for `whenever` to allow versions from 0.7.2 up to but not including 0.8.0. diff --git a/infrahub_sdk/pytest_plugin/items/python_transform.py b/infrahub_sdk/pytest_plugin/items/python_transform.py index a030f8a1..02977f48 100644 --- a/infrahub_sdk/pytest_plugin/items/python_transform.py +++ b/infrahub_sdk/pytest_plugin/items/python_transform.py @@ -7,6 +7,7 @@ import ujson from httpx import HTTPStatusError +from ...node import InfrahubNode from ..exceptions import OutputMatchError, PythonTransformDefinitionError from ..models import InfrahubTestExpectedResult from .base import InfrahubItem @@ -41,7 +42,7 @@ def instantiate_transform(self) -> None: ) client = self.session.infrahub_client # type: ignore[attr-defined] # TODO: Look into seeing how a transform class may use the branch, but set as a empty string for the time being to keep current behaviour - self.transform_instance = transform_class(branch="", client=client) + self.transform_instance = transform_class(branch="", client=client, infrahub_node=InfrahubNode) def run_transform(self, variables: dict[str, Any]) -> Any: self.instantiate_transform() diff --git a/poetry.lock b/poetry.lock index 25585102..a1b4c065 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2394,4 +2394,4 @@ tests = ["Jinja2", "pytest", "pyyaml", "rich"] [metadata] lock-version = "2.1" python-versions = "^3.9, <3.14" -content-hash = "8fb3db8c3b2045247ef681d483005c7f3d19579fb9f982d9595a3ec7b94f8b24" +content-hash = "978a8ed3c6f4f4e46d39b8c33affb767a91275ee2bee532a48a7abc3d224deb8" diff --git a/pyproject.toml b/pyproject.toml index 73541708..d347fee5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "infrahub-sdk" -version = "1.12.1" +version = "1.12.2" description = "Python Client to interact with Infrahub" authors = ["OpsMill "] readme = "README.md" @@ -35,7 +35,7 @@ numpy = [ { version = "^1.26.2", optional = true, python = ">=3.12" }, ] pyarrow = { version = ">=14", optional = true } -rich = { version = "^13", optional = true } +rich = { version = ">=12, <14", optional = true } toml = { version = "^0.10", optional = true } typer = { version = "^0.12.3", optional = true } pytest = { version = "*", optional = true } diff --git a/tests/unit/pytest_plugin/test_plugin.py b/tests/unit/pytest_plugin/test_plugin.py index 5d336820..8d4b7b70 100644 --- a/tests/unit/pytest_plugin/test_plugin.py +++ b/tests/unit/pytest_plugin/test_plugin.py @@ -231,3 +231,61 @@ def test_jinja2_transform_unexpected_output(pytester): result = pytester.runpytest("--infrahub-repo-config=infrahub_config.yml") result.assert_outcomes(failed=1) + + +def test_python_transform(pytester): + pytester.makefile( + ".yml", + test_python_transform=""" + --- + version: "1.0" + infrahub_tests: + - resource: "PythonTransform" + resource_name: "device_config" + tests: + - name: "base_config" + expect: PASS + spec: + kind: "python-transform-unit-process" + directory: device_config/base_config + """, + ) + pytester.makefile( + ".yml", + infrahub_config=""" + --- + schemas: + - schemas/dcim.yml + + python_transforms: + - name: device_config + class_name: "DeviceConfig" + file_path: "transforms/device_config.py" + """, + ) + test_input = pytester.makefile( + ".json", input='{"data": { "InfraDevice": { "edges": [ { "node": { "name": {"value": "atl1-edge1"} } } ] } } }' + ) + test_output = pytester.makefile(".json", output='{"hostname": "atl1-edge1"}') + test_template = pytester.makefile( + ".py", + device_config=""" + from infrahub_sdk.transforms import InfrahubTransform + + class DeviceConfig(InfrahubTransform): + query = "device_config" + async def transform(self, data): + return {"hostname": data["InfraDevice"]["edges"][0]["node"]["name"]["value"]} + """, + ) + + pytester.mkdir("device_config") + test_dir = pytester.mkdir("device_config/base_config") + pytester.run("mv", test_input, test_dir) + pytester.run("mv", test_output, test_dir) + + transform_dir = pytester.mkdir("transforms") + pytester.run("mv", test_template, transform_dir) + + result = pytester.runpytest("--infrahub-repo-config=infrahub_config.yml") + result.assert_outcomes(passed=1)