Skip to content

Add tests to archive and unarchive models, versions#329

Merged
dbasunag merged 10 commits intoopendatahub-io:mainfrom
dbasunag:archive_model
Jun 5, 2025
Merged

Add tests to archive and unarchive models, versions#329
dbasunag merged 10 commits intoopendatahub-io:mainfrom
dbasunag:archive_model

Conversation

@dbasunag
Copy link
Copy Markdown
Collaborator

@dbasunag dbasunag commented Jun 3, 2025

Description

How Has This Been Tested?

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

Summary by CodeRabbit

  • New Features

    • Introduced support for custom metadata properties in model registration, version, and artifact resources.
    • Added new tests to validate updates on model versions and registered models, including descriptions, states, and custom properties.
  • Bug Fixes

    • Improved validation logic in tests to ensure resource attributes match expected values.
  • Tests

    • Enhanced test coverage for model registry updates and custom property handling.
    • Centralized attribute validation in tests for better maintainability.
    • Refined test fixtures for dynamic resource update operations.
  • Chores

    • Added new exceptions to improve error reporting in tests.

@dbasunag dbasunag requested a review from a team as a code owner June 3, 2025 12:25
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2025

Walkthrough

The changes introduce centralized resource attribute validation for model registry REST API tests by adding a utility function and custom exceptions. Test fixtures and constants are updated to support custom properties and more dynamic update scenarios. New tests are added for model version and registered model updates, and validation logic is refactored for consistency.

Changes

File(s) Change Summary
tests/model_registry/rest_api/conftest.py Renamed fixture updated_model_artifact to updated_model_registry_resource, changed scope to function, and generalized it for dynamic resource updates using parameters.
tests/model_registry/rest_api/constants.py Updated type annotation for MODEL_REGISTER; added customProperties key with nested metadata dictionaries to MODEL_REGISTER, MODEL_VERSION, and MODEL_ARTIFACT.
tests/model_registry/rest_api/test_model_registry_rest_api.py Refactored validation using new utility; added constants including CUSTOM_PROPERTY; introduced parameterized tests for model version and registered model updates with structured inputs.
tests/model_registry/rest_api/utils.py Added validate_resource_attributes function for centralized attribute validation; imported new exception ResourceValueMismatch.
utilities/exceptions.py Added new exception classes ResourceValueMismatch and MissingParameter.

Sequence Diagram(s)

sequenceDiagram
    participant TestCase
    participant Fixture
    participant Utils
    participant Exception

    TestCase->>Fixture: Request updated resource (PATCH)
    Fixture->>Utils: Call validate_resource_attributes(expected, actual, name)
    Utils->>Utils: Compare expected vs actual attributes
    alt Mismatch found
        Utils->>Exception: Raise ResourceValueMismatch
    else All match
        Utils-->>TestCase: Validation succeeds
    end
Loading

Suggested labels

lgtm-by-lugi0, lgtm-by-dbasunag

Suggested reviewers

  • lugi0
  • fege

Poem

A rabbit hopped through fields of code,
With fixtures fresh and tests bestowed.
Now custom props and PATCH requests bloom,
Validation central, no more gloom!
If values mismatch, exceptions fly—
But when all aligns, the tests hop by.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2025

The following are automatically added/executed:

  • PR size label.
  • Run pre-commit
  • Run tox
  • Add PR author as the PR assignee
  • Build image based on the PR

Available user actions:

  • To mark a PR as WIP, add /wip in a comment. To remove it from the PR comment /wip cancel to the PR.
  • To block merging of a PR, add /hold in a comment. To un-block merging of PR comment /hold cancel.
  • To mark a PR as approved, add /lgtm in a comment. To remove, add /lgtm cancel.
    lgtm label removed on each new commit push.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To Cherry-pick a merged PR /cherry-pick <target_branch_name> to the PR. If <target_branch_name> is valid,
    and the current PR is merged, a cherry-picked PR would be created and linked to the current PR.
  • To build and push image to quay, add /build-push-pr-image in a comment. This would create an image with tag
    pr-<pr_number> to quay repository. This image tag, however would be deleted on PR merge or close action.
Supported labels

{'/hold', '/verified', '/lgtm', '/wip'}

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (5)
tests/model_registry/rest_api/utils.py (1)

94-104: Add docstring for better documentation.

The validation function is well-implemented with efficient use of walrus operator and list comprehension. However, it would benefit from a docstring to document its purpose and parameters.

 def validate_resource_attributes(
     expected_params: dict[str, Any], actual_resource_data: dict[str, Any], resource_name: str
 ) -> None:
