Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions infrahub_sdk/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
if node_data:
self._id = node_data.get("id", None)
self._hfid = node_data.get("hfid", None)
self._kind = node_data.get("kind", None)
self._display_label = node_data.get("display_label", None)
self._typename = node_data.get("__typename", None)

Expand Down Expand Up @@ -255,6 +256,8 @@
data["id"] = self.id
elif self.hfid is not None:
data["hfid"] = self.hfid
if self._kind is not None:
data["kind"] = self._kind

Check warning on line 260 in infrahub_sdk/node.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/node.py#L260

Added line #L260 was not covered by tests

for prop_name in self._properties:
if getattr(self, prop_name) is not None:
Expand Down
9 changes: 9 additions & 0 deletions infrahub_sdk/testing/schemas/animal.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def schema_cat(self) -> NodeSchema:
namespace=NAMESPACE,
include_in_menu=True,
inherit_from=[TESTING_ANIMAL],
human_friendly_id=["owner__name__value", "name__value", "color__value"],
display_labels=["name__value", "breed__value", "color__value"],
order_by=["name__value"],
attributes=[
Expand Down Expand Up @@ -108,6 +109,14 @@ def schema_person(self) -> NodeSchema:
identifier="person__animal",
cardinality="many",
direction=RelationshipDirection.INBOUND,
max_count=10,
),
Rel(
name="favorite_animal",
peer=TESTING_ANIMAL,
identifier="favorite_animal",
cardinality="one",
direction=RelationshipDirection.INBOUND,
),
Rel(
name="best_friends",
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/test_infrahub_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ async def test_count_with_filter(self, client: InfrahubClient, base_dataset):
count = await client.count(kind=TESTING_PERSON, name__values=["Liam Walker", "Ethan Carter"])
assert count == 2

async def test_create_generic_rel_with_hfid(
self, client: InfrahubClient, base_dataset, cat_luna, person_sophia, schema_animal, schema_cat
):
# See https://github.com/opsmill/infrahub-sdk-python/issues/277
assert (
schema_animal.human_friendly_id != schema_cat.human_friendly_id
), "Inherited node schema should have a different hfid than generic one for this test to be relevant"
person_sophia.favorite_animal = {"hfid": cat_luna.hfid, "kind": TESTING_CAT}
await person_sophia.save()
person_sophia = await client.get(kind=TESTING_PERSON, id=person_sophia.id, prefetch_relationships=True)
assert person_sophia.favorite_animal.id == cat_luna.id

# async def test_get_generic_filter_source(self, client: InfrahubClient, base_dataset):
# admin = await client.get(kind="CoreAccount", name__value="admin")

Expand Down