-
Notifications
You must be signed in to change notification settings - Fork 6
Add integration tests for metadata #861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: stable
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| from infrahub_sdk.constants import InfrahubClientMode | ||
| from infrahub_sdk.exceptions import BranchNotFoundError, URLNotFoundError | ||
| from infrahub_sdk.node import InfrahubNodeSync | ||
| from infrahub_sdk.node.metadata import NodeMetadata, RelationshipMetadata | ||
| from infrahub_sdk.playback import JSONPlayback | ||
| from infrahub_sdk.recorder import JSONRecorder | ||
| from infrahub_sdk.schema import GenericSchema, NodeSchema, ProfileSchemaAPI | ||
|
|
@@ -330,6 +331,81 @@ def create_person_with_tags(clt: InfrahubClientSync, nbr_tags: int) -> None: | |
| ) | ||
| assert len(group.members.peers) == 2 | ||
|
|
||
| def test_node_metadata_not_fetched_by_default( | ||
| self, client_sync: InfrahubClientSync, base_dataset: None, cat_luna: InfrahubNode | ||
| ) -> None: | ||
| node = client_sync.get(kind=TESTING_CAT, id=cat_luna.id) | ||
| assert node.get_node_metadata() is None | ||
|
|
||
| def test_node_metadata_with_get( | ||
| self, client_sync: InfrahubClientSync, base_dataset: None, cat_luna: InfrahubNode | ||
| ) -> None: | ||
| node = client_sync.get(kind=TESTING_CAT, id=cat_luna.id, include_metadata=True) | ||
|
|
||
| metadata = node.get_node_metadata() | ||
| assert isinstance(metadata, NodeMetadata) | ||
| assert metadata.created_at is not None | ||
| assert metadata.updated_at is not None | ||
| assert metadata.created_by.display_label == "Admin" | ||
|
|
||
| def test_attribute_metadata( | ||
| self, client_sync: InfrahubClientSync, base_dataset: None, person_ethan: InfrahubNode | ||
| ) -> None: | ||
| disposable = client_sync.create( | ||
| kind=TESTING_CAT, name="MetadataTestCat", breed="Siamese", color="#FFFFFF", owner=person_ethan | ||
| ) | ||
| disposable.save() | ||
|
|
||
| node = client_sync.get(kind=TESTING_CAT, id=disposable.id, include_metadata=True) | ||
|
|
||
| assert node.name.updated_by.display_label == "Admin" | ||
| assert node.breed.updated_by.display_label == "Admin" | ||
| original_name_updated_at = node.name.updated_at | ||
| original_breed_updated_at = node.breed.updated_at | ||
| assert original_name_updated_at is not None | ||
|
|
||
| node.name.value = "MetadataTestCat Updated" | ||
| node.save() | ||
|
|
||
| node_after = client_sync.get(kind=TESTING_CAT, id=disposable.id, include_metadata=True) | ||
| assert node_after.name.value == "MetadataTestCat Updated" | ||
| assert node_after.name.updated_by.display_label == "Admin" | ||
| assert node_after.name.updated_at is not None | ||
| assert node_after.name.updated_at > original_name_updated_at | ||
| assert node_after.breed.updated_at == original_breed_updated_at | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+363
to
+375
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The strict This update happens immediately after creation, so both values can land in the same timestamp bucket on fast containers. Consider polling until the timestamp changes, or assert on a non-time-based signal instead. 🤖 Prompt for AI Agents |
||
|
|
||
| node_after.delete() | ||
|
|
||
| def test_relationship_metadata_cardinality_one( | ||
| self, client_sync: InfrahubClientSync, base_dataset: None, cat_luna: InfrahubNode | ||
| ) -> None: | ||
| node = client_sync.get(kind=TESTING_CAT, id=cat_luna.id, include_metadata=True) | ||
|
|
||
| rel_metadata = node.owner.get_relationship_metadata() | ||
| assert isinstance(rel_metadata, RelationshipMetadata) | ||
| assert rel_metadata.updated_at is not None | ||
| assert rel_metadata.updated_by.display_label == "Admin" | ||
|
|
||
| def test_relationship_metadata_cardinality_many( | ||
| self, client_sync: InfrahubClientSync, base_dataset: None, person_ethan: InfrahubNode | ||
| ) -> None: | ||
| # Use include=["animals"] rather than prefetch_relationships=True — see async counterpart | ||
| # in test_infrahub_client.py for full explanation. | ||
| node = client_sync.get( | ||
| kind=TESTING_PERSON, | ||
| id=person_ethan.id, | ||
| include_metadata=True, | ||
| include=["animals"], | ||
| exclude=["favorite_animal"], | ||
| ) | ||
|
|
||
| assert node.animals.peers | ||
| for peer in node.animals.peers: | ||
| rel_metadata = peer.get_relationship_metadata() | ||
| assert isinstance(rel_metadata, RelationshipMetadata) | ||
| assert rel_metadata.updated_at is not None | ||
| assert rel_metadata.updated_by.display_label == "Admin" | ||
|
|
||
| @pytest.mark.xfail(reason="https://github.com/opsmill/infrahub-sdk-python/issues/733") | ||
| def test_recorder_with_playback_rewrite_host(self, base_dataset: None, tmp_path: Path, infrahub_port: int) -> None: | ||
| # Create a fresh client for recording to ensure clean state (no cached schema) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The immediate
updated_atordering assertion is prone to flakiness.A create and update performed back-to-back can legitimately share the same timestamp resolution in the containerized test environment. Poll until the timestamp changes, or avoid asserting strict monotonicity here.
🤖 Prompt for AI Agents