+    """
+    Validate that actual resource data matches expected parameters.
+    
+    Args:
+        expected_params: Dictionary of expected parameter values
+        actual_resource_data: Dictionary of actual resource data to validate
+        resource_name: Name of the resource being validated (for logging)
+        
+    Raises:
+        ResourceValueMismatch: If any expected parameter doesn't match actual data
+    """
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 94-94: Missing function or method docstring

(C0116)

tests/model_registry/rest_api/conftest.py (2)

52-65: Consider adding docstring for consistency.

The updated_model_version fixture follows the established pattern well with proper ID extraction and assertion. Consider adding a docstring to document its purpose.

 @pytest.fixture()
 def updated_model_version(
     request: pytest.FixtureRequest,
     model_registry_rest_url: str,
     model_registry_rest_headers: dict[str, str],
     registered_model_rest_api: dict[str, Any],
 ) -> dict[str, Any]:
+    """Update a model version via PATCH request using test parameters."""
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 60-60: Line too long (104/100)

(C0301)


[convention] 53-53: Missing function or method docstring

(C0116)


[warning] 55-55: Redefining name 'model_registry_rest_url' from outer scope (line 11)

(W0621)


[warning] 56-56: Redefining name 'model_registry_rest_headers' from outer scope (line 17)

(W0621)


[warning] 57-57: Redefining name 'registered_model_rest_api' from outer scope (line 26)

(W0621)


68-81: Consider adding docstring for consistency.

The updated_registered_model fixture is well-implemented and consistent with the pattern. Consider adding a docstring to document its purpose.

 @pytest.fixture()
 def updated_registered_model(
     request: pytest.FixtureRequest,
     model_registry_rest_url: str,
     model_registry_rest_headers: dict[str, str],
     registered_model_rest_api: dict[str, Any],
 ) -> dict[str, Any]:
+    """Update a registered model via PATCH request using test parameters."""
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 69-69: Missing function or method docstring

(C0116)


[warning] 71-71: Redefining name 'model_registry_rest_url' from outer scope (line 11)

(W0621)


[warning] 72-72: Redefining name 'model_registry_rest_headers' from outer scope (line 17)

(W0621)


[warning] 73-73: Redefining name 'registered_model_rest_api' from outer scope (line 26)

(W0621)

tests/model_registry/rest_api/test_model_registry_rest_api.py (2)

6-6: Import addition looks good, but consider fixing import order.

The import of validate_resource_attributes is necessary for the refactoring and correctly used throughout the file.

However, consider addressing the import order issue flagged by pylint - third-party imports should come before first-party imports.


102-108: Good refactoring with improved documentation.

The updated test method uses the centralized validation utility and has a more descriptive docstring.

Consider wrapping the long line (line 107) to comply with the 100-character limit:

-        validate_resource_attributes(
-            expected_params=expected_param, actual_resource_data=updated_model_artifact, resource_name="model artifact"
-        )
+        validate_resource_attributes(
+            expected_params=expected_param,
+            actual_resource_data=updated_model_artifact,
+            resource_name="model artifact"
+        )
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 107-107: Line too long (119/100)

(C0301)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de11de9 and 73aeea7.

📒 Files selected for processing (5)
  • tests/model_registry/rest_api/conftest.py (2 hunks)
  • tests/model_registry/rest_api/constants.py (2 hunks)
  • tests/model_registry/rest_api/test_model_registry_rest_api.py (3 hunks)
  • tests/model_registry/rest_api/utils.py (2 hunks)
  • utilities/exceptions.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
tests/model_registry/rest_api/test_model_registry_rest_api.py (2)
tests/model_registry/rest_api/utils.py (1)
  • validate_resource_attributes (94-104)
tests/model_registry/rest_api/conftest.py (4)
  • registered_model_rest_api (26-33)
  • updated_model_artifact (37-49)
  • updated_model_version (53-65)
  • updated_registered_model (69-81)
tests/model_registry/rest_api/utils.py (1)
utilities/exceptions.py (1)
  • ResourceValueMismatch (125-128)
tests/model_registry/rest_api/conftest.py (1)
tests/model_registry/rest_api/utils.py (1)
  • execute_model_registry_patch_command (17-31)
🪛 Pylint (3.3.7)
utilities/exceptions.py

[warning] 128-128: Unnecessary pass statement

(W0107)

tests/model_registry/rest_api/test_model_registry_rest_api.py

[error] 8-8: Unable to import 'simple_logger.logger'

(E0401)


[convention] 8-8: third party import "simple_logger.logger.get_logger" should be placed before first party imports "tests.model_registry.rest_api.constants.MODEL_REGISTER", "tests.model_registry.rest_api.utils.validate_resource_attributes", "utilities.constants.DscComponents"

(C0411)


