Skip to content

Commit

Permalink
[CDF-21645] 👮Warning on a valid container with direct relation constr…
Browse files Browse the repository at this point in the history
…aint. (#592)

* tests: added failing test

* fix: no warning on vailid container
  • Loading branch information
doctrino authored Jun 3, 2024
1 parent 4f06e27 commit 2e3ea96
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.cdf-tk.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Changes are grouped as follows:
- Running the build command, `cdf-tk build`, with a `View` resource with a `hasData` filter would print a
`UnusedParameterWarning: Parameter 'externalId' is not used in section ('filter', 'hasData', 0, 'externalId').`.
This is incorrect and is now fixed to not print this warning.
- If you had a `container` with a direct relation property with a required constraint, the `cdf-tk build` command
would incorrectly yield a warning that the `Parameter 'type' is not used ...`. This is now fixed.

## [0.2.0b1] - 2024-05-20

Expand Down
7 changes: 7 additions & 0 deletions cognite_toolkit/_cdf_tk/loaders/_resource_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -2431,6 +2431,13 @@ def get_write_cls_parameter_spec(cls) -> ParameterSpecSet:
is_required=True,
_is_nullable=False,
),
ParameterSpec(
# direct relations with constraint
("properties", ANY_STR, "type", "container", "type"),
frozenset({"str"}),
is_required=True,
_is_nullable=False,
),
ParameterSpec(
("constraints", ANY_STR, "constraintType"),
frozenset({"str"}),
Expand Down
33 changes: 33 additions & 0 deletions tests/tests_unit/test_cdf_tk/test_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,39 @@ def test_upsert_data_set(self, cognite_client_approval: ApprovalCogniteClient):
assert len(unchanged) == 1


class TestContainerLoader:
@pytest.mark.parametrize(
"item",
[
pytest.param(
{
"properties": {
"myDirectRelation": {
"name": "my direct relation",
"type": {
"type": "direct",
"container": {
"type": "container",
"space": "sp_my_space",
"externalId": "my_container",
},
},
}
}
},
id="Direct relation property with require constraint.",
),
],
)
def test_valid_spec(self, item: dict):
spec = ContainerLoader.get_write_cls_parameter_spec()
dumped = read_parameters_from_dict(item)

extra = dumped - spec

assert not extra, f"Extra keys: {extra}"


class TestViewLoader:
@pytest.mark.parametrize(
"item",
Expand Down

0 comments on commit 2e3ea96

Please sign in to comment.