[convention] 107-107: Line too long (119/100)

(C0301)


[convention] 142-142: Line too long (117/100)

(C0301)


[convention] 146-146: Line too long (117/100)

(C0301)


[convention] 181-181: Line too long (116/100)

(C0301)

tests/model_registry/rest_api/utils.py

[error] 5-5: Unable to import 'simple_logger.logger'

(E0401)


[convention] 94-94: Missing function or method docstring

(C0116)

tests/model_registry/rest_api/conftest.py

[convention] 60-60: Line too long (104/100)

(C0301)


[convention] 53-53: Missing function or method docstring

(C0116)


[warning] 55-55: Redefining name 'model_registry_rest_url' from outer scope (line 11)

(W0621)


[warning] 56-56: Redefining name 'model_registry_rest_headers' from outer scope (line 17)

(W0621)


[warning] 57-57: Redefining name 'registered_model_rest_api' from outer scope (line 26)

(W0621)


[convention] 69-69: Missing function or method docstring

(C0116)


[warning] 71-71: Redefining name 'model_registry_rest_url' from outer scope (line 11)

(W0621)


[warning] 72-72: Redefining name 'model_registry_rest_headers' from outer scope (line 17)

(W0621)


[warning] 73-73: Redefining name 'registered_model_rest_api' from outer scope (line 26)

(W0621)

🔇 Additional comments (7)
utilities/exceptions.py (1)

125-128: LGTM! Exception class follows established patterns.

The new ResourceValueMismatch exception class is well-defined and follows the consistent pattern used by other exception classes in this file. The pass statement is necessary for the empty class body.

🧰 Tools
🪛 Pylint (3.3.7)

[warning] 128-128: Unnecessary pass statement

(W0107)

tests/model_registry/rest_api/constants.py (2)

5-5: Good type annotation update.

Changing the type annotation from dict[str, str] to dict[str, Any] is appropriate since the dictionary now contains nested structures in the customProperties fields.


9-12: Well-structured custom properties addition.

The custom properties are consistently structured across all three constants with appropriate metadata types (MetadataBoolValue and MetadataStringValue). This enhances the test coverage for custom property validation scenarios.

Also applies to: 19-22, 33-36

tests/model_registry/rest_api/utils.py (1)

12-12: Import addition looks good.

The import of ResourceValueMismatch is correctly placed and supports the new validation functionality.

tests/model_registry/rest_api/conftest.py (1)

36-36: Good scope change for more granular testing.

Changing the scope from "class" to function-level (default) allows for more isolated test execution, which is appropriate for update operations that might have side effects.

tests/model_registry/rest_api/test_model_registry_rest_api.py (2)

11-17: Well-structured test data for custom properties.

The CUSTOM_PROPERTY constant provides comprehensive coverage for different metadata types (bool, string, double) which is excellent for testing custom properties functionality.


70-74: Excellent refactoring to centralize validation logic.

The replacement of manual validation with the validate_resource_attributes utility function improves code maintainability and consistency across tests.

Comment thread tests/model_registry/rest_api/test_model_registry_rest_api.py
Comment thread tests/model_registry/rest_api/test_model_registry_rest_api.py
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
tests/model_registry/rest_api/utils.py (1)

94-104: Add docstring for better documentation.

The validation function logic is well-implemented and serves its purpose effectively. However, adding a docstring would improve maintainability and help other developers understand the function's purpose and parameters.

Add a docstring like this:

 def validate_resource_attributes(
     expected_params: dict[str, Any], actual_resource_data: dict[str, Any], resource_name: str
 ) -> None:
+    """
+    Validate that expected parameters match actual resource data.
+    
+    Args:
+        expected_params: Dictionary of expected key-value pairs
+        actual_resource_data: Dictionary of actual resource data to validate
+        resource_name: Name of the resource for logging and error messages
+        
+    Raises:
+        ResourceValueMismatch: If any expected values don't match actual values
+    """
     errors: list[dict[str, list[Any]]]
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 94-94: Missing function or method docstring

(C0116)

tests/model_registry/rest_api/conftest.py (2)

52-65: Add docstring and fix line length.

The fixture implementation is correct and follows the established pattern. However, it needs a docstring and has a line length issue.

Apply this diff to add documentation and fix formatting:

 @pytest.fixture()
 def updated_model_version(
     request: pytest.FixtureRequest,
     model_registry_rest_url: str,
     model_registry_rest_headers: dict[str, str],
     registered_model_rest_api: dict[str, Any],
 ) -> dict[str, Any]:
+    """Update a model version using PATCH request with provided parameters."""
     model_version_id = registered_model_rest_api["model_version"]["id"]
-    assert model_version_id, f"Model version id not found: {registered_model_rest_api['model_version']}"
+    assert model_version_id, (
+        f"Model version id not found: {registered_model_rest_api['model_version']}"
+    )
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 60-60: Line too long (104/100)

(C0301)


[convention] 53-53: Missing function or method docstring

(C0116)


[warning] 55-55: Redefining name 'model_registry_rest_url' from outer scope (line 11)

(W0621)


[warning] 56-56: Redefining name 'model_registry_rest_headers' from outer scope (line 17)

(W0621)


[warning] 57-57: Redefining name 'registered_model_rest_api' from outer scope (line 26)

(W0621)


68-81: Add docstring for consistency.

The fixture implementation is correct but should include a docstring for consistency with other fixtures.

Add a docstring:

 @pytest.fixture()
 def updated_registered_model(
     request: pytest.FixtureRequest,
     model_registry_rest_url: str,
     model_registry_rest_headers: dict[str, str],
     registered_model_rest_api: dict[str, Any],
 ) -> dict[str, Any]:
+    """Update a registered model using PATCH request with provided parameters."""
     model_id = registered_model_rest_api["register_model"]["id"]
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 69-69: Missing function or method docstring

(C0116)


[warning] 71-71: Redefining name 'model_registry_rest_url' from outer scope (line 11)

(W0621)


[warning] 72-72: Redefining name 'model_registry_rest_headers' from outer scope (line 17)

(W0621)


[warning] 73-73: Redefining name 'registered_model_rest_api' from outer scope (line 26)

(W0621)

tests/model_registry/rest_api/test_model_registry_rest_api.py (2)

102-108: Fix line length issue.

The refactoring and added docstring are good improvements, but there's a line length violation that should be addressed.

Apply this diff to fix the line length:

-        validate_resource_attributes(
-            expected_params=expected_param, actual_resource_data=updated_model_artifact, resource_name="model artifact"
-        )
+        validate_resource_attributes(
+            expected_params=expected_param,
+            actual_resource_data=updated_model_artifact,
+            resource_name="model artifact"
+        )
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 107-107: Line too long (119/100)

(C0301)


110-147: Excellent test coverage for archive/unarchive functionality! Fix line length.

This test method directly addresses the PR objective by testing model version updates including archive/unarchive functionality (ARCHIVED/LIVE states). The test coverage is comprehensive with description updates, state changes, and custom properties.

Fix the line length issue on line 146:

-        validate_resource_attributes(
-            expected_params=expected_param, actual_resource_data=updated_model_version, resource_name="model version"
-        )
+        validate_resource_attributes(
+            expected_params=expected_param,
+            actual_resource_data=updated_model_version,
+            resource_name="model version"
+        )
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 146-146: Line too long (117/100)

(C0301)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 73aeea7 and 2b22f75.

📒 Files selected for processing (5)
  • tests/model_registry/rest_api/conftest.py (2 hunks)
  • tests/model_registry/rest_api/constants.py (2 hunks)
  • tests/model_registry/rest_api/test_model_registry_rest_api.py (3 hunks)
  • tests/model_registry/rest_api/utils.py (2 hunks)
  • utilities/exceptions.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/model_registry/rest_api/constants.py
🧰 Additional context used
🧬 Code Graph Analysis (3)
tests/model_registry/rest_api/conftest.py (1)
tests/model_registry/rest_api/utils.py (1)
  • execute_model_registry_patch_command (17-31)
tests/model_registry/rest_api/test_model_registry_rest_api.py (2)
tests/model_registry/rest_api/utils.py (1)
  • validate_resource_attributes (94-104)
tests/model_registry/rest_api/conftest.py (4)
  • registered_model_rest_api (26-33)
  • updated_model_artifact (37-49)
  • updated_model_version (53-65)
  • updated_registered_model (69-81)
tests/model_registry/rest_api/utils.py (1)
utilities/exceptions.py (1)
  • ResourceValueMismatch (125-128)
🪛 Pylint (3.3.7)
tests/model_registry/rest_api/conftest.py

[convention] 60-60: Line too long (104/100)

(C0301)


[convention] 53-53: Missing function or method docstring

(C0116)


[warning] 55-55: Redefining name 'model_registry_rest_url' from outer scope (line 11)

(W0621)


[warning] 56-56: Redefining name 'model_registry_rest_headers' from outer scope (line 17)

(W0621)


[warning] 57-57: Redefining name 'registered_model_rest_api' from outer scope (line 26)

(W0621)


[convention] 69-69: Missing function or method docstring

(C0116)


[warning] 71-71: Redefining name 'model_registry_rest_url' from outer scope (line 11)

(W0621)


[warning] 72-72: Redefining name 'model_registry_rest_headers' from outer scope (line 17)

(W0621)


[warning] 73-73: Redefining name 'registered_model_rest_api' from outer scope (line 26)

(W0621)

tests/model_registry/rest_api/test_model_registry_rest_api.py

[error] 8-8: Unable to import 'simple_logger.logger'

(E0401)


[convention] 8-8: third party import "simple_logger.logger.get_logger" should be placed before first party imports "tests.model_registry.rest_api.constants.MODEL_REGISTER", "tests.model_registry.rest_api.utils.validate_resource_attributes", "utilities.constants.DscComponents"

(C0411)


[convention] 107-107: Line too long (119/100)

(C0301)


[convention] 146-146: Line too long (117/100)

(C0301)

tests/model_registry/rest_api/utils.py

[error] 5-5: Unable to import 'simple_logger.logger'

(E0401)


[convention] 94-94: Missing function or method docstring

(C0116)

utilities/exceptions.py

[warning] 128-128: Unnecessary pass statement

(W0107)

🔇 Additional comments (5)
utilities/exceptions.py (1)

125-128: LGTM! Well-defined exception class.

The new ResourceValueMismatch exception follows the established pattern in this file and serves its purpose well for the validation utility. The pass statement is appropriate here as no additional behavior is needed beyond the base Exception class.

🧰 Tools
🪛 Pylint (3.3.7)

[warning] 128-128: Unnecessary pass statement

(W0107)

tests/model_registry/rest_api/conftest.py (1)

36-36: Good scope change for more granular testing.

Changing from class scope to function scope allows for more isolated testing and is appropriate for update operations that may modify state.

tests/model_registry/rest_api/test_model_registry_rest_api.py (3)

11-17: Well-structured custom property constant.

The CUSTOM_PROPERTY constant is well-defined and provides good test coverage for different metadata types including boolean, string, and double values.


70-74: Excellent refactoring to use centralized validation.

The refactoring to use the validate_resource_attributes utility function improves code consistency and maintainability across the test suite.


149-188: Great coverage for registered model archive/unarchive functionality.

This test method complements the model version tests and provides comprehensive coverage for registered model updates including archive/unarchive functionality, which aligns perfectly with the PR objectives.

Copy link
Copy Markdown
Contributor

@lugi0 lugi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple comments but won't hold the PR for it

Comment thread tests/model_registry/rest_api/test_model_registry_rest_api.py Outdated
Comment thread tests/model_registry/rest_api/test_model_registry_rest_api.py Outdated
Comment thread tests/model_registry/rest_api/utils.py
Comment thread tests/model_registry/rest_api/conftest.py Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
tests/model_registry/rest_api/test_model_registry_rest_api.py (2)

124-167: Excellent coverage for model version archive/unarchive functionality.

This test method directly addresses the PR objective by providing comprehensive coverage for model version updates, including the critical archive/unarchive functionality (ARCHIVED/LIVE states) mentioned in RHOAIENG-24371. The test also covers custom properties validation.

Fix line length violations for better readability:

             pytest.param(
-                {"resource_name": "model_version", "api_name": "model_versions", "data": {"state": "ARCHIVED"}},
+                {
+                    "resource_name": "model_version",
+                    "api_name": "model_versions", 
+                    "data": {"state": "ARCHIVED"}
+                },
                 {"state": "ARCHIVED"},
                 id="test_validate_updated_version_state_archived",
             ),
             pytest.param(
-                {"resource_name": "model_version", "api_name": "model_versions", "data": {"state": "LIVE"}},
+                {
+                    "resource_name": "model_version",
+                    "api_name": "model_versions", 
+                    "data": {"state": "LIVE"}
+                },
                 {"state": "LIVE"},
                 id="test_validate_updated_version_state_unarchived",
             ),
             pytest.param(
-                {"resource_name": "model_version", "api_name": "model_versions", "data": CUSTOM_PROPERTY},
+                {
+                    "resource_name": "model_version",
+                    "api_name": "model_versions", 
+                    "data": CUSTOM_PROPERTY
+                },
                 CUSTOM_PROPERTY,
                 id="test_validate_updated_version_custom_properties",
             ),
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 137-137: Line too long (112/100)

(C0301)


[convention] 142-142: Line too long (108/100)

(C0301)


[convention] 147-147: Line too long (106/100)

(C0301)


169-212: Comprehensive registered model testing with good coverage.

This test method provides excellent coverage for registered model updates including archive/unarchive functionality, complementing the model version tests. The testing approach is consistent and thorough.

Fix line length violations for better readability:

             pytest.param(
-                {"resource_name": "register_model", "api_name": "registered_models", "data": {"state": "ARCHIVED"}},
+                {
+                    "resource_name": "register_model",
+                    "api_name": "registered_models", 
+                    "data": {"state": "ARCHIVED"}
+                },
                 {"state": "ARCHIVED"},
                 id="test_validate_updated_model_state_archived",
             ),
             pytest.param(
-                {"resource_name": "register_model", "api_name": "registered_models", "data": {"state": "LIVE"}},
+                {
+                    "resource_name": "register_model",
+                    "api_name": "registered_models", 
+                    "data": {"state": "LIVE"}
+                },
                 {"state": "LIVE"},
                 id="test_validate_updated_model_state_unarchived",
             ),
             pytest.param(
-                {"resource_name": "register_model", "api_name": "registered_models", "data": CUSTOM_PROPERTY},
+                {
+                    "resource_name": "register_model",
+                    "api_name": "registered_models", 
+                    "data": CUSTOM_PROPERTY
+                },
                 CUSTOM_PROPERTY,
                 id="test_validate_updated_registered_model_custom_properties",
             ),
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 182-182: Line too long (116/100)

(C0301)


[convention] 187-187: Line too long (112/100)

(C0301)


[convention] 192-192: Line too long (110/100)

(C0301)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b22f75 and f2bf0d1.

📒 Files selected for processing (5)
  • tests/model_registry/rest_api/conftest.py (2 hunks)
  • tests/model_registry/rest_api/constants.py (2 hunks)
  • tests/model_registry/rest_api/test_model_registry_rest_api.py (2 hunks)
  • tests/model_registry/rest_api/utils.py (2 hunks)
  • utilities/exceptions.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/model_registry/rest_api/constants.py
🧰 Additional context used
🧬 Code Graph Analysis (3)
tests/model_registry/rest_api/conftest.py (2)
utilities/exceptions.py (1)
  • MissingParameter (131-134)
tests/model_registry/rest_api/utils.py (1)
  • execute_model_registry_patch_command (17-31)
tests/model_registry/rest_api/test_model_registry_rest_api.py (3)
tests/model_registry/rest_api/utils.py (1)
  • validate_resource_attributes (94-104)
utilities/constants.py (1)
  • DscComponents (146-164)
tests/model_registry/rest_api/conftest.py (2)
  • registered_model_rest_api (27-34)
  • updated_model_registry_resource (38-54)
tests/model_registry/rest_api/utils.py (1)
utilities/exceptions.py (1)
  • ResourceValueMismatch (125-128)
🪛 Pylint (3.3.7)
tests/model_registry/rest_api/conftest.py

[convention] 47-47: Line too long (102/100)

(C0301)


[convention] 38-38: Missing function or method docstring

(C0116)


[warning] 40-40: Redefining name 'model_registry_rest_url' from outer scope (line 12)

(W0621)


[warning] 41-41: Redefining name 'model_registry_rest_headers' from outer scope (line 18)

(W0621)


[warning] 42-42: Redefining name 'registered_model_rest_api' from outer scope (line 27)

(W0621)

tests/model_registry/rest_api/test_model_registry_rest_api.py

[error] 8-8: Unable to import 'simple_logger.logger'

(E0401)


[convention] 8-8: third party import "simple_logger.logger.get_logger" should be placed before first party imports "tests.model_registry.rest_api.constants.MODEL_REGISTER", "tests.model_registry.rest_api.utils.validate_resource_attributes", "utilities.constants.DscComponents"

(C0411)


[convention] 137-137: Line too long (112/100)

(C0301)


[convention] 142-142: Line too long (108/100)

(C0301)


[convention] 147-147: Line too long (106/100)

(C0301)


[convention] 182-182: Line too long (116/100)

(C0301)


[convention] 187-187: Line too long (112/100)

(C0301)


[convention] 192-192: Line too long (110/100)

(C0301)

tests/model_registry/rest_api/utils.py

[error] 5-5: Unable to import 'simple_logger.logger'

(E0401)


[convention] 99-99: Line too long (105/100)

(C0301)


[convention] 94-94: Missing function or method docstring

(C0116)

utilities/exceptions.py

[warning] 128-128: Unnecessary pass statement

(W0107)


[warning] 134-134: Unnecessary pass statement

(W0107)

🔇 Additional comments (6)
utilities/exceptions.py (1)

125-134: Well-designed exception classes for validation framework.

The new exception classes ResourceValueMismatch and MissingParameter are well-named and serve clear purposes in the validation framework. They provide specific error types for resource validation mismatches and missing required parameters.

The pass statements are not strictly necessary but are commonly used for clarity in empty class bodies.

🧰 Tools
🪛 Pylint (3.3.7)

[warning] 128-128: Unnecessary pass statement

(W0107)


[warning] 134-134: Unnecessary pass statement

(W0107)

tests/model_registry/rest_api/utils.py (1)

12-12: Good addition of centralized validation utility.

The import of ResourceValueMismatch supports the new centralized validation approach, which is a good improvement for consistency across tests.

tests/model_registry/rest_api/conftest.py (1)

8-8: Good addition of MissingParameter exception import.

The import supports proper error handling in the generalized fixture for missing required parameters.

tests/model_registry/rest_api/test_model_registry_rest_api.py (3)

11-17: Good addition of structured custom property test data.

The CUSTOM_PROPERTY constant provides well-structured test data for validating custom metadata properties across different data types (bool, string, double). This supports comprehensive testing of the custom properties functionality.


70-74: Excellent refactoring to use centralized validation.

The replacement of manual validation logic with the validate_resource_attributes utility function improves consistency and maintainability across tests.


76-122: Good restructuring of model artifact tests.

The parameterization has been updated to use the new structured format with resource_name, api_name, and data fields, which aligns well with the generalized fixture. The validation approach is consistent and clean.

Comment thread tests/model_registry/rest_api/utils.py
Comment thread tests/model_registry/rest_api/conftest.py
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
tests/model_registry/rest_api/utils.py (1)

94-116: ⚠️ Potential issue

Fix falsy value handling in validation logic.

The validation function provides excellent centralization, but there's a potential bug in the condition on line 112:

if (not actual_resource_data.get(key) or actual_resource_data[key] != expected_params[key])

The not actual_resource_data.get(key) check will incorrectly trigger for legitimate falsy values like 0, False, or empty strings. This could cause false validation failures.

Apply this diff to fix the falsy value handling:

-        if (not actual_resource_data.get(key) or actual_resource_data[key] != expected_params[key])
+        if (key not in actual_resource_data or actual_resource_data[key] != expected_params[key])

Also fix the line length violation:

-        {key: [f"Expected value: {expected_params[key]}, actual value: {actual_resource_data.get(key)}"]}
+        {
+            key: [
+                f"Expected value: {expected_params[key]}, "
+                f"actual value: {actual_resource_data.get(key)}"
+            ]
+        }
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 110-110: Line too long (105/100)

(C0301)

🧹 Nitpick comments (3)
tests/model_registry/rest_api/conftest.py (1)

37-65: Excellent fixture generalization with minor formatting fix needed.

The transformation from updated_model_artifact to updated_model_registry_resource is a great improvement that enables testing updates across different model registry entities. The parameter validation and error handling are appropriate.

Fix the line length violation:

-        raise MissingParameter("resource_name and api_name are required parameters for this fixture.")
+        raise MissingParameter(
+            "resource_name and api_name are required parameters for this fixture."
+        )
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 58-58: Line too long (102/100)

(C0301)


[warning] 40-40: Redefining name 'model_registry_rest_url' from outer scope (line 12)

(W0621)


[warning] 41-41: Redefining name 'model_registry_rest_headers' from outer scope (line 18)

(W0621)


[warning] 42-42: Redefining name 'registered_model_rest_api' from outer scope (line 27)

(W0621)

tests/model_registry/rest_api/test_model_registry_rest_api.py (2)

131-174: Excellent coverage for model version archive/unarchive functionality.

This test method directly addresses the PR objective by comprehensively testing model version updates including archive/unarchive functionality (ARCHIVED/LIVE states). The test coverage is thorough and well-structured.

Fix the line length violations for better code style compliance:

-            pytest.param(
-                {"resource_name": "model_version", "api_name": "model_versions", "data": STATE_ARCHIVED},
-                STATE_ARCHIVED,
-                id="test_validate_updated_version_state_archived",
-            ),
+            pytest.param(
+                {
+                    "resource_name": "model_version",
+                    "api_name": "model_versions", 
+                    "data": STATE_ARCHIVED
+                },
+                STATE_ARCHIVED,
+                id="test_validate_updated_version_state_archived",
+            ),

Apply similar formatting to other long lines (149, 154).

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 144-144: Line too long (105/100)

(C0301)


[convention] 149-149: Line too long (101/100)

(C0301)


[convention] 154-154: Line too long (106/100)

(C0301)


176-219: Comprehensive registered model archive/unarchive testing.

This test method provides excellent coverage for registered model updates including archive/unarchive functionality, perfectly complementing the model version tests and fulfilling the PR objectives.

Fix the line length violations for consistency:

-            pytest.param(
-                {"resource_name": "register_model", "api_name": "registered_models", "data": STATE_ARCHIVED},
-                STATE_ARCHIVED,
-                id="test_validate_updated_model_state_archived",
-            ),
+            pytest.param(
+                {
+                    "resource_name": "register_model",
+                    "api_name": "registered_models",
+                    "data": STATE_ARCHIVED
+                },
+                STATE_ARCHIVED,
+                id="test_validate_updated_model_state_archived",
+            ),

Apply similar formatting to lines 194 and 199.

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 189-189: Line too long (109/100)

(C0301)


[convention] 194-194: Line too long (105/100)

(C0301)


[convention] 199-199: Line too long (110/100)

(C0301)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f2bf0d1 and b4e930b.

📒 Files selected for processing (5)
  • tests/model_registry/rest_api/conftest.py (2 hunks)
  • tests/model_registry/rest_api/constants.py (2 hunks)
  • tests/model_registry/rest_api/test_model_registry_rest_api.py (2 hunks)
  • tests/model_registry/rest_api/utils.py (2 hunks)
  • utilities/exceptions.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/model_registry/rest_api/constants.py
🧰 Additional context used
🧬 Code Graph Analysis (2)
tests/model_registry/rest_api/conftest.py (2)
utilities/exceptions.py (1)
  • MissingParameter (131-134)
tests/model_registry/rest_api/utils.py (1)
  • execute_model_registry_patch_command (17-31)
tests/model_registry/rest_api/utils.py (1)
utilities/exceptions.py (1)
  • ResourceValueMismatch (125-128)
🪛 Pylint (3.3.7)
tests/model_registry/rest_api/test_model_registry_rest_api.py

[error] 8-8: Unable to import 'simple_logger.logger'

(E0401)


[convention] 8-8: third party import "simple_logger.logger.get_logger" should be placed before first party imports "tests.model_registry.rest_api.constants.MODEL_REGISTER", "tests.model_registry.rest_api.utils.validate_resource_attributes", "utilities.constants.DscComponents"

(C0411)


[convention] 144-144: Line too long (105/100)

(C0301)


[convention] 149-149: Line too long (101/100)

(C0301)


[convention] 154-154: Line too long (106/100)

(C0301)


[convention] 189-189: Line too long (109/100)

(C0301)


[convention] 194-194: Line too long (105/100)

(C0301)


[convention] 199-199: Line too long (110/100)

(C0301)

tests/model_registry/rest_api/conftest.py

[convention] 58-58: Line too long (102/100)

(C0301)


[warning] 40-40: Redefining name 'model_registry_rest_url' from outer scope (line 12)

(W0621)


[warning] 41-41: Redefining name 'model_registry_rest_headers' from outer scope (line 18)

(W0621)


[warning] 42-42: Redefining name 'registered_model_rest_api' from outer scope (line 27)

(W0621)

tests/model_registry/rest_api/utils.py

[error] 5-5: Unable to import 'simple_logger.logger'

(E0401)


[convention] 110-110: Line too long (105/100)

(C0301)

utilities/exceptions.py

[warning] 128-128: Unnecessary pass statement

(W0107)


[warning] 134-134: Unnecessary pass statement

(W0107)

🔇 Additional comments (3)
utilities/exceptions.py (1)

125-134: Well-designed exception classes for model registry validation.

The new exception classes ResourceValueMismatch and MissingParameter are appropriately designed with clear docstrings and proper inheritance. They provide specific error types for the model registry validation framework.

🧰 Tools
🪛 Pylint (3.3.7)

[warning] 128-128: Unnecessary pass statement

(W0107)


[warning] 134-134: Unnecessary pass statement

(W0107)

tests/model_registry/rest_api/test_model_registry_rest_api.py (2)

11-24: Excellent test constants supporting comprehensive archive/unarchive testing.

The new constants provide well-structured test data for validating model registry updates, including the archive/unarchive functionality mentioned in the PR objectives. The CUSTOM_PROPERTY constant with metadata types is particularly well-designed.


77-81: Good refactoring to use centralized validation.

The replacement of manual validation logic with the validate_resource_attributes function improves code consistency and maintainability.

Comment thread tests/model_registry/rest_api/test_model_registry_rest_api.py
Copy link
Copy Markdown
Contributor

@fege fege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@dbasunag dbasunag merged commit f28e958 into opendatahub-io:main Jun 5, 2025
13 checks passed
@dbasunag dbasunag deleted the archive_model branch June 5, 2025 12:27
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2025

Status of building tag latest: success.
Status of pushing tag latest to image registry: success.

adolfo-ab pushed a commit to adolfo-ab/opendatahub-tests that referenced this pull request Jun 11, 2025
* on rebase clean commented-by- labels

* Add tests to archive and unarchive models, versions

updates! 1b232c3

updates! 8195a8f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants