Skip to content

feat: fake k8 client and resource test generator #2433

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

Merged
merged 7 commits into from
Jul 6, 2025
Merged

feat: fake k8 client and resource test generator #2433

merged 7 commits into from
Jul 6, 2025

Conversation

myakove
Copy link
Collaborator

@myakove myakove commented Jul 5, 2025

Add fake k8s client.
Add resource test generator

Summary by CodeRabbit

  • New Features

    • Introduced a comprehensive fake Kubernetes dynamic client for unit testing, enabling simulation of Kubernetes resource operations without a real cluster.
    • Added automated test generation scripts and documentation for creating standard CRUD tests for new resource classes.
    • Significantly expanded test coverage with new test suites for numerous Kubernetes and OpenShift resources, all using the fake client for isolated testing.
  • Bug Fixes

    • Improved client context handling during resource cleanup operations.
  • Documentation

    • Added detailed documentation for the fake Kubernetes client and test generation process.
    • Updated README files with instructions for generating and running tests for new resources.
  • Chores

    • Increased the minimum required test coverage threshold from 45% to 60%.

Copy link

coderabbitai bot commented Jul 5, 2025

## Walkthrough

This update introduces a comprehensive fake Kubernetes dynamic client for unit testing, a test generator script for resource classes, and a large suite of pytest-based resource lifecycle tests using the fake client. Documentation is expanded to cover these features. Minor configuration and code adjustments support the new testing approach.

## Changes

| Files/Group                                                                 | Change Summary                                                                                                                      |
|-----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|
| `.flake8`, `pyproject.toml`                                                 | Updated configuration: `.flake8` adds more excluded functions; `pyproject.toml` raises minimum coverage threshold from 45% to 60%.  |
| `README.md`                                                                 | Added section on test generation and running tests for new resources.                                                               |
| `fake_kubernetes_client/README.md`, `fake_kubernetes_client/__init__.py`,<br>`fake_kubernetes_client/fake_dynamic_client.py` | Added new fake Kubernetes dynamic client package with documentation, API, and implementation for resource simulation/testing.        |
| `ocp_resources/project_request.py`                                          | Modified `clean_up` to pass the `client` attribute when instantiating `Project`.                                                    |
| `tests/scripts/generate_pytest_test.py`                                     | Added a script to auto-generate pytest test modules for resource classes.                                                           |
| `tests/test_resource.py`                                                     | Refactored to use the new fake Kubernetes client for tests, removing real cluster dependencies.                                     |
| `tests/test_resources/test_*.py` (all new test modules)                     | Added extensive pytest suites for resource classes, covering CRUD operations using the fake client.                                 |

## Possibly related issues

- RedHatQE/openshift-python-wrapper#2434: This PR directly implements the "fake k8 client and resource test generator" feature described in the issue.

## Possibly related PRs

- RedHatQE/openshift-python-wrapper#2165: Both PRs update the `.flake8` configuration, modifying the exclusion list for complexity checks.
- RedHatQE/openshift-python-wrapper#2172: This PR refines the `clean_up` method for `ProjectRequest`, building upon changes introduced in #2172.
- RedHatQE/openshift-python-wrapper#2431: This PR adds tests for the `LlamaStackDistribution` resource, related to the resource class introduced in #2431.

## Suggested labels

`verified`, `can-be-merged`, `approved-myakove`, `lgtm-dbasunag`

## Suggested reviewers

- rnetser
- dbasunag
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in a Comment
  • Commit Unit Tests in branch fake-client

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 auto-generate unit tests to generate unit tests for 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.

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.

@redhat-qe-bot1
Copy link

Report bugs in Issues

Welcome! 🎉

This pull request will be automatically processed with the following features:

🔄 Automatic Actions

  • Reviewer Assignment: Reviewers are automatically assigned based on the OWNERS file in the repository root
  • Size Labeling: PR size labels (XS, S, M, L, XL, XXL) are automatically applied based on changes
  • Issue Creation: A tracking issue is created for this PR and will be closed when the PR is merged or closed
  • Pre-commit Checks: pre-commit runs automatically if .pre-commit-config.yaml exists
  • Branch Labeling: Branch-specific labels are applied to track the target branch
  • Auto-verification: Auto-verified users have their PRs automatically marked as verified

📋 Available Commands

PR Status Management

  • /wip - Mark PR as work in progress (adds WIP: prefix to title)
  • /wip cancel - Remove work in progress status
  • /hold - Block PR merging (approvers only)
  • /hold cancel - Unblock PR merging
  • /verified - Mark PR as verified
  • /verified cancel - Remove verification status

Review & Approval

  • /lgtm - Approve changes (looks good to me)
  • /approve - Approve PR (approvers only)
  • /automerge - Enable automatic merging when all requirements are met (maintainers and approvers only)
  • /assign-reviewers - Assign reviewers based on OWNERS file
  • /assign-reviewer @username - Assign specific reviewer
  • /check-can-merge - Check if PR meets merge requirements

Testing & Validation

  • /retest tox - Run Python test suite with tox
  • /retest python-module-install - Test Python package installation
  • /retest conventional-title - Validate commit message format
  • /retest all - Run all available tests

Container Operations

  • /build-and-push-container - Build and push container image (tagged with PR number)
    • Supports additional build arguments: /build-and-push-container --build-arg KEY=value

Cherry-pick Operations

  • /cherry-pick <branch> - Schedule cherry-pick to target branch when PR is merged
    • Multiple branches: /cherry-pick branch1 branch2 branch3

Label Management

  • /<label-name> - Add a label to the PR
  • /<label-name> cancel - Remove a label from the PR

✅ Merge Requirements

This PR will be automatically approved when the following conditions are met:

  1. Approval: /approve from at least one approver
  2. LGTM Count: Minimum 0 /lgtm from reviewers
  3. Status Checks: All required status checks must pass
  4. No Blockers: No WIP, hold, or conflict labels
  5. Verified: PR must be marked as verified (if verification is enabled)

📊 Review Process

Approvers and Reviewers

Approvers:

  • myakove
  • rnetser

Reviewers:

  • dbasunag
  • myakove
  • rnetser
Available Labels
  • hold
  • verified
  • wip
  • lgtm
  • approve
  • automerge

💡 Tips

  • WIP Status: Use /wip when your PR is not ready for review
  • Verification: The verified label is automatically removed on each new commit
  • Cherry-picking: Cherry-pick labels are processed when the PR is merged
  • Container Builds: Container images are automatically tagged with the PR number
  • Permission Levels: Some commands require approver permissions
  • Auto-verified Users: Certain users have automatic verification and merge privileges

For more information, please refer to the project documentation or contact the maintainers.

@myakove
Copy link
Collaborator Author

myakove commented Jul 5, 2025

/verified

@myakove
Copy link
Collaborator Author

myakove commented Jul 5, 2025

/verified

Copy link

@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: 29

🔭 Outside diff range comments (7)
tests/test_resources/test_authorino.py (1)

6-45: Consider improving test isolation and independence.

The test structure follows a clear CRUD pattern, which is good. However, the tests have potential interdependencies that could lead to flaky behavior:

  1. Test execution order dependency: Tests like test_get_authorino, test_update_authorino, and test_delete_authorino depend on the resource being created first by test_create_authorino. Pytest doesn't guarantee test execution order within a class.

  2. Shared state via class-scoped fixtures: The authorino fixture is class-scoped, meaning the same instance is shared across all tests, potentially causing state leakage between tests.

Consider these improvements:

 class TestAuthorino:
     @pytest.fixture(scope="class")
     def client(self):
         return FakeDynamicClient()

-    @pytest.fixture(scope="class")
+    @pytest.fixture()
     def authorino(self, client):
-        return Authorino(
+        authorino = Authorino(
             client=client,
             name="test-authorino",
             namespace="default",
             listener="test-listener",
             oidc_server="test-oidc_server",
         )
+        # Ensure the resource is created for tests that need it
+        authorino.deploy()
+        yield authorino
+        # Cleanup after each test
+        if authorino.exists:
+            authorino.clean_up(wait=False)

This ensures each test gets a fresh, deployed resource instance and proper cleanup.

tests/test_resources/test_prometheus.py (1)

38-43: Consider cleanup verification and suggest pattern standardization.

Same recommendation for delete test verification. Given the repetitive nature of these tests across multiple files, consider standardizing the pattern.

 def test_delete_prometheus(self, prometheus):
     """Test deleting Prometheus"""
     prometheus.clean_up(wait=False)
+    assert not prometheus.exists
     # Note: In real clusters, you might want to verify deletion
     # but with fake client, clean_up() removes the resource immediately

Since this pattern is repeated across multiple resource test files, would you like me to generate a standardized base test class that could be inherited by all resource tests to ensure consistency and proper test isolation?

tests/test_resources/test_mariadb_operator.py (1)

1-43: Consider refactoring to reduce code duplication and improve test coverage.

This test file follows an identical pattern to multiple other test files in this PR, leading to significant code duplication. While the basic CRUD testing approach is sound, consider these improvements:

  1. Extract common test patterns: Create a base test class or shared utilities for common CRUD operations
  2. Add parameterized tests: Use pytest.mark.parametrize to test multiple resource types with the same pattern
  3. Expand test coverage: Add tests for edge cases, error conditions, and resource-specific behaviors
  4. Consider fixture isolation: Class-scoped fixtures may cause test interdependencies

Example refactoring approach:

# shared_test_utils.py
def create_base_resource_tests(resource_class, resource_params):
    """Factory function to create standard CRUD tests for any resource"""
    pass

# test_mariadb_operator.py
import pytest
from shared_test_utils import create_base_resource_tests
from ocp_resources.mariadb_operator import MariadbOperator

class TestMariadbOperator(create_base_resource_tests(
    MariadbOperator, 
    {"name": "test-mariadboperator", "namespace": "default"}
)):
    # Add MariadbOperator-specific tests here
    pass
tests/test_resources/test_virtual_machine_cluster_instancetype.py (1)

1-44: Identical code duplication pattern - consider shared testing utilities.

This test file is nearly identical to the other resource test files in this PR, differing only in the resource type and constructor parameters. This represents a maintenance burden and missed opportunity for comprehensive testing.

Consider:

  1. Creating a shared base test class for common CRUD operations
  2. Adding resource-specific tests for VirtualMachineClusterInstancetype's unique features (cpu, memory validation, etc.)
  3. Testing invalid parameter scenarios given the cpu/memory parameters

Example resource-specific test:

def test_cpu_memory_validation(self, virtualmachineclusterinstancetype):
    """Test CPU and memory specifications"""
    assert virtualmachineclusterinstancetype.instance.spec.cpu == "test-cpu"
    assert virtualmachineclusterinstancetype.instance.spec.memory == "test-memory"
tests/test_resources/test_virtual_machine_instance_migration.py (1)

1-43: Duplicate code pattern - missing migration-specific test coverage.

This test file continues the identical pattern seen across multiple resource test files. For VirtualMachineInstanceMigration, consider adding tests specific to migration operations and states.

Resource-specific tests to consider:

def test_migration_status_tracking(self, virtualmachineinstancemigration):
    """Test migration status and progress tracking"""
    # Test migration-specific status fields
    pass

def test_migration_target_validation(self, virtualmachineinstancemigration):
    """Test migration target node validation"""
    # Test migration target specifications
    pass

Consider consolidating the common CRUD pattern into a shared utility to reduce the ~200 lines of duplicated code across these test files.

tests/test_resources/test_virtual_machine_instancetype.py (1)

1-45: Code duplication continues - leverage API validation insights from learnings.

This test file maintains the same duplicated structure as the others. Given the retrieved learnings about VirtualMachineInstancetype relying on API validation, consider adding tests that exercise this validation behavior.

Based on the learning that "the code relies on the underlying API to handle type validation errors", add tests like:

def test_api_validation_handling(self, client):
    """Test that invalid parameters are handled by API validation"""
    with pytest.raises(Exception):  # or specific validation exception
        invalid_resource = VirtualMachineInstancetype(
            client=client,
            name="invalid-test",
            namespace="default",
            cpu="invalid-cpu-spec",
            memory="invalid-memory-spec",
        )
        invalid_resource.deploy()

This would provide more meaningful coverage than just the basic CRUD operations.

tests/test_resources/test_data_import_cron.py (1)

1-49: Final instance of code duplication pattern.

This is the 5th test file following the identical structure. The cumulative code duplication across all these files represents a significant maintenance burden.

Recommendation: Before adding more resource test files, implement a shared testing framework:

# tests/conftest.py or tests/shared_test_base.py
class BaseResourceTest:
    """Base class for resource CRUD testing"""
    
    @pytest.fixture(scope="class")
    def client(self):
        return FakeDynamicClient()
    
    def test_create_resource(self, resource_fixture):
        """Generic create test"""
        deployed_resource = resource_fixture.deploy()
        assert deployed_resource
        assert deployed_resource.name == resource_fixture.name
        assert resource_fixture.exists
    
    # ... other common tests

This would eliminate ~90% of the duplicated code while maintaining the same test coverage.

♻️ Duplicate comments (18)
tests/test_resources/test_pod_metrics.py (1)

6-46: Apply the same test isolation improvements as suggested for Authorino.

This test file follows the identical pattern to test_authorino.py and has the same potential issues with test interdependencies and shared state via class-scoped fixtures. The same refactoring suggestions apply here to improve test isolation and independence.

tests/test_resources/test_mig_plan.py (1)

6-43: Apply the same test isolation improvements as other test files.

This test file follows the same pattern as the other resource test files and has identical concerns regarding test interdependencies and shared state. The minimal parameter approach for the MigPlan fixture is appropriate for testing basic functionality.

tests/test_resources/test_storage_cluster.py (1)

6-43: Apply the same test isolation improvements as other test files.

This test file follows the same pattern as the other resource test files and has identical concerns regarding test interdependencies and shared state. The minimal parameter approach for the StorageCluster fixture is appropriate for testing basic CRUD functionality, even though the StorageCluster class supports many additional configuration parameters.

tests/test_resources/test_snapshot.py (1)

6-44: Apply the same test isolation improvements as other test files.

This test file follows the same pattern as the other resource test files and has identical concerns regarding test interdependencies and shared state. The inclusion of the application parameter in the Snapshot fixture is appropriate for this resource type.

Overall pattern observation: All five test files follow a consistent, generated pattern which is good for maintainability. However, they all share the same fundamental issue with test dependencies. Consider updating the test generator script to produce more isolated tests to improve the robustness of the entire test suite.

tests/test_resources/test_replica_set.py (1)

20-44: Consistent test lifecycle pattern

This test suite maintains the same pattern as other resource tests in the PR. The same structural considerations apply regarding test dependencies and delete verification.

tests/test_resources/test_model_registry_components_platform_opendatahub_io.py (1)

6-42: Consistent ModelRegistry test implementation

This test suite follows the established pattern for resource lifecycle testing introduced in this PR. The ModelRegistry resource configuration appears appropriate for this resource type.

tests/test_resources/test_deployment.py (1)

25-49: Consistent test pattern with comprehensive resource

This test suite maintains the same lifecycle testing pattern while working with a more complex resource configuration. The tests appropriately verify the Deployment's behavior through the fake client.

tests/test_resources/test_project_project_openshift_io.py (2)

7-16: Consider test isolation with class-scoped fixtures.

Same issue as in other test files - class-scoped fixtures can create test interdependencies. Consider using function-scoped fixtures for better test isolation.


37-41: Verify resource deletion in test.

The deletion test doesn't verify that the resource is actually deleted after calling clean_up().

tests/test_resources/test_guardrails_orchestrator.py (2)

7-19: Consider test isolation with class-scoped fixtures.

Same fixture scope issue as in other test files - consider function-scoped fixtures for better test isolation.


40-44: Verify resource deletion in test.

The deletion test doesn't verify that the resource is actually deleted after calling clean_up().

tests/test_resources/test_image_content_source_policy.py (3)

6-17: Same test isolation concerns as other resource tests.

The class-scoped fixtures create implicit test dependencies without enforcement of execution order.

Apply the same recommendation as for test_volume_snapshot.py:

+@pytest.mark.incremental
 class TestImageContentSourcePolicy:

30-36: Same label modification concern.

The update test modifies labels which could affect subsequent tests with shared resource instance.


37-42: Consider cleanup verification.

Same recommendation as other delete tests - add existence check after cleanup.

 def test_delete_imagecontentsourcepolicy(self, imagecontentsourcepolicy):
     """Test deleting ImageContentSourcePolicy"""
     imagecontentsourcepolicy.clean_up(wait=False)
+    assert not imagecontentsourcepolicy.exists
     # Note: In real clusters, you might want to verify deletion
     # but with fake client, clean_up() removes the resource immediately
tests/test_resources/test_image_caching_internal_knative_dev.py (3)

6-19: Same test isolation pattern needs addressing.

Identical issue with class-scoped fixtures creating implicit test dependencies.

+@pytest.mark.incremental
 class TestImage:

32-38: Same label modification concern.

The update test modifies labels which could affect subsequent tests.


39-44: Consider cleanup verification.

Same recommendation for delete test verification.

 def test_delete_image(self, image):
     """Test deleting Image"""
     image.clean_up(wait=False)
+    assert not image.exists
     # Note: In real clusters, you might want to verify deletion
     # but with fake client, clean_up() removes the resource immediately
tests/test_resources/test_prometheus.py (1)

31-37: Same label modification concern.

The update test modifies labels which could affect subsequent tests.

🧹 Nitpick comments (27)
.flake8 (1)

65-67: Re-evaluate the new exemptions (self, defaultdict, add_row).

self is not a function, and defaultdict is a standard-library constructor whose calls you probably still want checked. Blanket-exempting them (and every helper you add in the future) gradually erodes the benefit of flake8-function-naming / flake8-complexity checks.

Consider keeping the list minimal and project-specific. If these three are not triggering noisy false-positives, drop them:

-    self,
-    defaultdict,
-    add_row,

Please confirm that the current violations really warrant global suppression instead of local # noqa: FCN???? overrides.

tests/test_resources/test_aaq.py (1)

7-16: Consider test interdependency with class-scoped fixtures.

The class-scoped fixtures mean all tests share the same resource instance, creating dependencies between tests. While this enables lifecycle testing, it can make tests brittle if they don't run in the expected order or if one test fails.

Consider either:

  1. Using function-scoped fixtures for better test isolation
  2. Adding explicit test ordering with pytest.mark.order if lifecycle testing is intended
  3. Making each test self-contained by creating its own resource instance
-    @pytest.fixture(scope="class")
+    @pytest.fixture(scope="function")
     def aaq(self, client):
         return AAQ(
             client=client,
             name="test-aaq",
         )
tests/test_resources/test_direct_volume_migration.py (1)

11-17: Consider shortening the fixture name and addressing test interdependency.

The fixture name directvolumemigration is quite long and could be shortened for better readability. Also, the class-scoped fixtures create test interdependencies.

Consider these improvements:

     @pytest.fixture(scope="class")
-    def directvolumemigration(self, client):
+    def dvm(self, client):
         return DirectVolumeMigration(
             client=client,
-            name="test-directvolumemigration",
+            name="test-dvm",
             namespace="default",
         )

Also consider using function-scoped fixtures for better test isolation if lifecycle testing isn't specifically required.

tests/test_resources/test_user_defined_network.py (1)

11-18: Good use of topology parameter, but consider fixture naming.

The inclusion of the topology="Layer2" parameter is appropriate based on the UserDefinedNetwork resource design. However, the fixture name could be shortened for better readability.

The topology parameter usage aligns with the resource design.

Consider shortening the fixture name:

     @pytest.fixture(scope="class")
-    def userdefinednetwork(self, client):
+    def udn(self, client):
         return UserDefinedNetwork(
             client=client,
-            name="test-userdefinednetwork",
+            name="test-udn",
             namespace="default",
             topology="Layer2",
         )
tests/test_resources/test_mtq.py (2)

30-35: Add defensive checks for metadata structure.

The test assumes that instance.to_dict() returns a dictionary with a metadata key and that labels can be safely updated. Consider adding defensive checks.

     def test_update_mtq(self, mtq):
         """Test updating MTQ"""
         resource_dict = mtq.instance.to_dict()
+        if "metadata" not in resource_dict:
+            resource_dict["metadata"] = {}
         resource_dict["metadata"]["labels"] = {"updated": "true"}
         mtq.update(resource_dict=resource_dict)
         assert mtq.labels["updated"] == "true"

37-42: Consider verifying resource state after deletion.

While the comment explains that the fake client removes resources immediately, adding verification would make the test more robust and align with real-world testing patterns.

     def test_delete_mtq(self, mtq):
         """Test deleting MTQ"""
         mtq.clean_up(wait=False)
+        assert not mtq.exists
         # Note: In real clusters, you might want to verify deletion
         # but with fake client, clean_up() removes the resource immediately
tests/test_resources/test_model_registry_modelregistry_opendatahub_io.py (1)

33-38: Add validation for resource-specific attributes.

Consider adding tests that validate the ModelRegistry-specific parameters (grpc, rest) are correctly set in the resource.

     def test_update_modelregistry(self, modelregistry):
         """Test updating ModelRegistry"""
         resource_dict = modelregistry.instance.to_dict()
         resource_dict["metadata"]["labels"] = {"updated": "true"}
         modelregistry.update(resource_dict=resource_dict)
         assert modelregistry.labels["updated"] == "true"
+        # Verify resource-specific parameters are preserved
+        assert modelregistry.instance.to_dict().get("spec", {}).get("grpc") == "test-grpc"
+        assert modelregistry.instance.to_dict().get("spec", {}).get("rest") == "test-rest"
tests/test_resources/test_scheduler.py (1)

18-23: Consider testing Scheduler-specific functionality.

The current tests only cover basic CRUD operations. Based on the Scheduler resource implementation, consider adding tests for Scheduler-specific parameters like default_node_selector, masters_schedulable, and profile.

Add a test for Scheduler-specific functionality:

+    def test_scheduler_configuration(self, scheduler):
+        """Test Scheduler-specific configuration"""
+        # Test that scheduler configuration is properly set
+        resource_dict = scheduler.instance.to_dict()
+        spec = resource_dict.get("spec", {})
+        
+        # Add assertions for Scheduler-specific fields if they were set
+        # assert spec.get("defaultNodeSelector") == "test-selector"
+        # assert spec.get("mastersSchedulable") == True
+        # assert spec.get("profile") == "HighNodeUtilization"
tests/test_resources/test_oauth.py (1)

30-35: Add defensive programming for metadata handling.

The test assumes the resource has a properly structured metadata dictionary. Adding defensive checks would make the test more robust.

     def test_update_oauth(self, oauth):
         """Test updating OAuth"""
         resource_dict = oauth.instance.to_dict()
+        if "metadata" not in resource_dict:
+            resource_dict["metadata"] = {}
+        if "labels" not in resource_dict["metadata"]:
+            resource_dict["metadata"]["labels"] = {}
         resource_dict["metadata"]["labels"] = {"updated": "true"}
         oauth.update(resource_dict=resource_dict)
         assert oauth.labels["updated"] == "true"
tests/test_resources/test_network_config_openshift_io.py (1)

1-42: Consider enhancing the test generation template.

All test files follow an identical pattern that suggests they were generated from a template. While this provides consistent coverage, consider enhancing the template to:

  1. Use function-scoped fixtures for better test isolation
  2. Add resource-specific parameter testing
  3. Include error handling scenarios
  4. Add edge case coverage

This would improve the overall quality and robustness of the generated test suite while maintaining the automation benefits.

tests/test_resources/test_group.py (1)

7-17: Consider test isolation to avoid execution order dependencies.

The class-scoped fixtures create shared state between tests, making them dependent on execution order. While this works with the current test structure, it reduces test isolation and could cause issues if tests are run individually or in different orders.

Consider using function-scoped fixtures or implementing proper test setup/teardown to ensure each test can run independently.

tests/test_resources/test_image_image_openshift_io.py (1)

7-16: Consider test isolation to avoid execution order dependencies.

Similar to the Group test, this uses class-scoped fixtures creating shared state between tests. Consider using function-scoped fixtures for better test isolation.

tests/test_resources/test_ssp.py (1)

7-18: Consider test isolation to avoid execution order dependencies.

The class-scoped fixtures create shared state between tests. Consider using function-scoped fixtures for better test isolation, especially since the SSP resource includes namespace-specific configuration.

tests/test_resources/test_namespace.py (1)

7-16: Consider test isolation to avoid execution order dependencies.

The class-scoped fixtures create shared state between tests. For Namespace testing, this is particularly important since namespaces can affect resource scoping in real clusters.

tests/test_resources/test_dns_operator_openshift_io.py (1)

7-16: Consider test isolation to avoid execution order dependencies.

The class-scoped fixtures create shared state between tests. Consider using function-scoped fixtures for better test isolation.

tests/test_resources/test_maria_db.py (1)

6-43: Test structure follows good pattern but has implicit dependencies

The test suite follows a consistent pattern for resource lifecycle testing. However, there are some considerations:

  1. Test dependencies: Tests rely on execution order (create → get → update → delete) which reduces test isolation
  2. Missing delete verification: The delete test doesn't verify the resource was actually removed
  3. Class-scoped fixtures: All tests share the same resource instance, which could cause issues if tests don't clean up properly

For generated tests, this pattern may be acceptable, but consider adding verification that the resource no longer exists after deletion.

 def test_delete_mariadb(self, mariadb):
     """Test deleting MariaDB"""
     mariadb.clean_up(wait=False)
+    assert not mariadb.exists
     # Note: In real clusters, you might want to verify deletion
     # but with fake client, clean_up() removes the resource immediately
tests/test_resources/test_console_operator_openshift_io.py (1)

6-42: Consistent test pattern with same structural considerations

This test suite follows the same pattern as other resource tests, which maintains consistency across the codebase. The same considerations apply:

  1. Test execution order dependency: Tests assume sequential execution
  2. Missing delete verification: No assertion that the resource was actually deleted
  3. Resource scope: Console resource correctly omits namespace (likely cluster-scoped)

The pattern is consistent with the testing framework introduced in this PR.

 def test_delete_console(self, console):
     """Test deleting Console"""
     console.clean_up(wait=False)
+    assert not console.exists
     # Note: In real clusters, you might want to verify deletion
     # but with fake client, clean_up() removes the resource immediately
tests/test_resources/test_mig_migration.py (2)

7-19: Consider test isolation with class-scoped fixtures.

Class-scoped fixtures can create test interdependencies since the same resource instance is shared across all test methods. This can lead to unpredictable test behavior if tests modify the resource state.

Consider using function-scoped fixtures for better test isolation:

-    @pytest.fixture(scope="class")
+    @pytest.fixture(scope="function")
     def client(self):
         return FakeDynamicClient()
 
-    @pytest.fixture(scope="class")
+    @pytest.fixture(scope="function")
     def migmigration(self, client):

39-43: Verify resource deletion in test.

The test doesn't verify that the resource is actually deleted after calling clean_up(). Consider adding an assertion to ensure the resource no longer exists.

     def test_delete_migmigration(self, migmigration):
         """Test deleting MigMigration"""
         migmigration.clean_up(wait=False)
+        assert not migmigration.exists
         # Note: In real clusters, you might want to verify deletion
         # but with fake client, clean_up() removes the resource immediately
tests/test_resources/test_network_operator_openshift_io.py (1)

7-16: Consider test isolation for future improvements.

While the current class-scoped fixture approach maintains consistency across all generated test files, future iterations might benefit from function-scoped fixtures for better test isolation.

tests/test_resource.py (1)

11-11: Redundant import addition.

The Resource class is already imported implicitly through usage in the existing code. This explicit import is not necessary but doesn't cause issues.

tests/test_resources/test_volume_snapshot.py (1)

39-44: Consider cleanup timing for test reliability.

The delete test with wait=False may not provide sufficient verification that cleanup completed successfully, even with the fake client's immediate deletion behavior.

Consider adding an existence check after cleanup:

 def test_delete_volumesnapshot(self, volumesnapshot):
     """Test deleting VolumeSnapshot"""
     volumesnapshot.clean_up(wait=False)
+    assert not volumesnapshot.exists
     # Note: In real clusters, you might want to verify deletion
     # but with fake client, clean_up() removes the resource immediately
tests/test_resources/test_security_context_constraints.py (1)

12-23: Review SecurityContextConstraints parameter types

The test uses string values for boolean security parameters (e.g., allow_host_ipc="test-allow_host_ipc"), which may not reflect realistic usage. Consider using boolean values for security constraint fields to better match expected production configurations.

return SecurityContextConstraints(
    client=client,
    name="test-securitycontextconstraints",
-   allow_host_dir_volume_plugin="test-allow_host_dir_volume_plugin",
-   allow_host_ipc="test-allow_host_ipc",
-   allow_host_network="test-allow_host_network",
-   allow_host_pid="test-allow_host_pid",
+   allow_host_dir_volume_plugin=True,
+   allow_host_ipc=False,
+   allow_host_network=False,
+   allow_host_pid=False,
    allow_host_ports=[{"port": 80, "target_port": 8080}],
-   allow_privileged_container="test-allow_privileged_container",
-   read_only_root_filesystem="test-read_only_root_filesystem",
+   allow_privileged_container=False,
+   read_only_root_filesystem=True,
)
fake_kubernetes_client/README.md (1)

257-259: Add language specification to fenced code block

The fenced code block should specify a language for proper syntax highlighting.

-```
+```text
 NotImplementedError: Couldn't find ResourceKind in api.group api group

</blockquote></details>
<details>
<summary>fake_kubernetes_client/fake_dynamic_client.py (3)</summary><blockquote>

`357-375`: **Misleading comment - status generation is not truly dynamic.**

The comment states "dynamic based on kind (no hardcoded mappings)" but the implementation uses explicit if/elif checks for specific kinds. This is exactly what hardcoded mappings are.



Either update the comment to be accurate or refactor to use a truly dynamic approach:

```diff
-def _add_realistic_status(self, body):
-    """Add realistic status for different resource types - dynamic based on kind"""
+def _add_realistic_status(self, body):
+    """Add realistic status for different resource types based on kind"""
     kind = body.get("kind", "")

Alternatively, for a truly dynamic approach:

STATUS_TEMPLATES = {
    "Pod": "_get_pod_status_template",
    "Deployment": "_get_deployment_status_template",
    "Service": "_get_service_status_template",
    "Namespace": "_get_namespace_status_template",
}

def _add_realistic_status(self, body):
    """Add realistic status for different resource types - dynamic based on kind"""
    kind = body.get("kind", "")
    
    template_method = self.STATUS_TEMPLATES.get(kind, "_get_generic_status_template")
    status = getattr(self, template_method)(body)
    
    if status:
        body["status"] = status

747-747: Remove debug comment from production code.

This appears to be a leftover comment from debugging. Such comments should be removed before merging.

-                    continue  # FIXED: Continue instead of return None
+                    continue

1384-1422: Clean up unnecessary else statements after return.

Multiple methods in this section have unnecessary else clauses after return statements, which reduces readability.

 def get(self, resource, name=None, namespace=None, **kwargs):
     """Get resource(s) using resource definition"""
     if hasattr(resource, "get"):
         return resource.get(name=name, namespace=namespace, **kwargs)
-    else:
-        raise ValueError("Invalid resource definition")
+    raise ValueError("Invalid resource definition")

 def create(self, resource, body=None, namespace=None, **kwargs):
     """Create resource using resource definition"""
     if hasattr(resource, "create"):
         return resource.create(body=body, namespace=namespace, **kwargs)
-    else:
-        raise ValueError("Invalid resource definition")
+    raise ValueError("Invalid resource definition")

 def delete(self, resource, name=None, namespace=None, **kwargs):
     """Delete resource using resource definition"""
     if hasattr(resource, "delete"):
         return resource.delete(name=name, namespace=namespace, **kwargs)
-    else:
-        raise ValueError("Invalid resource definition")
+    raise ValueError("Invalid resource definition")

 def patch(self, resource, name=None, body=None, namespace=None, **kwargs):
     """Patch resource using resource definition"""
     if hasattr(resource, "patch"):
         return resource.patch(name=name, body=body, namespace=namespace, **kwargs)
-    else:
-        raise ValueError("Invalid resource definition")
+    raise ValueError("Invalid resource definition")

 def replace(self, resource, name=None, body=None, namespace=None, **kwargs):
     """Replace resource using resource definition"""
     if hasattr(resource, "replace"):
         return resource.replace(name=name, body=body, namespace=namespace, **kwargs)
-    else:
-        raise ValueError("Invalid resource definition")
+    raise ValueError("Invalid resource definition")

 def watch(self, resource, namespace=None, **kwargs):
     """Watch resource using resource definition"""
     if hasattr(resource, "watch"):
         return resource.watch(namespace=namespace, **kwargs)
-    else:
-        raise ValueError("Invalid resource definition")
+    raise ValueError("Invalid resource definition")
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e165e61 and 478c6fc.

📒 Files selected for processing (90)
  • .flake8 (1 hunks)
  • README.md (1 hunks)
  • fake_kubernetes_client/README.md (1 hunks)
  • fake_kubernetes_client/__init__.py (1 hunks)
  • fake_kubernetes_client/fake_dynamic_client.py (1 hunks)
  • ocp_resources/project_request.py (2 hunks)
  • test_utils/fake_dynamic_client.py (1 hunks)
  • tests/scripts/generate_pytest_test.py (1 hunks)
  • tests/test_resource.py (4 hunks)
  • tests/test_resources/test_aaq.py (1 hunks)
  • tests/test_resources/test_api_server.py (1 hunks)
  • tests/test_resources/test_authorino.py (1 hunks)
  • tests/test_resources/test_cdi.py (1 hunks)
  • tests/test_resources/test_cdi_config.py (1 hunks)
  • tests/test_resources/test_cluster_resource_quota.py (1 hunks)
  • tests/test_resources/test_cluster_user_defined_network.py (1 hunks)
  • tests/test_resources/test_config_map.py (1 hunks)
  • tests/test_resources/test_console_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_console_operator_openshift_io.py (1 hunks)
  • tests/test_resources/test_csi_driver.py (1 hunks)
  • tests/test_resources/test_data_import_cron.py (1 hunks)
  • tests/test_resources/test_data_science_cluster.py (1 hunks)
  • tests/test_resources/test_deployment.py (1 hunks)
  • tests/test_resources/test_direct_volume_migration.py (1 hunks)
  • tests/test_resources/test_direct_volume_migration_progress.py (1 hunks)
  • tests/test_resources/test_dns_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_dns_operator_openshift_io.py (1 hunks)
  • tests/test_resources/test_dsc_initialization.py (1 hunks)
  • tests/test_resources/test_group.py (1 hunks)
  • tests/test_resources/test_guardrails_orchestrator.py (1 hunks)
  • tests/test_resources/test_image_caching_internal_knative_dev.py (1 hunks)
  • tests/test_resources/test_image_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_image_content_source_policy.py (1 hunks)
  • tests/test_resources/test_image_image_openshift_io.py (1 hunks)
  • tests/test_resources/test_inference_graph.py (1 hunks)
  • tests/test_resources/test_kube_descheduler.py (1 hunks)
  • tests/test_resources/test_kubelet_config.py (1 hunks)
  • tests/test_resources/test_kubevirt.py (1 hunks)
  • tests/test_resources/test_llama_stack_distribution.py (1 hunks)
  • tests/test_resources/test_lm_eval_job.py (1 hunks)
  • tests/test_resources/test_machine.py (1 hunks)
  • tests/test_resources/test_maria_db.py (1 hunks)
  • tests/test_resources/test_mariadb_operator.py (1 hunks)
  • tests/test_resources/test_mig_analytic.py (1 hunks)
  • tests/test_resources/test_mig_cluster.py (1 hunks)
  • tests/test_resources/test_mig_migration.py (1 hunks)
  • tests/test_resources/test_mig_plan.py (1 hunks)
  • tests/test_resources/test_model_registry.py (1 hunks)
  • tests/test_resources/test_model_registry_components_platform_opendatahub_io.py (1 hunks)
  • tests/test_resources/test_model_registry_modelregistry_opendatahub_io.py (1 hunks)
  • tests/test_resources/test_mtq.py (1 hunks)
  • tests/test_resources/test_namespace.py (1 hunks)
  • tests/test_resources/test_network_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_network_operator_openshift_io.py (1 hunks)
  • tests/test_resources/test_nm_state.py (1 hunks)
  • tests/test_resources/test_node.py (1 hunks)
  • tests/test_resources/test_node_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_node_network_configuration_policy_latest.py (1 hunks)
  • tests/test_resources/test_notebook.py (1 hunks)
  • tests/test_resources/test_oauth.py (1 hunks)
  • tests/test_resources/test_operator.py (1 hunks)
  • tests/test_resources/test_pod.py (1 hunks)
  • tests/test_resources/test_pod_metrics.py (1 hunks)
  • tests/test_resources/test_project_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_project_project_openshift_io.py (1 hunks)
  • tests/test_resources/test_project_request.py (1 hunks)
  • tests/test_resources/test_prometheus.py (1 hunks)
  • tests/test_resources/test_replica_set.py (1 hunks)
  • tests/test_resources/test_scheduler.py (1 hunks)
  • tests/test_resources/test_security_context_constraints.py (1 hunks)
  • tests/test_resources/test_self_subject_review.py (1 hunks)
  • tests/test_resources/test_service.py (1 hunks)
  • tests/test_resources/test_service_mesh_member.py (1 hunks)
  • tests/test_resources/test_service_serving_knative_dev.py (1 hunks)
  • tests/test_resources/test_serving_runtime.py (1 hunks)
  • tests/test_resources/test_snapshot.py (1 hunks)
  • tests/test_resources/test_ssp.py (1 hunks)
  • tests/test_resources/test_storage_cluster.py (1 hunks)
  • tests/test_resources/test_user.py (1 hunks)
  • tests/test_resources/test_user_defined_network.py (1 hunks)
  • tests/test_resources/test_virtual_machine_cluster_instancetype.py (1 hunks)
  • tests/test_resources/test_virtual_machine_cluster_preference.py (1 hunks)
  • tests/test_resources/test_virtual_machine_export.py (1 hunks)
  • tests/test_resources/test_virtual_machine_instance_migration.py (1 hunks)
  • tests/test_resources/test_virtual_machine_instance_preset.py (1 hunks)
  • tests/test_resources/test_virtual_machine_instance_replica_set.py (1 hunks)
  • tests/test_resources/test_virtual_machine_instancetype.py (1 hunks)
  • tests/test_resources/test_virtual_machine_preference.py (1 hunks)
  • tests/test_resources/test_volume_snapshot.py (1 hunks)
  • tests/test_resources/test_volume_snapshot_class.py (1 hunks)
🧰 Additional context used
🧠 Learnings (45)
README.md (3)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:9-10
Timestamp: 2024-10-09T14:23:46.600Z
Learning: In the file `class_generator/tests/manifests/ServingRuntime/serving_runtime.py`, the `ServingRuntime` class is auto-generated code. Do not request adding descriptions to docstrings when reviewing auto-generated code containing placeholders like "No field description from API; please add description."
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:96-160
Timestamp: 2024-10-09T14:25:49.618Z
Learning: The code in the `class_generator/tests/manifests/ServingRuntime/serving_runtime.py` file is auto-generated. Avoid suggesting refactoring changes to auto-generated code in this path.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2209
File: ocp_resources/volume_snapshot_class.py:0-0
Timestamp: 2024-12-03T08:02:11.880Z
Learning: In generated code files like `ocp_resources/volume_snapshot_class.py`, avoid suggesting adding validation checks or modifications, as generated code should not be manually altered.
ocp_resources/project_request.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2009
File: ocp_resources/project.py:77-91
Timestamp: 2024-08-10T21:52:00.488Z
Learning: In the `ProjectRequest` class, rely on the underlying API to handle validation errors for `description` and `display_name`.
tests/test_resources/test_project_config_openshift_io.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_snapshot.py (2)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2209
File: ocp_resources/volume_snapshot_class.py:0-0
Timestamp: 2024-12-03T08:02:11.880Z
Learning: In generated code files like `ocp_resources/volume_snapshot_class.py`, avoid suggesting adding validation checks or modifications, as generated code should not be manually altered.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_user_defined_network.py (4)
Learnt from: sbahar619
PR: RedHatQE/openshift-python-wrapper#2124
File: ocp_resources/user_defined_network.py:365-369
Timestamp: 2024-10-01T12:56:17.103Z
Learning: In `user_defined_network.py`, the `Layer3Subnets` class is defined before the `Layer3UserDefinedNetwork` class, so forward references in type annotations are not necessary.
Learnt from: sbahar619
PR: RedHatQE/openshift-python-wrapper#2124
File: ocp_resources/user_defined_network.py:365-369
Timestamp: 2024-10-08T23:43:22.342Z
Learning: In `user_defined_network.py`, the `Layer3Subnets` class is defined before the `Layer3UserDefinedNetwork` class, so forward references in type annotations are not necessary.
Learnt from: sbahar619
PR: RedHatQE/openshift-python-wrapper#2124
File: ocp_resources/user_defined_network.py:23-23
Timestamp: 2024-10-08T23:43:22.342Z
Learning: In the `UserDefinedNetwork` class, the `topology` parameter is intentionally left optional to facilitate testing scenarios where it is not set and to check the API's response.
Learnt from: sbahar619
PR: RedHatQE/openshift-python-wrapper#2124
File: ocp_resources/user_defined_network.py:23-23
Timestamp: 2024-09-26T07:32:43.266Z
Learning: In the `UserDefinedNetwork` class, the `topology` parameter is intentionally left optional to facilitate testing scenarios where it is not set and to check the API's response.
tests/test_resources/test_serving_runtime.py (5)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:9-10
Timestamp: 2024-10-09T14:23:46.600Z
Learning: In the file `class_generator/tests/manifests/ServingRuntime/serving_runtime.py`, the `ServingRuntime` class is auto-generated code. Do not request adding descriptions to docstrings when reviewing auto-generated code containing placeholders like "No field description from API; please add description."
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:96-160
Timestamp: 2024-10-09T14:25:49.618Z
Learning: The code in the `class_generator/tests/manifests/ServingRuntime/serving_runtime.py` file is auto-generated. Avoid suggesting refactoring changes to auto-generated code in this path.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2154
File: ocp_resources/serving_runtime.py:110-160
Timestamp: 2024-10-09T18:44:29.284Z
Learning: In `ocp_resources/serving_runtime.py`, the code is auto-generated and should not be manually modified.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2154
File: ocp_resources/serving_runtime.py:16-32
Timestamp: 2024-10-09T18:44:30.628Z
Learning: The file `ocp_resources/serving_runtime.py` is auto-generated code.
Learnt from: tarukumar
PR: RedHatQE/openshift-python-wrapper#2151
File: ocp_resources/serving_runtime.py:130-134
Timestamp: 2024-10-09T13:40:48.030Z
Learning: In the `ServingRuntime` class in `ocp_resources/serving_runtime.py`, the `nodeSelector` key is correctly used in camelCase within the `_spec` dictionary. Avoid flagging this as an issue in future reviews.
tests/test_resources/test_authorino.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_self_subject_review.py (2)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:9-10
Timestamp: 2024-10-09T14:23:46.600Z
Learning: In the file `class_generator/tests/manifests/ServingRuntime/serving_runtime.py`, the `ServingRuntime` class is auto-generated code. Do not request adding descriptions to docstrings when reviewing auto-generated code containing placeholders like "No field description from API; please add description."
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_machine.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_direct_volume_migration.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2209
File: ocp_resources/volume_snapshot_class.py:0-0
Timestamp: 2024-12-03T08:02:11.880Z
Learning: In generated code files like `ocp_resources/volume_snapshot_class.py`, avoid suggesting adding validation checks or modifications, as generated code should not be manually altered.
tests/test_resources/test_storage_cluster.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_console_config_openshift_io.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_node_config_openshift_io.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_mig_cluster.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_scheduler.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_group.py (2)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2131
File: tests/test_api_group_order.py:21-26
Timestamp: 2024-09-29T13:38:14.766Z
Learning: In the `test_api_group_order`, the implementation intentionally adds only the diffs to the `errors` set, as this is the desired behavior.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2131
File: tests/test_api_group_order.py:21-26
Timestamp: 2024-10-08T23:43:22.342Z
Learning: In the `test_api_group_order`, the implementation intentionally adds only the diffs to the `errors` set, as this is the desired behavior.
tests/test_resources/test_model_registry_modelregistry_opendatahub_io.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_deployment.py (2)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2235
File: ocp_resources/resource.py:634-634
Timestamp: 2024-12-16T11:42:49.731Z
Learning: In `ocp_resources/resource.py`, the `deploy` method in the `Resource` class cannot have a return type of `Resource` because each subclass has its own specific return type, and it's not `Resource`.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_prometheus.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_mig_plan.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_aaq.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_model_registry_components_platform_opendatahub_io.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_replica_set.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_kubelet_config.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_volume_snapshot_class.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2209
File: ocp_resources/volume_snapshot_class.py:0-0
Timestamp: 2024-12-03T08:02:11.880Z
Learning: In generated code files like `ocp_resources/volume_snapshot_class.py`, avoid suggesting adding validation checks or modifications, as generated code should not be manually altered.
tests/test_resources/test_data_science_cluster.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_pod_metrics.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_direct_volume_migration_progress.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2209
File: ocp_resources/volume_snapshot_class.py:0-0
Timestamp: 2024-12-03T08:02:11.880Z
Learning: In generated code files like `ocp_resources/volume_snapshot_class.py`, avoid suggesting adding validation checks or modifications, as generated code should not be manually altered.
tests/test_resources/test_maria_db.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2171
File: ocp_resources/mariadb_operator.py:90-140
Timestamp: 2024-10-15T13:51:36.142Z
Learning: In `ocp_resources/mariadb_operator.py`, the `to_dict` method in the `MariadbOperator` class is intentionally kept in its current form for better readability, and should not be refactored to reduce repetition.
tests/test_resources/test_node_network_configuration_policy_latest.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_console_operator_openshift_io.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_service_serving_knative_dev.py (2)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:96-160
Timestamp: 2024-10-09T14:25:49.618Z
Learning: The code in the `class_generator/tests/manifests/ServingRuntime/serving_runtime.py` file is auto-generated. Avoid suggesting refactoring changes to auto-generated code in this path.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:9-10
Timestamp: 2024-10-09T14:23:46.600Z
Learning: In the file `class_generator/tests/manifests/ServingRuntime/serving_runtime.py`, the `ServingRuntime` class is auto-generated code. Do not request adding descriptions to docstrings when reviewing auto-generated code containing placeholders like "No field description from API; please add description."
tests/test_resources/test_virtual_machine_cluster_instancetype.py (2)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2013
File: ocp_resources/virtual_machine_instancetype.py:16-28
Timestamp: 2024-08-11T10:25:20.750Z
Learning: In the `VirtualMachineInstancetype` class, the code relies on the underlying API to handle type validation errors, rather than performing validation within the constructor.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2013
File: ocp_resources/virtual_machine_instancetype.py:16-28
Timestamp: 2024-10-08T23:43:22.342Z
Learning: In the `VirtualMachineInstancetype` class, the code relies on the underlying API to handle type validation errors, rather than performing validation within the constructor.
tests/test_resources/test_kube_descheduler.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_project_request.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2009
File: ocp_resources/project.py:77-91
Timestamp: 2024-08-10T21:52:00.488Z
Learning: In the `ProjectRequest` class, rely on the underlying API to handle validation errors for `description` and `display_name`.
tests/test_resources/test_pod.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resource.py (2)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
Learnt from: EdDev
PR: RedHatQE/openshift-python-wrapper#2291
File: ocp_resources/resource.py:126-126
Timestamp: 2025-01-28T07:25:19.573Z
Learning: The environment variable `OPENSHIFT_PYTHON_WRAPPER_CLIENT_USE_PROXY` must be set and not empty to override the `use_proxy` parameter in the `get_client` function.
tests/test_resources/test_project_project_openshift_io.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_cluster_resource_quota.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/test_resources/test_volume_snapshot.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2209
File: ocp_resources/volume_snapshot_class.py:0-0
Timestamp: 2024-12-03T08:02:11.880Z
Learning: In generated code files like `ocp_resources/volume_snapshot_class.py`, avoid suggesting adding validation checks or modifications, as generated code should not be manually altered.
tests/test_resources/test_mariadb_operator.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2171
File: ocp_resources/mariadb_operator.py:90-140
Timestamp: 2024-10-15T13:51:36.142Z
Learning: In `ocp_resources/mariadb_operator.py`, the `to_dict` method in the `MariadbOperator` class is intentionally kept in its current form for better readability, and should not be refactored to reduce repetition.
tests/test_resources/test_virtual_machine_instancetype.py (2)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2013
File: ocp_resources/virtual_machine_instancetype.py:16-28
Timestamp: 2024-08-11T10:25:20.750Z
Learning: In the `VirtualMachineInstancetype` class, the code relies on the underlying API to handle type validation errors, rather than performing validation within the constructor.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2013
File: ocp_resources/virtual_machine_instancetype.py:16-28
Timestamp: 2024-10-08T23:43:22.342Z
Learning: In the `VirtualMachineInstancetype` class, the code relies on the underlying API to handle type validation errors, rather than performing validation within the constructor.
tests/test_resources/test_node.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/scripts/generate_pytest_test.py (5)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2209
File: ocp_resources/volume_snapshot_class.py:0-0
Timestamp: 2024-12-03T08:02:11.880Z
Learning: In generated code files like `ocp_resources/volume_snapshot_class.py`, avoid suggesting adding validation checks or modifications, as generated code should not be manually altered.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:9-10
Timestamp: 2024-10-09T14:23:46.600Z
Learning: In the file `class_generator/tests/manifests/ServingRuntime/serving_runtime.py`, the `ServingRuntime` class is auto-generated code. Do not request adding descriptions to docstrings when reviewing auto-generated code containing placeholders like "No field description from API; please add description."
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:96-160
Timestamp: 2024-10-09T14:25:49.618Z
Learning: The code in the `class_generator/tests/manifests/ServingRuntime/serving_runtime.py` file is auto-generated. Avoid suggesting refactoring changes to auto-generated code in this path.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2154
File: ocp_resources/serving_runtime.py:16-32
Timestamp: 2024-10-09T18:44:30.628Z
Learning: The file `ocp_resources/serving_runtime.py` is auto-generated code.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2154
File: ocp_resources/serving_runtime.py:110-160
Timestamp: 2024-10-09T18:44:29.284Z
Learning: In `ocp_resources/serving_runtime.py`, the code is auto-generated and should not be manually modified.
fake_kubernetes_client/fake_dynamic_client.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
🧬 Code Graph Analysis (26)
ocp_resources/project_request.py (1)
ocp_resources/resource.py (1)
  • Resource (436-1429)
tests/test_resources/test_operator.py (3)
fake_kubernetes_client/fake_dynamic_client.py (1)
  • FakeDynamicClient (1298-1503)
ocp_resources/operator.py (1)
  • Operator (7-20)
ocp_resources/resource.py (3)
  • exists (918-925)
  • kind (671-672)
  • labels (1158-1165)
tests/test_resources/test_machine.py (3)
fake_kubernetes_client/fake_dynamic_client.py (1)
  • FakeDynamicClient (1298-1503)
tests/test_resource.py (2)
  • client (25-26)
  • namespace (30-31)
ocp_resources/resource.py (3)
  • exists (918-925)
  • kind (671-672)
  • labels (1158-1165)
tests/test_resources/test_direct_volume_migration.py (2)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
ocp_resources/direct_volume_migration.py (1)
  • DirectVolumeMigration (9-139)
tests/test_resources/test_storage_cluster.py (4)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
ocp_resources/storage_cluster.py (1)
  • StorageCluster (9-287)
tests/test_resource.py (4)
  • client (25-26)
  • namespace (30-31)
  • deploy (17-18)
  • clean_up (20-21)
ocp_resources/resource.py (2)
  • exists (918-925)
  • labels (1158-1165)
tests/test_resources/test_llama_stack_distribution.py (2)
test_utils/fake_dynamic_client.py (2)
  • FakeDynamicClient (1134-1295)
  • to_dict (145-147)
ocp_resources/llama_stack_distribution.py (1)
  • LlamaStackDistribution (9-49)
tests/test_resources/test_scheduler.py (4)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
ocp_resources/scheduler.py (1)
  • Scheduler (7-93)
tests/test_resource.py (3)
  • client (25-26)
  • deploy (17-18)
  • clean_up (20-21)
ocp_resources/resource.py (3)
  • exists (918-925)
  • kind (671-672)
  • labels (1158-1165)
fake_kubernetes_client/__init__.py (1)
fake_kubernetes_client/fake_dynamic_client.py (7)
  • FakeDynamicClient (1298-1503)
  • create_fake_client_with_resources (1509-1513)
  • create_fake_client_with_custom_resources (1516-1521)
  • FakeResourceField (101-203)
  • FakeResourceInstance (206-671)
  • FakeResourceRegistry (674-1084)
  • FakeResourceStorage (1087-1270)
tests/test_resources/test_deployment.py (3)
test_utils/fake_dynamic_client.py (1)
  • FakeDynamicClient (1134-1295)
tests/test_resource.py (2)
  • client (25-26)
  • namespace (30-31)
ocp_resources/resource.py (3)
  • exists (918-925)
  • kind (671-672)
  • labels (1158-1165)
tests/test_resources/test_namespace.py (3)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
ocp_resources/namespace.py (1)
  • Namespace (7-40)
ocp_resources/resource.py (3)
  • exists (918-925)
  • kind (671-672)
  • labels (1158-1165)
tests/test_resources/test_service.py (4)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
tests/test_resources/test_service_serving_knative_dev.py (2)
  • service (12-19)
  • TestService (6-44)
ocp_resources/service.py (1)
  • Service (7-386)
ocp_resources/resource.py (2)
  • exists (918-925)
  • labels (1158-1165)
tests/test_resources/test_aaq.py (4)
test_utils/fake_dynamic_client.py (2)
  • FakeDynamicClient (1134-1295)
  • to_dict (145-147)
ocp_resources/aaq.py (1)
  • AAQ (7-82)
tests/test_resource.py (3)
  • client (25-26)
  • deploy (17-18)
  • clean_up (20-21)
ocp_resources/resource.py (3)
  • exists (918-925)
  • kind (671-672)
  • labels (1158-1165)
tests/test_resources/test_user.py (2)
test_utils/fake_dynamic_client.py (2)
  • FakeDynamicClient (1134-1295)
  • to_dict (145-147)
ocp_resources/user.py (1)
  • User (9-57)
tests/test_resources/test_kubelet_config.py (4)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
ocp_resources/kubelet_config.py (1)
  • KubeletConfig (9-82)
tests/test_resource.py (3)
  • client (25-26)
  • deploy (17-18)
  • clean_up (20-21)
ocp_resources/resource.py (3)
  • exists (918-925)
  • kind (671-672)
  • labels (1158-1165)
tests/test_resources/test_dns_operator_openshift_io.py (4)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
tests/test_resources/test_dns_config_openshift_io.py (7)
  • TestDNS (6-41)
  • client (8-9)
  • dns (12-16)
  • test_create_dns (18-23)
  • test_get_dns (25-28)
  • test_update_dns (30-35)
  • test_delete_dns (37-41)
tests/test_resource.py (3)
  • client (25-26)
  • deploy (17-18)
  • clean_up (20-21)
ocp_resources/resource.py (3)
  • exists (918-925)
  • kind (671-672)
  • labels (1158-1165)
tests/test_resources/test_mig_analytic.py (4)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
ocp_resources/mig_analytic.py (1)
  • MigAnalytic (9-121)
tests/test_resource.py (4)
  • client (25-26)
  • namespace (30-31)
  • deploy (17-18)
  • clean_up (20-21)
ocp_resources/resource.py (3)
  • exists (918-925)
  • kind (671-672)
  • labels (1158-1165)
tests/test_resources/test_data_science_cluster.py (3)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
ocp_resources/data_science_cluster.py (1)
  • DataScienceCluster (7-38)
ocp_resources/resource.py (3)
  • exists (918-925)
  • kind (671-672)
  • labels (1158-1165)
tests/test_resources/test_maria_db.py (3)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
ocp_resources/maria_db.py (1)
  • MariaDB (7-462)
tests/test_resource.py (4)
  • client (25-26)
  • namespace (30-31)
  • deploy (17-18)
  • clean_up (20-21)
tests/test_resources/test_mtq.py (2)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
ocp_resources/mtq.py (1)
  • MTQ (7-110)
tests/test_resources/test_kube_descheduler.py (2)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
ocp_resources/kube_descheduler.py (1)
  • KubeDescheduler (7-111)
tests/test_resources/test_virtual_machine_cluster_preference.py (4)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
ocp_resources/virtual_machine_cluster_preference.py (1)
  • VirtualMachineClusterPreference (7-126)
tests/test_resource.py (3)
  • client (25-26)
  • deploy (17-18)
  • clean_up (20-21)
ocp_resources/resource.py (3)
  • exists (918-925)
  • kind (671-672)
  • labels (1158-1165)
tests/test_resource.py (4)
ocp_resources/resource.py (1)
  • Resource (436-1429)
test_utils/fake_dynamic_client.py (3)
  • FakeDynamicClient (1134-1295)
  • patch (496-538)
  • patch (1195-1200)
tests/test_resources/test_aaq.py (1)
  • client (8-9)
tests/test_resources/test_namespace.py (1)
  • namespace (12-16)
tests/test_resources/test_virtual_machine_preference.py (2)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
ocp_resources/virtual_machine_preference.py (1)
  • VirtualMachinePreference (7-126)
tests/test_resources/test_project_project_openshift_io.py (4)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
tests/test_resources/test_project_config_openshift_io.py (6)
  • TestProject (6-41)
  • project (12-16)
  • test_create_project (18-23)
  • test_get_project (25-28)
  • test_update_project (30-35)
  • test_delete_project (37-41)
ocp_resources/resource.py (3)
  • exists (918-925)
  • kind (671-672)
  • labels (1158-1165)
ocp_resources/project_request.py (2)
  • to_dict (36-44)
  • clean_up (48-49)
tests/test_resources/test_lm_eval_job.py (3)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1298-1503)
  • to_dict (174-176)
ocp_resources/lm_eval_job.py (1)
  • LMEvalJob (8-156)
tests/test_resource.py (4)
  • client (25-26)
  • namespace (30-31)
  • deploy (17-18)
  • clean_up (20-21)
tests/test_resources/test_notebook.py (2)
test_utils/fake_dynamic_client.py (2)
  • FakeDynamicClient (1134-1295)
  • to_dict (145-147)
ocp_resources/notebook.py (1)
  • Notebook (9-37)
🪛 LanguageTool
fake_kubernetes_client/README.md

[misspelling] ~141-~141: This word is normally spelled as one.
Context: ... # → Generates "Deleted" event ``` ### Pre-loading Test Data Load multiple resources at o...

(EN_COMPOUNDS_PRE_LOADING)

🪛 markdownlint-cli2 (0.17.2)
fake_kubernetes_client/README.md

257-257: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🪛 Pylint (3.3.7)
test_utils/fake_dynamic_client.py

[refactor] 107-114: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 118-125: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 423-464: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 468-494: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 600-600: Either all return statements in a function should return an expression, or none of them should.

(R1710)


[refactor] 811-811: Too many arguments (6/5)

(R0913)


[refactor] 811-811: Too many positional arguments (6/5)

(R0917)


[refactor] 947-947: Too many arguments (6/5)

(R0913)


[refactor] 947-947: Too many positional arguments (6/5)

(R0917)


[refactor] 958-963: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 967-972: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 974-974: Too many arguments (6/5)

(R0913)


[refactor] 974-974: Too many positional arguments (6/5)

(R0917)


[refactor] 1040-1040: Too many branches (13/12)

(R0912)


[refactor] 1109-1109: Too few public methods (0/2)

(R0903)


[refactor] 1119-1119: Too few public methods (1/2)

(R0903)


[refactor] 1176-1179: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1183-1186: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1190-1193: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1197-1200: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1204-1207: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1211-1214: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1291-1295: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)

tests/scripts/generate_pytest_test.py

[refactor] 55-55: Too many instance attributes (8/7)

(R0902)


[refactor] 206-222: Too many nested blocks (9/5)

(R1702)


[refactor] 80-80: Too few public methods (1/2)

(R0903)


[refactor] 269-269: Too few public methods (1/2)

(R0903)


[refactor] 357-357: Too many branches (24/12)

(R0912)


[refactor] 357-357: Too many statements (53/50)

(R0915)


[refactor] 326-326: Too few public methods (1/2)

(R0903)


[refactor] 557-557: Too many local variables (26/15)

(R0914)


[refactor] 557-557: Too many branches (20/12)

(R0912)


[refactor] 557-557: Too many statements (69/50)

(R0915)


[error] 677-677: No value for argument 'kind' in function call

(E1120)


[error] 677-677: No value for argument 'check_coverage' in function call

(E1120)


[error] 677-677: No value for argument 'generate_missing' in function call

(E1120)


[error] 677-677: No value for argument 'dry_run' in function call

(E1120)

fake_kubernetes_client/fake_dynamic_client.py

[refactor] 136-143: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 119-119: Too many return statements (8/6)

(R0911)


[refactor] 147-154: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 508-541: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 545-561: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 662-662: Either all return statements in a function should return an expression, or none of them should.

(R1710)


[refactor] 685-692: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 708-708: Too many local variables (16/15)

(R0914)


[refactor] 802-802: Too many arguments (6/5)

(R0913)


[refactor] 802-802: Too many positional arguments (6/5)

(R0917)


[refactor] 827-827: Too many local variables (18/15)

(R0914)


[refactor] 827-827: Too many return statements (8/6)

(R0911)


[refactor] 827-827: Too many branches (18/12)

(R0912)


[refactor] 921-921: Too many branches (16/12)

(R0912)


[refactor] 1104-1104: Too many arguments (6/5)

(R0913)


[refactor] 1104-1104: Too many positional arguments (6/5)

(R0917)


[refactor] 1115-1120: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1124-1129: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1131-1131: Too many arguments (6/5)

(R0913)


[refactor] 1131-1131: Too many positional arguments (6/5)

(R0917)


[refactor] 1200-1200: Too many branches (14/12)

(R0912)


[refactor] 1273-1273: Too few public methods (0/2)

(R0903)


[refactor] 1283-1283: Too few public methods (1/2)

(R0903)


[refactor] 1384-1387: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1391-1394: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1398-1401: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1405-1408: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1412-1415: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1419-1422: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1499-1503: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1527-1527: Too many local variables (17/15)

(R0914)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: tox
  • GitHub Check: conventional-title
  • GitHub Check: python-module-install
🔇 Additional comments (75)
ocp_resources/project_request.py (1)

49-49: LGTM - Proper client context passing.

The addition of client=self.client ensures that the Project instance created for cleanup uses the same client context as the ProjectRequest instance, which is essential for proper resource management and consistent behavior across different client implementations (including the new FakeDynamicClient).

README.md (1)

120-150: Excellent documentation for the new testing workflow.

The new section clearly explains how to generate and run automated tests for resource classes using the test generator script and fake client. The examples are practical and the note about generated tests being only for class-generator created resources is important context.

tests/test_resources/test_dsc_initialization.py (1)

1-43: Well-structured test suite following pytest best practices.

The test implementation correctly uses FakeDynamicClient for isolated testing and covers the essential CRUD operations. The use of class-scoped fixtures is appropriate, and the assertions properly validate resource behavior. The comment about fake client behavior vs real cluster behavior is helpful for understanding the testing environment.

tests/test_resources/test_operator.py (1)

1-42: Consistent test implementation following established patterns.

The test suite correctly implements the standard resource testing pattern using FakeDynamicClient and covers all essential CRUD operations. The consistent structure across resource tests facilitates maintainability and aligns with the automated test generation approach documented in the README.

tests/test_resources/test_project_config_openshift_io.py (1)

1-42: Consistent and comprehensive test coverage for Project resource.

The test suite maintains the established pattern for resource testing and properly validates the Project resource lifecycle using FakeDynamicClient. The implementation is clean, follows pytest best practices, and provides good test coverage for the essential operations.

tests/test_resources/test_cdi.py (1)

7-16: Same test design pattern as other resource tests.

This follows the same pattern as the other resource test files with class-scoped fixtures creating test interdependencies.

The test structure is consistent with the established pattern for this test suite.

tests/test_resources/test_node_config_openshift_io.py (1)

1-42: Well-structured test suite following pytest best practices.

The test implementation is clean and follows the established pattern for resource lifecycle testing. The use of class-scoped fixtures and systematic CRUD testing provides good coverage for the Node resource.

tests/test_resources/test_kubelet_config.py (1)

1-42: Consistent test implementation with appropriate fixture setup.

The test suite correctly implements the standard pattern for resource lifecycle testing. The minimal parameter setup in the fixture is appropriate for testing basic CRUD operations.

tests/test_resources/test_dns_config_openshift_io.py (1)

1-42: Consistent implementation maintaining established testing patterns.

The test suite follows the standardized pattern for resource lifecycle testing, ensuring consistency across the test suite.

tests/test_resources/test_console_config_openshift_io.py (1)

1-42: Properly implemented test suite following established patterns.

The test implementation correctly follows the standardized approach for resource lifecycle testing, maintaining consistency across the test suite.

tests/test_resources/test_mig_cluster.py (1)

1-44: Well-implemented test suite with comprehensive parameter coverage.

The test suite follows the established pattern while appropriately including additional parameters specific to the MigCluster resource. The structure and test logic are correct.

tests/test_resources/test_group.py (4)

19-24: LGTM - Comprehensive resource creation testing.

The create test properly verifies resource deployment, name assignment, and existence. The assertions cover the essential aspects of resource creation.


26-29: LGTM - Appropriate instance and kind verification.

The get test correctly validates resource retrieval and kind identification, ensuring the resource can be accessed and has the expected type.


31-36: LGTM - Proper update workflow testing.

The update test follows the correct pattern of retrieving the resource dictionary, modifying labels, applying the update, and verifying the changes were persisted.


38-43: LGTM - Appropriate cleanup testing with fake client note.

The delete test correctly calls cleanup and includes a helpful comment explaining the fake client's immediate deletion behavior, which differs from real cluster behavior.

tests/test_resources/test_image_image_openshift_io.py (1)

18-42: LGTM - Comprehensive CRUD lifecycle testing.

The test suite properly covers all essential operations (create, get, update, delete) with appropriate assertions for each phase. The structure is consistent and follows testing best practices for resource lifecycle management.

tests/test_resources/test_ssp.py (1)

20-44: LGTM - Thorough SSP resource lifecycle testing.

The test suite comprehensively covers CRUD operations with proper assertions. The namespace and common_templates parameters in the SSP constructor are appropriate for this resource type.

tests/test_resources/test_namespace.py (1)

18-42: LGTM - Appropriate Namespace lifecycle testing.

The test suite covers essential CRUD operations for Namespace resources. The minimal constructor usage (name only) is appropriate for basic testing, even though the Namespace class supports additional parameters like finalizers.

tests/test_resources/test_dns_operator_openshift_io.py (1)

18-42: LGTM - Comprehensive DNS resource testing.

The test suite properly covers CRUD operations for the DNS resource from the dns_operator_openshift_io module. The import is correct and distinct from similar DNS resources in other modules.

tests/test_resources/test_config_map.py (1)

1-44: LGTM! Well-structured test suite for ConfigMap resource.

The test suite follows the established pattern for resource testing with proper fixtures, comprehensive CRUD operations, and appropriate assertions. The use of FakeDynamicClient enables isolated testing without requiring a real cluster.

tests/test_resources/test_service_serving_knative_dev.py (1)

1-45: LGTM! Well-structured test suite for Knative Service resource.

The test suite properly configures the Knative Service with template and traffic parameters, following the established testing pattern. The use of FakeDynamicClient enables comprehensive lifecycle testing without cluster dependency.

tests/test_resources/test_self_subject_review.py (1)

1-42: LGTM! Well-structured test suite for SelfSubjectReview resource.

The test suite follows the established pattern with proper fixtures and comprehensive CRUD operations. The minimal configuration for SelfSubjectReview is appropriate, and the use of FakeDynamicClient enables isolated testing.

tests/test_resources/test_cdi_config.py (1)

1-42: Well-structured test suite with comprehensive coverage.

The test suite follows excellent practices:

  • Class-scoped fixtures appropriately share resources across tests
  • Comprehensive CRUD operation coverage (create, get, update, delete)
  • Clear test documentation with descriptive method names
  • Proper assertions verifying expected behavior
  • Good use of the FakeDynamicClient for isolated testing
tests/test_resources/test_service.py (2)

12-19: Excellent Service configuration with realistic parameters.

The Service fixture properly configures essential Service parameters:

  • Port mapping (port 80 → target_port 8080)
  • Selector for pod targeting ({"app": "test"})
  • Proper namespace specification

This provides a comprehensive test setup that closely mirrors real-world Service usage.


21-44: Comprehensive CRUD test coverage for Service resource.

The test methods effectively cover the complete Service lifecycle with appropriate assertions for each operation. The consistent structure across all test methods makes the suite maintainable and predictable.

tests/test_resources/test_serving_runtime.py (2)

12-18: Proper ServingRuntime configuration with required parameters.

The ServingRuntime fixture correctly includes the required containers parameter, ensuring the resource can be properly instantiated and tested.


20-43: Consistent CRUD test coverage matching established pattern.

The test methods maintain the same structure and coverage as other resource test files, providing predictable and maintainable test patterns across the codebase.

tests/test_resources/test_lm_eval_job.py (2)

12-19: Correctly configured LMEvalJob with required parameters.

The LMEvalJob fixture properly includes the required parameters:

  • model: "test-model"
  • task_list: "test-task_list"

This ensures the resource meets the validation requirements from the LMEvalJob class implementation.


21-44: Comprehensive test coverage following established pattern.

The test suite maintains consistency with other resource test files while providing complete CRUD operation coverage for the LMEvalJob resource.

fake_kubernetes_client/__init__.py (2)

1-24: Excellent package documentation with comprehensive feature overview.

The package docstring effectively communicates:

  • Clear purpose and use case
  • Comprehensive feature list covering all major capabilities
  • Practical usage example
  • Professional documentation standards

26-47: Proper package structure following Python best practices.

The package initialization demonstrates excellent practices:

  • Clean imports from implementation module
  • Controlled exports via __all__ for API stability
  • Version management with semantic versioning
  • Clear separation of concerns
tests/test_resources/test_replica_set.py (1)

11-18: Appropriate ReplicaSet configuration with selector

The ReplicaSet fixture correctly includes the selector parameter with matchLabels, which is required for ReplicaSet resources to define which pods it manages.

tests/test_resources/test_deployment.py (1)

11-23: Comprehensive Deployment configuration

The Deployment fixture includes all necessary parameters:

  • selector with matchLabels for pod selection
  • template with proper metadata labels and container specification
  • replicas count

This configuration correctly represents a typical Deployment resource structure.

tests/test_resources/test_guardrails_orchestrator.py (1)

17-18: Resource-specific parameters configured correctly.

The GuardrailsOrchestrator fixture includes appropriate resource-specific parameters (orchestrator_config and replicas).

tests/test_resources/test_volume_snapshot_class.py (2)

7-18: Generated test structure follows established pattern.

The test structure and class-scoped fixtures are consistent with the established pattern for generated resource tests. While function-scoped fixtures might provide better isolation, the current approach maintains consistency across all generated test files.


16-17: Resource-specific parameters configured correctly.

The VolumeSnapshotClass fixture includes appropriate resource-specific parameters (deletion_policy and driver).

tests/test_resources/test_network_operator_openshift_io.py (1)

1-42: Consistent implementation across all resource test files.

This test file follows the exact same pattern as all other resource test files in this PR, maintaining consistency in the generated test framework. The structure is well-organized and provides comprehensive CRUD testing for the Network resource.

tests/test_resources/test_service_mesh_member.py (1)

1-44: Well-structured test suite with comprehensive CRUD coverage.

The test implementation follows good practices:

  • Appropriate use of class-scoped fixtures for shared resources
  • Complete lifecycle testing (create, get, update, delete)
  • Clear assertions that verify expected behavior
  • Helpful comments about fake client behavior differences

The test structure is consistent and maintainable.

tests/test_resources/test_llama_stack_distribution.py (1)

1-44: Good test structure overall.

The test follows the established CRUD pattern and uses appropriate fixtures. Once the server parameter type is fixed, this will be a solid test suite.

tests/test_resources/test_image_config_openshift_io.py (1)

1-42: Clean and well-structured test implementation.

The test suite follows the established pattern with proper:

  • Import statements and fixture setup
  • Complete CRUD lifecycle coverage
  • Clear assertions and meaningful test names
  • Helpful documentation comments

The implementation is solid and maintainable.

tests/test_resources/test_csi_driver.py (1)

1-42: Excellent test implementation following established patterns.

The test suite demonstrates good practices:

  • Proper fixture scoping for resource testing
  • Comprehensive CRUD operations coverage
  • Clear and descriptive test methods
  • Meaningful assertions that verify expected behavior
  • Valuable comments about fake client characteristics

The code is well-structured and maintainable.

tests/test_resources/test_project_request.py (1)

1-42: Consistent and well-implemented test suite.

The test follows the established pattern with:

  • Appropriate fixture setup and scoping
  • Complete CRUD lifecycle testing
  • Clear test documentation and assertions
  • Consistent structure with other resource tests

The implementation aligns well with the overall testing framework.

tests/test_resources/test_pod.py (1)

1-44: Excellent test structure and coverage!

The test suite follows pytest best practices with class-scoped fixtures and covers all essential CRUD operations. The Pod configuration with nginx container is realistic and the assertions properly verify resource state transitions.

tests/test_resources/test_data_science_cluster.py (1)

12-16: Correct namespace handling for cluster-scoped resource.

The DataScienceCluster fixture correctly omits the namespace parameter since this appears to be a cluster-scoped resource based on its inheritance from the base Resource class rather than NamespacedResource.

tests/test_resources/test_nm_state.py (1)

1-42: Consistent test implementation following established patterns.

The test suite maintains consistency with other resource test files and correctly handles the NMState resource lifecycle. The structure and assertions are appropriate for testing cluster-scoped resources.

tests/test_resources/test_kube_descheduler.py (1)

12-17: Correct namespace handling for namespaced resource.

The KubeDescheduler fixture properly specifies the namespace parameter since this resource extends NamespacedResource, demonstrating appropriate understanding of the resource's scope requirements.

tests/test_resources/test_kubevirt.py (2)

1-43: Well-structured test suite with proper resource scoping.

The test implementation correctly handles the KubeVirt resource as a namespaced resource and follows the established testing patterns. The class-scoped fixtures and comprehensive CRUD test coverage provide good validation of the resource lifecycle.


1-1: Excellent systematic approach to resource testing.

These test files demonstrate a well-designed, consistent testing framework that appropriately handles both namespaced and cluster-scoped Kubernetes resources. The use of the FakeDynamicClient enables isolated unit testing without cluster dependencies, while the standardized test structure ensures comprehensive CRUD coverage across all resource types.

tests/test_resources/test_node.py (1)

1-42: LGTM! Well-structured test suite for Node resource.

This test suite follows excellent pytest practices with appropriate class-scoped fixtures and comprehensive CRUD testing. The Node resource is correctly handled as a cluster-scoped resource (no namespace parameter), and the test assertions properly verify each lifecycle operation.

tests/test_resources/test_model_registry.py (1)

1-45: LGTM! Proper test coverage for ModelRegistry resource.

The test suite correctly handles the ModelRegistry as a namespaced resource with appropriate resource-specific parameters (grpc, rest). The fixture setup and test methods provide comprehensive coverage of the resource lifecycle operations.

tests/test_resources/test_inference_graph.py (1)

1-44: LGTM! Comprehensive test suite for InferenceGraph resource.

The test suite properly handles the InferenceGraph as a namespaced resource with the appropriate nodes parameter. The fixture setup and CRUD test methods provide excellent coverage of the resource lifecycle operations.

tests/test_resources/test_node_network_configuration_policy_latest.py (1)

1-42: LGTM! Appropriate test coverage for NodeNetworkConfigurationPolicy resource.

The test suite correctly handles the NodeNetworkConfigurationPolicy as a cluster-scoped resource (no namespace parameter). The fixture setup and test methods provide comprehensive coverage of the resource lifecycle operations with proper assertions.

tests/test_resources/test_direct_volume_migration_progress.py (1)

1-43: LGTM! Well-implemented test suite for DirectVolumeMigrationProgress resource.

The test suite properly handles the DirectVolumeMigrationProgress as a namespaced resource. The fixture setup and CRUD test methods provide excellent coverage of the resource lifecycle operations with appropriate assertions throughout.

tests/test_resource.py (5)

13-13: LGTM: Clean integration of fake client.

The import of FakeDynamicClient is properly added to support the new testing infrastructure.


25-26: Excellent migration to fake client.

The fixture replacement from real K8s client to FakeDynamicClient() simplifies testing by eliminating external dependencies while maintaining the same interface.


36-46: Well-implemented pod fixture with proper lifecycle management.

The pod fixture correctly creates a test pod explicitly and handles cleanup properly. The deployment and cleanup pattern aligns with the fake client's immediate operation behavior.


124-124: Appropriate test method signature update.

The test method correctly uses the client fixture instead of the removed k3scontainer_config fixture.


131-131: Consistent fixture usage update.

The proxy precedence test is properly updated to use the client fixture, maintaining test functionality with the fake client.

tests/test_resources/test_volume_snapshot.py (2)

20-26: LGTM: Proper resource creation test.

The test correctly verifies deployment, naming, and existence of the VolumeSnapshot resource.


32-38: No dependent label assertions found in subsequent tests

I inspected the rest of tests/test_resources/test_volume_snapshot.py and the only test after test_update_volumesnapshot is:

def test_delete_volumesnapshot(self, volumesnapshot):
    """Test deleting VolumeSnapshot"""
    volumesnapshot.clean_up(wait=False)
    # Note: In real clusters, you might want to verify deletion

It doesn’t inspect or assert on any label values, so mutating the labels in the update test won’t break it.

tests/test_resources/test_image_content_source_policy.py (1)

18-24: LGTM: Proper resource creation test.

The test correctly verifies deployment, naming, and existence of the ImageContentSourcePolicy resource.

tests/test_resources/test_image_caching_internal_knative_dev.py (1)

20-26: LGTM: Proper resource creation test.

The test correctly verifies deployment, naming, and existence of the Image resource.

tests/test_resources/test_prometheus.py (1)

19-25: LGTM: Proper resource creation test.

The test correctly verifies deployment, naming, and existence of the Prometheus resource.

tests/test_resources/test_virtual_machine_export.py (1)

1-44: LGTM: Well-structured test suite for VirtualMachineExport

The test suite follows a clean, consistent pattern with appropriate fixtures and comprehensive CRUD testing. The use of FakeDynamicClient enables isolated testing without cluster dependencies, and the resource configuration with source parameter is appropriate for VirtualMachineExport.

tests/test_resources/test_api_server.py (1)

1-42: LGTM: Clean and appropriate APIServer test

The test suite correctly handles APIServer as a cluster-scoped resource with minimal required configuration. The CRUD test pattern is consistent and the use of FakeDynamicClient enables reliable isolated testing.

tests/test_resources/test_virtual_machine_preference.py (1)

1-43: LGTM: Clean test suite for VirtualMachinePreference

The test suite uses a minimal but appropriate configuration for VirtualMachinePreference, focusing on basic CRUD operations. The simple setup with just name and namespace is sufficient for testing core functionality without unnecessary complexity.

tests/test_resources/test_virtual_machine_cluster_preference.py (4)

18-24: LGTM - Good basic resource creation test.

The test properly validates resource deployment and existence checks.


25-28: LGTM - Proper instance and kind validation.

The test correctly verifies resource retrieval and kind matching.


30-35: LGTM - Effective update operation test.

The test properly demonstrates label updating and verification functionality.


37-42: LGTM - Clear deletion test with helpful documentation.

The test properly exercises the cleanup functionality, and the comment clearly explains the fake client behavior differences.

tests/test_resources/test_cluster_user_defined_network.py (1)

20-44: LGTM - Comprehensive CRUD test coverage.

The test methods properly cover all lifecycle operations with appropriate assertions and clear documentation.

tests/test_resources/test_cluster_resource_quota.py (1)

20-44: LGTM - Standard CRUD test implementation.

The test methods follow the established pattern and provide adequate coverage for basic resource operations.

tests/test_resources/test_notebook.py (1)

19-43: LGTM - Standard CRUD test implementation.

The test methods follow the established pattern and provide adequate coverage for basic resource operations.

tests/test_resources/test_virtual_machine_instance_preset.py (1)

20-44: LGTM - Complete CRUD test coverage.

The test methods properly implement all lifecycle operations with appropriate assertions and clear documentation.

fake_kubernetes_client/fake_dynamic_client.py (1)

1-1643: Well-implemented fake Kubernetes client for testing!

This is a comprehensive implementation of a fake Kubernetes dynamic client that will greatly improve test reliability and speed. The resource-agnostic design and support for custom resources make it very flexible for various testing scenarios.

Copy link

@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

♻️ Duplicate comments (6)
tests/test_resources/test_oauth.py (1)

7-16: Address test interdependencies for better isolation.

tests/scripts/generate_pytest_test.py (2)

777-777: Fix incorrect main() function call


223-239: Refactor deeply nested code for better readability

fake_kubernetes_client/fake_dynamic_client.py (3)

186-195: Confusing behavior in items() method - prioritizes data key over dict method.


703-711: Fix inconsistent return behavior in _merge_patch.


107-117: Simplify __getattribute__ override to avoid potential recursion issues.

🧹 Nitpick comments (1)
tests/test_resources/test_oauth.py (1)

42-42: Add newline at end of file.

-        assert not oauth.exists
+        assert not oauth.exists
+
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 84a48aa and a41b298.

📒 Files selected for processing (83)
  • fake_kubernetes_client/fake_dynamic_client.py (1 hunks)
  • tests/scripts/generate_pytest_test.py (1 hunks)
  • tests/test_resources/test_aaq.py (1 hunks)
  • tests/test_resources/test_api_server.py (1 hunks)
  • tests/test_resources/test_authorino.py (1 hunks)
  • tests/test_resources/test_cdi.py (1 hunks)
  • tests/test_resources/test_cdi_config.py (1 hunks)
  • tests/test_resources/test_cluster_resource_quota.py (1 hunks)
  • tests/test_resources/test_cluster_user_defined_network.py (1 hunks)
  • tests/test_resources/test_config_map.py (1 hunks)
  • tests/test_resources/test_console_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_console_operator_openshift_io.py (1 hunks)
  • tests/test_resources/test_csi_driver.py (1 hunks)
  • tests/test_resources/test_data_import_cron.py (1 hunks)
  • tests/test_resources/test_data_science_cluster.py (1 hunks)
  • tests/test_resources/test_deployment.py (1 hunks)
  • tests/test_resources/test_direct_volume_migration.py (1 hunks)
  • tests/test_resources/test_direct_volume_migration_progress.py (1 hunks)
  • tests/test_resources/test_dns_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_dns_operator_openshift_io.py (1 hunks)
  • tests/test_resources/test_dsc_initialization.py (1 hunks)
  • tests/test_resources/test_group.py (1 hunks)
  • tests/test_resources/test_guardrails_orchestrator.py (1 hunks)
  • tests/test_resources/test_image_caching_internal_knative_dev.py (1 hunks)
  • tests/test_resources/test_image_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_image_content_source_policy.py (1 hunks)
  • tests/test_resources/test_image_image_openshift_io.py (1 hunks)
  • tests/test_resources/test_inference_graph.py (1 hunks)
  • tests/test_resources/test_kube_descheduler.py (1 hunks)
  • tests/test_resources/test_kubelet_config.py (1 hunks)
  • tests/test_resources/test_kubevirt.py (1 hunks)
  • tests/test_resources/test_llama_stack_distribution.py (1 hunks)
  • tests/test_resources/test_lm_eval_job.py (1 hunks)
  • tests/test_resources/test_machine.py (1 hunks)
  • tests/test_resources/test_maria_db.py (1 hunks)
  • tests/test_resources/test_mariadb_operator.py (1 hunks)
  • tests/test_resources/test_mig_analytic.py (1 hunks)
  • tests/test_resources/test_mig_cluster.py (1 hunks)
  • tests/test_resources/test_mig_migration.py (1 hunks)
  • tests/test_resources/test_mig_plan.py (1 hunks)
  • tests/test_resources/test_model_registry.py (1 hunks)
  • tests/test_resources/test_model_registry_components_platform_opendatahub_io.py (1 hunks)
  • tests/test_resources/test_model_registry_modelregistry_opendatahub_io.py (1 hunks)
  • tests/test_resources/test_mtq.py (1 hunks)
  • tests/test_resources/test_namespace.py (1 hunks)
  • tests/test_resources/test_network_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_network_operator_openshift_io.py (1 hunks)
  • tests/test_resources/test_nm_state.py (1 hunks)
  • tests/test_resources/test_node.py (1 hunks)
  • tests/test_resources/test_node_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_node_network_configuration_policy_latest.py (1 hunks)
  • tests/test_resources/test_notebook.py (1 hunks)
  • tests/test_resources/test_oauth.py (1 hunks)
  • tests/test_resources/test_operator.py (1 hunks)
  • tests/test_resources/test_pod.py (1 hunks)
  • tests/test_resources/test_pod_metrics.py (1 hunks)
  • tests/test_resources/test_project_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_project_project_openshift_io.py (1 hunks)
  • tests/test_resources/test_project_request.py (1 hunks)
  • tests/test_resources/test_prometheus.py (1 hunks)
  • tests/test_resources/test_replica_set.py (1 hunks)
  • tests/test_resources/test_scheduler.py (1 hunks)
  • tests/test_resources/test_security_context_constraints.py (1 hunks)
  • tests/test_resources/test_self_subject_review.py (1 hunks)
  • tests/test_resources/test_service.py (1 hunks)
  • tests/test_resources/test_service_mesh_member.py (1 hunks)
  • tests/test_resources/test_service_serving_knative_dev.py (1 hunks)
  • tests/test_resources/test_serving_runtime.py (1 hunks)
  • tests/test_resources/test_snapshot.py (1 hunks)
  • tests/test_resources/test_ssp.py (1 hunks)
  • tests/test_resources/test_storage_cluster.py (1 hunks)
  • tests/test_resources/test_user.py (1 hunks)
  • tests/test_resources/test_user_defined_network.py (1 hunks)
  • tests/test_resources/test_virtual_machine_cluster_instancetype.py (1 hunks)
  • tests/test_resources/test_virtual_machine_cluster_preference.py (1 hunks)
  • tests/test_resources/test_virtual_machine_export.py (1 hunks)
  • tests/test_resources/test_virtual_machine_instance_migration.py (1 hunks)
  • tests/test_resources/test_virtual_machine_instance_preset.py (1 hunks)
  • tests/test_resources/test_virtual_machine_instance_replica_set.py (1 hunks)
  • tests/test_resources/test_virtual_machine_instancetype.py (1 hunks)
  • tests/test_resources/test_virtual_machine_preference.py (1 hunks)
  • tests/test_resources/test_volume_snapshot.py (1 hunks)
  • tests/test_resources/test_volume_snapshot_class.py (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • tests/test_resources/test_project_project_openshift_io.py
  • tests/test_resources/test_console_operator_openshift_io.py
🚧 Files skipped from review as they are similar to previous changes (78)
  • tests/test_resources/test_dsc_initialization.py
  • tests/test_resources/test_operator.py
  • tests/test_resources/test_project_config_openshift_io.py
  • tests/test_resources/test_user_defined_network.py
  • tests/test_resources/test_machine.py
  • tests/test_resources/test_mig_plan.py
  • tests/test_resources/test_authorino.py
  • tests/test_resources/test_mig_cluster.py
  • tests/test_resources/test_node_config_openshift_io.py
  • tests/test_resources/test_scheduler.py
  • tests/test_resources/test_serving_runtime.py
  • tests/test_resources/test_image_image_openshift_io.py
  • tests/test_resources/test_snapshot.py
  • tests/test_resources/test_deployment.py
  • tests/test_resources/test_dns_config_openshift_io.py
  • tests/test_resources/test_pod_metrics.py
  • tests/test_resources/test_mig_migration.py
  • tests/test_resources/test_service.py
  • tests/test_resources/test_node_network_configuration_policy_latest.py
  • tests/test_resources/test_network_config_openshift_io.py
  • tests/test_resources/test_aaq.py
  • tests/test_resources/test_direct_volume_migration_progress.py
  • tests/test_resources/test_mig_analytic.py
  • tests/test_resources/test_model_registry_components_platform_opendatahub_io.py
  • tests/test_resources/test_service_mesh_member.py
  • tests/test_resources/test_volume_snapshot_class.py
  • tests/test_resources/test_llama_stack_distribution.py
  • tests/test_resources/test_network_operator_openshift_io.py
  • tests/test_resources/test_replica_set.py
  • tests/test_resources/test_model_registry.py
  • tests/test_resources/test_virtual_machine_cluster_instancetype.py
  • tests/test_resources/test_kubelet_config.py
  • tests/test_resources/test_direct_volume_migration.py
  • tests/test_resources/test_cdi_config.py
  • tests/test_resources/test_group.py
  • tests/test_resources/test_virtual_machine_instance_migration.py
  • tests/test_resources/test_inference_graph.py
  • tests/test_resources/test_service_serving_knative_dev.py
  • tests/test_resources/test_data_science_cluster.py
  • tests/test_resources/test_image_content_source_policy.py
  • tests/test_resources/test_storage_cluster.py
  • tests/test_resources/test_virtual_machine_cluster_preference.py
  • tests/test_resources/test_virtual_machine_export.py
  • tests/test_resources/test_console_config_openshift_io.py
  • tests/test_resources/test_self_subject_review.py
  • tests/test_resources/test_namespace.py
  • tests/test_resources/test_mtq.py
  • tests/test_resources/test_model_registry_modelregistry_opendatahub_io.py
  • tests/test_resources/test_ssp.py
  • tests/test_resources/test_mariadb_operator.py
  • tests/test_resources/test_maria_db.py
  • tests/test_resources/test_user.py
  • tests/test_resources/test_volume_snapshot.py
  • tests/test_resources/test_kube_descheduler.py
  • tests/test_resources/test_project_request.py
  • tests/test_resources/test_nm_state.py
  • tests/test_resources/test_api_server.py
  • tests/test_resources/test_csi_driver.py
  • tests/test_resources/test_prometheus.py
  • tests/test_resources/test_cdi.py
  • tests/test_resources/test_virtual_machine_preference.py
  • tests/test_resources/test_lm_eval_job.py
  • tests/test_resources/test_virtual_machine_instance_preset.py
  • tests/test_resources/test_dns_operator_openshift_io.py
  • tests/test_resources/test_image_caching_internal_knative_dev.py
  • tests/test_resources/test_pod.py
  • tests/test_resources/test_virtual_machine_instancetype.py
  • tests/test_resources/test_cluster_user_defined_network.py
  • tests/test_resources/test_cluster_resource_quota.py
  • tests/test_resources/test_guardrails_orchestrator.py
  • tests/test_resources/test_security_context_constraints.py
  • tests/test_resources/test_config_map.py
  • tests/test_resources/test_kubevirt.py
  • tests/test_resources/test_image_config_openshift_io.py
  • tests/test_resources/test_virtual_machine_instance_replica_set.py
  • tests/test_resources/test_node.py
  • tests/test_resources/test_data_import_cron.py
  • tests/test_resources/test_notebook.py
🧰 Additional context used
🧠 Learnings (3)
tests/test_resources/test_oauth.py (1)
Learnt from: dbasunag
PR: RedHatQE/openshift-python-wrapper#2178
File: tests/test_unittests.py:62-67
Timestamp: 2024-11-26T18:59:33.316Z
Learning: In this codebase, it's acceptable to modify function-scoped fixtures within tests, as it does not impact other tests.
fake_kubernetes_client/fake_dynamic_client.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/scripts/generate_pytest_test.py (7)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2209
File: ocp_resources/volume_snapshot_class.py:0-0
Timestamp: 2024-12-03T08:02:11.880Z
Learning: In generated code files like `ocp_resources/volume_snapshot_class.py`, avoid suggesting adding validation checks or modifications, as generated code should not be manually altered.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:9-10
Timestamp: 2024-10-09T14:23:46.600Z
Learning: In the file `class_generator/tests/manifests/ServingRuntime/serving_runtime.py`, the `ServingRuntime` class is auto-generated code. Do not request adding descriptions to docstrings when reviewing auto-generated code containing placeholders like "No field description from API; please add description."
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:96-160
Timestamp: 2024-10-09T14:25:49.618Z
Learning: The code in the `class_generator/tests/manifests/ServingRuntime/serving_runtime.py` file is auto-generated. Avoid suggesting refactoring changes to auto-generated code in this path.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2154
File: ocp_resources/serving_runtime.py:16-32
Timestamp: 2024-10-09T18:44:30.628Z
Learning: The file `ocp_resources/serving_runtime.py` is auto-generated code.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2154
File: ocp_resources/serving_runtime.py:110-160
Timestamp: 2024-10-09T18:44:29.284Z
Learning: In `ocp_resources/serving_runtime.py`, the code is auto-generated and should not be manually modified.
Learnt from: sbahar619
PR: RedHatQE/openshift-python-wrapper#2124
File: ocp_resources/user_defined_network.py:303-318
Timestamp: 2024-10-08T23:43:22.342Z
Learning: When reviewing `to_dict` methods in the `UserDefinedNetwork` subclasses, avoid suggesting refactoring if it adds complexity without significant code savings.
Learnt from: sbahar619
PR: RedHatQE/openshift-python-wrapper#2124
File: ocp_resources/user_defined_network.py:303-318
Timestamp: 2024-09-26T07:27:13.102Z
Learning: When reviewing `to_dict` methods in the `UserDefinedNetwork` subclasses, avoid suggesting refactoring if it adds complexity without significant code savings.
🧬 Code Graph Analysis (1)
fake_kubernetes_client/fake_dynamic_client.py (23)
ocp_resources/benchmark.py (1)
  • uuid (50-55)
ocp_resources/project_request.py (1)
  • to_dict (36-44)
tests/test_resources/test_api_server.py (1)
  • client (8-9)
tests/test_resources/test_aaq.py (1)
  • client (8-9)
tests/test_resources/test_cdi.py (1)
  • client (8-9)
tests/test_resources/test_cdi_config.py (1)
  • client (8-9)
tests/test_resources/test_cluster_resource_quota.py (1)
  • client (8-9)
tests/test_resources/test_authorino.py (1)
  • client (8-9)
tests/test_resources/test_cluster_user_defined_network.py (1)
  • client (8-9)
tests/test_resources/test_csi_driver.py (1)
  • client (8-9)
tests/test_resources/test_config_map.py (1)
  • client (8-9)
tests/test_resources/test_console_operator_openshift_io.py (1)
  • client (8-9)
tests/test_resources/test_console_config_openshift_io.py (1)
  • client (8-9)
tests/test_resources/test_data_import_cron.py (1)
  • client (8-9)
tests/test_resources/test_data_science_cluster.py (1)
  • client (8-9)
tests/test_resources/test_deployment.py (1)
  • client (8-9)
tests/test_resources/test_direct_volume_migration.py (1)
  • client (8-9)
tests/test_resources/test_direct_volume_migration_progress.py (1)
  • client (8-9)
tests/test_resources/test_namespace.py (1)
  • namespace (12-16)
tests/test_resource.py (1)
  • namespace (30-31)
ocp_resources/resource.py (3)
  • kind (671-672)
  • exists (918-925)
  • labels (1158-1165)
tests/test_resources/test_group.py (1)
  • group (12-17)
ocp_resources/route.py (1)
  • host (56-60)
🪛 Pylint (3.3.7)
fake_kubernetes_client/fake_dynamic_client.py

[refactor] 136-143: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 119-119: Too many return statements (8/6)

(R0911)


[refactor] 147-154: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 549-582: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 586-602: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 724-731: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 747-747: Too many local variables (16/15)

(R0914)


[refactor] 841-841: Too many arguments (6/5)

(R0913)


[refactor] 841-841: Too many positional arguments (6/5)

(R0917)


[refactor] 866-866: Too many local variables (18/15)

(R0914)


[refactor] 866-866: Too many return statements (8/6)

(R0911)


[refactor] 866-866: Too many branches (18/12)

(R0912)


[refactor] 960-960: Too many branches (16/12)

(R0912)


[refactor] 1143-1143: Too many arguments (6/5)

(R0913)


[refactor] 1143-1143: Too many positional arguments (6/5)

(R0917)


[refactor] 1154-1159: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1163-1168: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1170-1170: Too many arguments (6/5)

(R0913)


[refactor] 1170-1170: Too many positional arguments (6/5)

(R0917)


[refactor] 1239-1239: Too many branches (14/12)

(R0912)


[refactor] 1312-1312: Too few public methods (0/2)

(R0903)


[refactor] 1322-1322: Too few public methods (1/2)

(R0903)


[refactor] 1423-1426: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1430-1433: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1437-1440: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1444-1447: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1451-1454: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1458-1461: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1538-1542: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1566-1566: Too many local variables (17/15)

(R0914)

tests/scripts/generate_pytest_test.py

[refactor] 62-62: Too many instance attributes (10/7)

(R0902)


[refactor] 153-158: Unnecessary "elif" after "break", remove the leading "el" from "elif"

(R1723)


[refactor] 223-239: Too many nested blocks (9/5)

(R1702)


[refactor] 89-89: Too few public methods (1/2)

(R0903)


[refactor] 296-296: Too few public methods (1/2)

(R0903)


[refactor] 386-386: Too many branches (24/12)

(R0912)


[refactor] 386-386: Too many statements (53/50)

(R0915)


[refactor] 353-353: Too few public methods (1/2)

(R0903)


[refactor] 657-657: Too many local variables (26/15)

(R0914)


[refactor] 657-657: Too many branches (20/12)

(R0912)


[refactor] 657-657: Too many statements (69/50)

(R0915)


[error] 777-777: No value for argument 'kind' in function call

(E1120)


[error] 777-777: No value for argument 'check_coverage' in function call

(E1120)


[error] 777-777: No value for argument 'generate_missing' in function call

(E1120)


[error] 777-777: No value for argument 'dry_run' in function call

(E1120)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: conventional-title
  • GitHub Check: python-module-install
  • GitHub Check: tox

@myakove
Copy link
Collaborator Author

myakove commented Jul 6, 2025

/verified

Copy link

@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

♻️ Duplicate comments (4)
tests/scripts/generate_pytest_test.py (2)

225-241: Refactor deeply nested code for better readability

The method has 5 levels of nesting which makes it hard to read and maintain. Consider extracting the inner logic.

 def _analyze_to_dict_method(self, class_node: ast.ClassDef) -> list[str]:
     """Analyze to_dict method to find parameters that raise MissingRequiredArgumentError"""
     required_params = []
 
     for node in class_node.body:
         if isinstance(node, ast.FunctionDef) and node.name == "to_dict":
-            # Look for MissingRequiredArgumentError raises
-            for stmt in ast.walk(node):
-                if isinstance(stmt, ast.Raise) and isinstance(stmt.exc, ast.Call):
-                    # Check if it's raising MissingRequiredArgumentError
-                    if isinstance(stmt.exc.func, ast.Name) and stmt.exc.func.id == "MissingRequiredArgumentError":
-                        # Extract the argument parameter
-                        for keyword in stmt.exc.keywords:
-                            if keyword.arg == "argument":
-                                if isinstance(keyword.value, ast.Constant):
-                                    # Extract parameter name from "self.param_name"
-                                    param_str = keyword.value.value
-                                    if isinstance(param_str, str) and param_str.startswith("self."):
-                                        param_name = param_str[5:]  # Remove "self."
-                                        required_params.append(param_name)
+            required_params.extend(self._extract_required_params_from_raises(node))
             break
 
     return required_params
+
+def _extract_required_params_from_raises(self, function_node: ast.FunctionDef) -> list[str]:
+    """Extract required parameters from MissingRequiredArgumentError raises"""
+    params = []
+    for stmt in ast.walk(function_node):
+        if not (isinstance(stmt, ast.Raise) and isinstance(stmt.exc, ast.Call)):
+            continue
+            
+        if not (isinstance(stmt.exc.func, ast.Name) and stmt.exc.func.id == "MissingRequiredArgumentError"):
+            continue
+            
+        param_name = self._extract_param_from_exception(stmt.exc)
+        if param_name:
+            params.append(param_name)
+    
+    return params
+
+def _extract_param_from_exception(self, exc_call: ast.Call) -> str | None:
+    """Extract parameter name from MissingRequiredArgumentError call"""
+    for keyword in exc_call.keywords:
+        if keyword.arg == "argument" and isinstance(keyword.value, ast.Constant):
+            param_str = keyword.value.value
+            if isinstance(param_str, str) and param_str.startswith("self."):
+                return param_str[5:]  # Remove "self."
+    return None

786-786: Fix incorrect main() function call

The main() function is a cloup command that should be invoked through the command interface, not called directly with arguments.

 if __name__ == "__main__":
-    main.main()
+    main()
fake_kubernetes_client/fake_dynamic_client.py (2)

197-206: Confusing behavior in items() method - prioritizes data key over dict method.

The items() method returns the value of an 'items' key if it exists in the data, rather than the expected dictionary items. This violates the principle of least surprise and could lead to bugs.

Consider renaming the data key access method or documenting this behavior clearly:

 def items(self):
-    """Get dictionary items - but handle special case where 'items' is data"""
-    # If 'items' key exists in data, return that instead of dict.items()
-    if "items" in self._data:
-        value = self._data["items"]
-        if isinstance(value, list):
-            return [FakeResourceField(data=item) if isinstance(item, dict) else item for item in value]
-        return value
-    # Otherwise return dict.items()
+    """Get dictionary items"""
     return self._data.items()
+
+def get_items_field(self):
+    """Get the 'items' field value if it exists"""
+    if "items" in self._data:
+        value = self._data["items"]
+        if isinstance(value, list):
+            return [FakeResourceField(data=item) if isinstance(item, dict) else item for item in value]
+        return value
+    return None

714-722: Fix inconsistent return behavior in _merge_patch.

The method implicitly returns None in the if branch but has no explicit return, making the behavior unclear. The recursive nature of this method doesn't require a return value.

 def _merge_patch(self, target, patch):
     """Simple merge patch implementation"""
     if isinstance(patch, dict):
         for key, value in patch.items():
             if key in target and isinstance(target[key], dict) and isinstance(value, dict):
                 self._merge_patch(target[key], value)
             else:
                 target[key] = value
-    else:
-        return patch
+    # Note: merge_patch modifies target in-place, no return needed
🧹 Nitpick comments (1)
fake_kubernetes_client/fake_dynamic_client.py (1)

1434-1472: Simplify control flow by removing unnecessary else blocks after return.

Multiple methods have unnecessary else blocks after return statements, which reduces readability.

 def get(self, resource, name=None, namespace=None, **kwargs):
     """Get resource(s) using resource definition"""
     if hasattr(resource, "get"):
         return resource.get(name=name, namespace=namespace, **kwargs)
-    else:
-        raise ValueError("Invalid resource definition")
+    raise ValueError("Invalid resource definition")

 def create(self, resource, body=None, namespace=None, **kwargs):
     """Create resource using resource definition"""
     if hasattr(resource, "create"):
         return resource.create(body=body, namespace=namespace, **kwargs)
-    else:
-        raise ValueError("Invalid resource definition")
+    raise ValueError("Invalid resource definition")

 def delete(self, resource, name=None, namespace=None, **kwargs):
     """Delete resource using resource definition"""
     if hasattr(resource, "delete"):
         return resource.delete(name=name, namespace=namespace, **kwargs)
-    else:
-        raise ValueError("Invalid resource definition")
+    raise ValueError("Invalid resource definition")

 def patch(self, resource, name=None, body=None, namespace=None, **kwargs):
     """Patch resource using resource definition"""
     if hasattr(resource, "patch"):
         return resource.patch(name=name, body=body, namespace=namespace, **kwargs)
-    else:
-        raise ValueError("Invalid resource definition")
+    raise ValueError("Invalid resource definition")

 def replace(self, resource, name=None, body=None, namespace=None, **kwargs):
     """Replace resource using resource definition"""
     if hasattr(resource, "replace"):
         return resource.replace(name=name, body=body, namespace=namespace, **kwargs)
-    else:
-        raise ValueError("Invalid resource definition")
+    raise ValueError("Invalid resource definition")

 def watch(self, resource, namespace=None, **kwargs):
     """Watch resource using resource definition"""
     if hasattr(resource, "watch"):
         return resource.watch(namespace=namespace, **kwargs)
-    else:
-        raise ValueError("Invalid resource definition")
+    raise ValueError("Invalid resource definition")
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a41b298 and 02f3310.

📒 Files selected for processing (2)
  • fake_kubernetes_client/fake_dynamic_client.py (1 hunks)
  • tests/scripts/generate_pytest_test.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
fake_kubernetes_client/fake_dynamic_client.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/scripts/generate_pytest_test.py (7)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2209
File: ocp_resources/volume_snapshot_class.py:0-0
Timestamp: 2024-12-03T08:02:11.880Z
Learning: In generated code files like `ocp_resources/volume_snapshot_class.py`, avoid suggesting adding validation checks or modifications, as generated code should not be manually altered.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:9-10
Timestamp: 2024-10-09T14:23:46.600Z
Learning: In the file `class_generator/tests/manifests/ServingRuntime/serving_runtime.py`, the `ServingRuntime` class is auto-generated code. Do not request adding descriptions to docstrings when reviewing auto-generated code containing placeholders like "No field description from API; please add description."
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:96-160
Timestamp: 2024-10-09T14:25:49.618Z
Learning: The code in the `class_generator/tests/manifests/ServingRuntime/serving_runtime.py` file is auto-generated. Avoid suggesting refactoring changes to auto-generated code in this path.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2154
File: ocp_resources/serving_runtime.py:16-32
Timestamp: 2024-10-09T18:44:30.628Z
Learning: The file `ocp_resources/serving_runtime.py` is auto-generated code.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2154
File: ocp_resources/serving_runtime.py:110-160
Timestamp: 2024-10-09T18:44:29.284Z
Learning: In `ocp_resources/serving_runtime.py`, the code is auto-generated and should not be manually modified.
Learnt from: sbahar619
PR: RedHatQE/openshift-python-wrapper#2124
File: ocp_resources/user_defined_network.py:303-318
Timestamp: 2024-10-08T23:43:22.342Z
Learning: When reviewing `to_dict` methods in the `UserDefinedNetwork` subclasses, avoid suggesting refactoring if it adds complexity without significant code savings.
Learnt from: sbahar619
PR: RedHatQE/openshift-python-wrapper#2124
File: ocp_resources/user_defined_network.py:303-318
Timestamp: 2024-09-26T07:27:13.102Z
Learning: When reviewing `to_dict` methods in the `UserDefinedNetwork` subclasses, avoid suggesting refactoring if it adds complexity without significant code savings.
🧬 Code Graph Analysis (1)
fake_kubernetes_client/fake_dynamic_client.py (23)
ocp_resources/benchmark.py (1)
  • uuid (50-55)
ocp_resources/project_request.py (1)
  • to_dict (36-44)
tests/test_resources/test_api_server.py (1)
  • client (8-9)
tests/test_resources/test_aaq.py (1)
  • client (8-9)
tests/test_resources/test_authorino.py (1)
  • client (8-9)
tests/test_resources/test_cdi.py (1)
  • client (8-9)
tests/test_resources/test_cdi_config.py (1)
  • client (8-9)
tests/test_resources/test_cluster_resource_quota.py (1)
  • client (8-9)
tests/test_resources/test_cluster_user_defined_network.py (1)
  • client (8-9)
tests/test_resources/test_config_map.py (1)
  • client (8-9)
tests/test_resources/test_console_config_openshift_io.py (1)
  • client (8-9)
tests/test_resources/test_console_operator_openshift_io.py (1)
  • client (8-9)
tests/test_resources/test_csi_driver.py (1)
  • client (8-9)
tests/test_resources/test_data_import_cron.py (1)
  • client (8-9)
tests/test_resources/test_data_science_cluster.py (1)
  • client (8-9)
tests/test_resources/test_deployment.py (1)
  • client (8-9)
tests/test_resources/test_direct_volume_migration.py (1)
  • client (8-9)
tests/test_resources/test_direct_volume_migration_progress.py (1)
  • client (8-9)
tests/test_resources/test_namespace.py (1)
  • namespace (12-16)
tests/test_resource.py (1)
  • namespace (30-31)
ocp_resources/resource.py (3)
  • kind (671-672)
  • exists (918-925)
  • labels (1158-1165)
tests/test_resources/test_group.py (1)
  • group (12-17)
ocp_resources/route.py (1)
  • host (56-60)
🪛 Pylint (3.3.7)
fake_kubernetes_client/fake_dynamic_client.py

[refactor] 147-154: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 158-165: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 735-742: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 758-758: Too many local variables (16/15)

(R0914)


[refactor] 852-852: Too many arguments (6/5)

(R0913)


[refactor] 852-852: Too many positional arguments (6/5)

(R0917)


[refactor] 877-877: Too many local variables (18/15)

(R0914)


[refactor] 877-877: Too many return statements (8/6)

(R0911)


[refactor] 877-877: Too many branches (18/12)

(R0912)


[refactor] 971-971: Too many branches (16/12)

(R0912)


[refactor] 1154-1154: Too many arguments (6/5)

(R0913)


[refactor] 1154-1154: Too many positional arguments (6/5)

(R0917)


[refactor] 1181-1181: Too many arguments (6/5)

(R0913)


[refactor] 1181-1181: Too many positional arguments (6/5)

(R0917)


[refactor] 1250-1250: Too many branches (14/12)

(R0912)


[refactor] 1323-1323: Too few public methods (0/2)

(R0903)


[refactor] 1333-1333: Too few public methods (1/2)

(R0903)


[refactor] 1434-1437: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1441-1444: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1448-1451: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1455-1458: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1462-1465: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1469-1472: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1549-1553: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1577-1577: Too many local variables (17/15)

(R0914)

tests/scripts/generate_pytest_test.py

[refactor] 64-64: Too many instance attributes (10/7)

(R0902)


[refactor] 225-241: Too many nested blocks (9/5)

(R1702)


[refactor] 91-91: Too few public methods (1/2)

(R0903)


[refactor] 298-298: Too few public methods (1/2)

(R0903)


[refactor] 388-388: Too many branches (24/12)

(R0912)


[refactor] 388-388: Too many statements (53/50)

(R0915)


[refactor] 355-355: Too few public methods (1/2)

(R0903)


[refactor] 672-672: Too many local variables (26/15)

(R0914)


[refactor] 672-672: Too many branches (16/12)

(R0912)


[refactor] 672-672: Too many statements (62/50)

(R0915)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: conventional-title
  • GitHub Check: tox
  • GitHub Check: python-module-install
🔇 Additional comments (2)
fake_kubernetes_client/fake_dynamic_client.py (2)

303-310: Well-implemented ephemeral resource handling for ProjectRequest.

The special case handling for ProjectRequest correctly mimics real OpenShift behavior by creating a Project resource instead of storing the ephemeral ProjectRequest. This is a good implementation detail.


1577-1657: Excellent test coverage demonstrating generic resource support.

The test_generic_resource_support function provides comprehensive examples of how the fake client handles various resource types, including custom CRDs, cluster-scoped resources, complex API groups, and unknown resources. This is valuable for understanding the fake client's capabilities.

@myakove
Copy link
Collaborator Author

myakove commented Jul 6, 2025

/verified

Copy link

@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

♻️ Duplicate comments (4)
tests/test_resources/test_scheduler.py (1)

8-17: Improve test isolation by using function-scoped fixtures.

The class-scoped fixtures create test interdependencies, where modifications in one test can affect subsequent tests. This reduces test reliability and isolation.

Consider changing to function-scoped fixtures and adding tests for Scheduler-specific configuration options like default_node_selector, masters_schedulable, and profile parameters.

-    @pytest.fixture(scope="class")
+    @pytest.fixture(scope="function")
     def client(self):
         return FakeDynamicClient()

-    @pytest.fixture(scope="class")
+    @pytest.fixture(scope="function")
     def scheduler(self, client):
         return Scheduler(
             client=client,
             name="test-scheduler",
+            # Add Scheduler-specific parameters for comprehensive testing
+            default_node_selector="test-selector",
+            masters_schedulable=True,
+            profile="HighNodeUtilization",
         )
tests/scripts/generate_pytest_test.py (2)

929-929: Fix incorrect main() function call.

The main() function is a cloup command that should be invoked through the command interface, not called directly.

 if __name__ == "__main__":
-    main.main()
+    main()

227-243: Refactor deeply nested code for better readability.

The method has excessive nesting (9 levels) which makes it difficult to read and maintain.

Extract the inner logic into helper methods:

 def _analyze_to_dict_method(self, class_node: ast.ClassDef) -> list[str]:
     """Analyze to_dict method to find parameters that raise MissingRequiredArgumentError"""
     required_params = []

     for node in class_node.body:
         if isinstance(node, ast.FunctionDef) and node.name == "to_dict":
-            # Look for MissingRequiredArgumentError raises
-            for stmt in ast.walk(node):
-                if isinstance(stmt, ast.Raise) and isinstance(stmt.exc, ast.Call):
-                    # Check if it's raising MissingRequiredArgumentError
-                    if isinstance(stmt.exc.func, ast.Name) and stmt.exc.func.id == "MissingRequiredArgumentError":
-                        # Extract the argument parameter
-                        for keyword in stmt.exc.keywords:
-                            if keyword.arg == "argument":
-                                if isinstance(keyword.value, ast.Constant):
-                                    # Extract parameter name from "self.param_name"
-                                    param_str = keyword.value.value
-                                    if isinstance(param_str, str) and param_str.startswith("self."):
-                                        param_name = param_str[5:]  # Remove "self."
-                                        required_params.append(param_name)
+            required_params.extend(self._extract_required_params_from_raises(node))
             break

     return required_params

+def _extract_required_params_from_raises(self, function_node: ast.FunctionDef) -> list[str]:
+    """Extract required parameters from MissingRequiredArgumentError raises"""
+    params = []
+    for stmt in ast.walk(function_node):
+        if not (isinstance(stmt, ast.Raise) and isinstance(stmt.exc, ast.Call)):
+            continue
+            
+        if not (isinstance(stmt.exc.func, ast.Name) and stmt.exc.func.id == "MissingRequiredArgumentError"):
+            continue
+            
+        param_name = self._extract_param_from_exception(stmt.exc)
+        if param_name:
+            params.append(param_name)
+    
+    return params

+def _extract_param_from_exception(self, exc_call: ast.Call) -> str | None:
+    """Extract parameter name from MissingRequiredArgumentError call"""
+    for keyword in exc_call.keywords:
+        if keyword.arg == "argument" and isinstance(keyword.value, ast.Constant):
+            param_str = keyword.value.value
+            if isinstance(param_str, str) and param_str.startswith("self."):
+                return param_str[5:]  # Remove "self."
+    return None
fake_kubernetes_client/fake_dynamic_client.py (1)

198-207: Confusing behavior in items() method persists.

The items() method still returns the value of an 'items' key if it exists in the data, rather than the expected dictionary items. This violates the principle of least surprise and could lead to bugs.

This issue was flagged in previous reviews but hasn't been addressed yet.

🧹 Nitpick comments (8)
tests/scripts/generate_pytest_test.py (2)

523-607: Consider refactoring the large _generate_test_data method.

This method has 26 branches and 59 statements, making it complex to maintain. Consider extracting resource-specific logic into separate methods.

 def _generate_test_data(self, resource: ResourceInfo) -> dict[str, Any]:
     """Generate realistic test data for a resource"""
     data: dict[str, Any] = {
         "name": f"test-{resource.name.lower()}",
     }

     # Add namespace for namespaced resources
     if resource.base_class == "NamespacedResource":
         data["namespace"] = "default"

-    # Add resource-specific required parameters
-    if resource.name == "VolumeSnapshotClass":
-        data["deletion_policy"] = "Delete"
-        data["driver"] = "example.com/csi-driver"
-    elif resource.name == "ConfigMap":
-        data["data"] = {"key1": "value1"}
-    # ... (many more elif blocks)
+    # Add resource-specific parameters
+    resource_specific_data = self._get_resource_specific_data(resource)
+    data.update(resource_specific_data)

     # Add any additional required parameters from analysis
     for param in resource.required_params:
         if param not in data and param not in ["name", "namespace", "client"]:
             data[param] = self._get_default_value_for_param(resource, param)

     return data

+def _get_resource_specific_data(self, resource: ResourceInfo) -> dict[str, Any]:
+    """Get resource-specific test data"""
+    resource_data_map = {
+        "VolumeSnapshotClass": {"deletion_policy": "Delete", "driver": "example.com/csi-driver"},
+        "ConfigMap": {"data": {"key1": "value1"}},
+        "Secret": {"string_data": {"password": "secret123"}},
+        # ... move other resource-specific mappings here
+    }
+    return resource_data_map.get(resource.name, {})

815-926: Consider extracting logic from the large main function.

The main function has 26 local variables, 16 branches, and 62 statements, making it complex to understand and maintain.

Consider extracting logical groups into helper methods:

 def main(kind, check_coverage, generate_missing, dry_run):
     """Generate pytest tests for OCP resources using fake_kubernetes_client."""
     console.print("[bold blue]OCP Resources Pytest Test Generator[/bold blue]")

-    # Initialize components
-    scanner = ResourceScanner()
-    analyzer = TestAnalyzer()
-    generator = TestGenerator()
-
-    # Scan for resources
-    console.print("Scanning ocp_resources directory...")
-    resources = scanner.scan_resources()
-    console.print(f"Found {len(resources)} resource classes")
-
-    # Analyze coverage
-    coverage = analyzer.analyze_coverage(resources=resources)
+    resources, coverage = self._setup_and_analyze()

     if check_coverage:
-        print_coverage_report(coverage=coverage)
+        self._handle_coverage_check(coverage)
         return

-    # Determine which resources to generate tests for
-    target_resources = []
-    # ... (complex logic for determining target resources)
+    target_resources = self._determine_target_resources(kind, generate_missing, resources, coverage)
+    if not target_resources:
+        return

-    # Generate tests
-    # ... (complex generation and execution logic)
+    self._generate_and_execute_tests(target_resources, generator, dry_run)
fake_kubernetes_client/fake_dynamic_client.py (6)

429-486: Consider making container status configurable.

The Pod status template hardcodes containers as not ready. For more realistic testing, consider allowing configuration of pod readiness state.

-def _get_pod_status_template(self, body):
+def _get_pod_status_template(self, body, ready=False):
     """Get realistic Pod status"""
     container_name = "test-container"
     if "spec" in body and "containers" in body["spec"] and body["spec"]["containers"]:
         container_name = body["spec"]["containers"][0].get("name", "test-container")
+    
+    ready_status = "True" if ready else "False"
+    ready_reason = "ContainersReady" if ready else "ContainersNotReady"

758-850: Complex initialization method could benefit from refactoring.

The _initialize_builtin_resources() method has high complexity (18 local variables, multiple nested conditions). Consider breaking it into smaller helper methods for better maintainability.

+def _load_resource_from_mapping(self, kind_lower, mapping):
+    """Extract resource definition from a single mapping entry"""
+    # Move the mapping processing logic here
+    
+def _create_fallback_resources(self):
+    """Create essential fallback resources when mappings fail"""
+    # Move fallback resource creation here

1154-1162: Consider using data class for resource parameters.

The store_resource() method takes 6 parameters. Consider using a data class or named tuple to group related parameters for better readability.

from dataclasses import dataclass

@dataclass
class ResourceKey:
    kind: str
    api_version: str
    name: str
    namespace: str | None = None

def store_resource(self, key: ResourceKey, resource: dict):
    """Store any resource type - completely resource-agnostic"""
    # Implementation using key.kind, key.api_version, etc.

1434-1472: Simplify control flow by removing unnecessary else clauses.

Multiple methods have unnecessary else clauses after return statements. This can be simplified for better readability.

 def get(self, resource, name=None, namespace=None, **kwargs):
     """Get resource(s) using resource definition"""
     if hasattr(resource, "get"):
         return resource.get(name=name, namespace=namespace, **kwargs)
-    else:
-        raise ValueError("Invalid resource definition")
+    raise ValueError("Invalid resource definition")

Apply similar changes to create(), delete(), patch(), replace(), and watch() methods.


748-756: Consider caching optimization for resource mappings.

The resource mappings are loaded from file and cached, but the JSON parsing happens every time _get_resource_mappings() is called. Consider loading once at class initialization for better performance.

 def __init__(self, storage):
     self.storage = storage
+    self._load_resource_mappings()
     self._builtin_resources = self._initialize_builtin_resources()
-    self._resource_mappings_cache = None

+def _load_resource_mappings(self):
+    """Load resource mappings once at initialization"""

1158-1161: Performance consideration: deep copying overhead.

The storage uses copy.deepcopy() for all stored resources. For large resources or high-volume testing, this could impact performance. Consider making deep copying optional or using shallow copying where appropriate.

-def store_resource(self, kind, api_version, name, namespace, resource):
+def store_resource(self, kind, api_version, name, namespace, resource, deep_copy=True):
     """Store any resource type - completely resource-agnostic"""
+    stored_resource = copy.deepcopy(resource) if deep_copy else resource
     if namespace is None:
         # Cluster-scoped resource
-        self._cluster_scoped_resources[kind][api_version][name] = copy.deepcopy(resource)
+        self._cluster_scoped_resources[kind][api_version][name] = stored_resource
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02f3310 and 5f52b7e.

📒 Files selected for processing (84)
  • .flake8 (1 hunks)
  • fake_kubernetes_client/fake_dynamic_client.py (1 hunks)
  • tests/scripts/generate_pytest_test.py (1 hunks)
  • tests/test_resources/test_aaq.py (1 hunks)
  • tests/test_resources/test_api_server.py (1 hunks)
  • tests/test_resources/test_authorino.py (1 hunks)
  • tests/test_resources/test_cdi.py (1 hunks)
  • tests/test_resources/test_cdi_config.py (1 hunks)
  • tests/test_resources/test_cluster_resource_quota.py (1 hunks)
  • tests/test_resources/test_cluster_user_defined_network.py (1 hunks)
  • tests/test_resources/test_config_map.py (1 hunks)
  • tests/test_resources/test_console_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_console_operator_openshift_io.py (1 hunks)
  • tests/test_resources/test_csi_driver.py (1 hunks)
  • tests/test_resources/test_data_import_cron.py (1 hunks)
  • tests/test_resources/test_data_science_cluster.py (1 hunks)
  • tests/test_resources/test_deployment.py (1 hunks)
  • tests/test_resources/test_direct_volume_migration.py (1 hunks)
  • tests/test_resources/test_direct_volume_migration_progress.py (1 hunks)
  • tests/test_resources/test_dns_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_dns_operator_openshift_io.py (1 hunks)
  • tests/test_resources/test_dsc_initialization.py (1 hunks)
  • tests/test_resources/test_group.py (1 hunks)
  • tests/test_resources/test_guardrails_orchestrator.py (1 hunks)
  • tests/test_resources/test_image_caching_internal_knative_dev.py (1 hunks)
  • tests/test_resources/test_image_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_image_content_source_policy.py (1 hunks)
  • tests/test_resources/test_image_image_openshift_io.py (1 hunks)
  • tests/test_resources/test_inference_graph.py (1 hunks)
  • tests/test_resources/test_kube_descheduler.py (1 hunks)
  • tests/test_resources/test_kubelet_config.py (1 hunks)
  • tests/test_resources/test_kubevirt.py (1 hunks)
  • tests/test_resources/test_llama_stack_distribution.py (1 hunks)
  • tests/test_resources/test_lm_eval_job.py (1 hunks)
  • tests/test_resources/test_machine.py (1 hunks)
  • tests/test_resources/test_maria_db.py (1 hunks)
  • tests/test_resources/test_mariadb_operator.py (1 hunks)
  • tests/test_resources/test_mig_analytic.py (1 hunks)
  • tests/test_resources/test_mig_cluster.py (1 hunks)
  • tests/test_resources/test_mig_migration.py (1 hunks)
  • tests/test_resources/test_mig_plan.py (1 hunks)
  • tests/test_resources/test_model_registry.py (1 hunks)
  • tests/test_resources/test_model_registry_components_platform_opendatahub_io.py (1 hunks)
  • tests/test_resources/test_model_registry_modelregistry_opendatahub_io.py (1 hunks)
  • tests/test_resources/test_mtq.py (1 hunks)
  • tests/test_resources/test_namespace.py (1 hunks)
  • tests/test_resources/test_network_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_network_operator_openshift_io.py (1 hunks)
  • tests/test_resources/test_nm_state.py (1 hunks)
  • tests/test_resources/test_node.py (1 hunks)
  • tests/test_resources/test_node_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_node_network_configuration_policy_latest.py (1 hunks)
  • tests/test_resources/test_notebook.py (1 hunks)
  • tests/test_resources/test_oauth.py (1 hunks)
  • tests/test_resources/test_operator.py (1 hunks)
  • tests/test_resources/test_pod.py (1 hunks)
  • tests/test_resources/test_pod_metrics.py (1 hunks)
  • tests/test_resources/test_project_config_openshift_io.py (1 hunks)
  • tests/test_resources/test_project_project_openshift_io.py (1 hunks)
  • tests/test_resources/test_project_request.py (1 hunks)
  • tests/test_resources/test_prometheus.py (1 hunks)
  • tests/test_resources/test_replica_set.py (1 hunks)
  • tests/test_resources/test_scheduler.py (1 hunks)
  • tests/test_resources/test_security_context_constraints.py (1 hunks)
  • tests/test_resources/test_self_subject_review.py (1 hunks)
  • tests/test_resources/test_service.py (1 hunks)
  • tests/test_resources/test_service_mesh_member.py (1 hunks)
  • tests/test_resources/test_service_serving_knative_dev.py (1 hunks)
  • tests/test_resources/test_serving_runtime.py (1 hunks)
  • tests/test_resources/test_snapshot.py (1 hunks)
  • tests/test_resources/test_ssp.py (1 hunks)
  • tests/test_resources/test_storage_cluster.py (1 hunks)
  • tests/test_resources/test_user.py (1 hunks)
  • tests/test_resources/test_user_defined_network.py (1 hunks)
  • tests/test_resources/test_virtual_machine_cluster_instancetype.py (1 hunks)
  • tests/test_resources/test_virtual_machine_cluster_preference.py (1 hunks)
  • tests/test_resources/test_virtual_machine_export.py (1 hunks)
  • tests/test_resources/test_virtual_machine_instance_migration.py (1 hunks)
  • tests/test_resources/test_virtual_machine_instance_preset.py (1 hunks)
  • tests/test_resources/test_virtual_machine_instance_replica_set.py (1 hunks)
  • tests/test_resources/test_virtual_machine_instancetype.py (1 hunks)
  • tests/test_resources/test_virtual_machine_preference.py (1 hunks)
  • tests/test_resources/test_volume_snapshot.py (1 hunks)
  • tests/test_resources/test_volume_snapshot_class.py (1 hunks)
✅ Files skipped from review due to trivial changes (11)
  • tests/test_resources/test_config_map.py
  • tests/test_resources/test_inference_graph.py
  • tests/test_resources/test_mig_cluster.py
  • tests/test_resources/test_self_subject_review.py
  • tests/test_resources/test_virtual_machine_instancetype.py
  • tests/test_resources/test_notebook.py
  • tests/test_resources/test_security_context_constraints.py
  • tests/test_resources/test_volume_snapshot.py
  • tests/test_resources/test_network_config_openshift_io.py
  • tests/test_resources/test_llama_stack_distribution.py
  • tests/test_resources/test_serving_runtime.py
🚧 Files skipped from review as they are similar to previous changes (69)
  • .flake8
  • tests/test_resources/test_direct_volume_migration.py
  • tests/test_resources/test_dsc_initialization.py
  • tests/test_resources/test_project_config_openshift_io.py
  • tests/test_resources/test_operator.py
  • tests/test_resources/test_user_defined_network.py
  • tests/test_resources/test_storage_cluster.py
  • tests/test_resources/test_pod_metrics.py
  • tests/test_resources/test_authorino.py
  • tests/test_resources/test_dns_config_openshift_io.py
  • tests/test_resources/test_group.py
  • tests/test_resources/test_console_config_openshift_io.py
  • tests/test_resources/test_model_registry_modelregistry_opendatahub_io.py
  • tests/test_resources/test_kubelet_config.py
  • tests/test_resources/test_aaq.py
  • tests/test_resources/test_mig_plan.py
  • tests/test_resources/test_cdi.py
  • tests/test_resources/test_dns_operator_openshift_io.py
  • tests/test_resources/test_namespace.py
  • tests/test_resources/test_snapshot.py
  • tests/test_resources/test_machine.py
  • tests/test_resources/test_oauth.py
  • tests/test_resources/test_node_network_configuration_policy_latest.py
  • tests/test_resources/test_service.py
  • tests/test_resources/test_guardrails_orchestrator.py
  • tests/test_resources/test_image_config_openshift_io.py
  • tests/test_resources/test_data_science_cluster.py
  • tests/test_resources/test_service_mesh_member.py
  • tests/test_resources/test_image_image_openshift_io.py
  • tests/test_resources/test_mig_migration.py
  • tests/test_resources/test_ssp.py
  • tests/test_resources/test_project_request.py
  • tests/test_resources/test_virtual_machine_cluster_instancetype.py
  • tests/test_resources/test_cluster_user_defined_network.py
  • tests/test_resources/test_maria_db.py
  • tests/test_resources/test_kubevirt.py
  • tests/test_resources/test_csi_driver.py
  • tests/test_resources/test_kube_descheduler.py
  • tests/test_resources/test_mariadb_operator.py
  • tests/test_resources/test_model_registry.py
  • tests/test_resources/test_nm_state.py
  • tests/test_resources/test_replica_set.py
  • tests/test_resources/test_node_config_openshift_io.py
  • tests/test_resources/test_mtq.py
  • tests/test_resources/test_network_operator_openshift_io.py
  • tests/test_resources/test_cluster_resource_quota.py
  • tests/test_resources/test_virtual_machine_instance_migration.py
  • tests/test_resources/test_lm_eval_job.py
  • tests/test_resources/test_console_operator_openshift_io.py
  • tests/test_resources/test_deployment.py
  • tests/test_resources/test_prometheus.py
  • tests/test_resources/test_virtual_machine_preference.py
  • tests/test_resources/test_data_import_cron.py
  • tests/test_resources/test_node.py
  • tests/test_resources/test_user.py
  • tests/test_resources/test_api_server.py
  • tests/test_resources/test_direct_volume_migration_progress.py
  • tests/test_resources/test_model_registry_components_platform_opendatahub_io.py
  • tests/test_resources/test_image_content_source_policy.py
  • tests/test_resources/test_service_serving_knative_dev.py
  • tests/test_resources/test_virtual_machine_instance_preset.py
  • tests/test_resources/test_volume_snapshot_class.py
  • tests/test_resources/test_pod.py
  • tests/test_resources/test_virtual_machine_export.py
  • tests/test_resources/test_project_project_openshift_io.py
  • tests/test_resources/test_virtual_machine_cluster_preference.py
  • tests/test_resources/test_cdi_config.py
  • tests/test_resources/test_virtual_machine_instance_replica_set.py
  • tests/test_resources/test_mig_analytic.py
🧰 Additional context used
🧠 Learnings (3)
tests/test_resources/test_scheduler.py (3)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
Learnt from: dbasunag
PR: RedHatQE/openshift-python-wrapper#2178
File: tests/test_unittests.py:62-67
Timestamp: 2024-11-26T18:59:33.316Z
Learning: In this codebase, it's acceptable to modify function-scoped fixtures within tests, as it does not impact other tests.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:96-160
Timestamp: 2024-10-09T14:25:49.618Z
Learning: The code in the `class_generator/tests/manifests/ServingRuntime/serving_runtime.py` file is auto-generated. Avoid suggesting refactoring changes to auto-generated code in this path.
tests/scripts/generate_pytest_test.py (8)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2209
File: ocp_resources/volume_snapshot_class.py:0-0
Timestamp: 2024-12-03T08:02:11.880Z
Learning: In generated code files like `ocp_resources/volume_snapshot_class.py`, avoid suggesting adding validation checks or modifications, as generated code should not be manually altered.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:9-10
Timestamp: 2024-10-09T14:23:46.600Z
Learning: In the file `class_generator/tests/manifests/ServingRuntime/serving_runtime.py`, the `ServingRuntime` class is auto-generated code. Do not request adding descriptions to docstrings when reviewing auto-generated code containing placeholders like "No field description from API; please add description."
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2154
File: ocp_resources/serving_runtime.py:16-32
Timestamp: 2024-10-09T18:44:30.628Z
Learning: The file `ocp_resources/serving_runtime.py` is auto-generated code.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:96-160
Timestamp: 2024-10-09T14:25:49.618Z
Learning: The code in the `class_generator/tests/manifests/ServingRuntime/serving_runtime.py` file is auto-generated. Avoid suggesting refactoring changes to auto-generated code in this path.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2154
File: ocp_resources/serving_runtime.py:110-160
Timestamp: 2024-10-09T18:44:29.284Z
Learning: In `ocp_resources/serving_runtime.py`, the code is auto-generated and should not be manually modified.
Learnt from: sbahar619
PR: RedHatQE/openshift-python-wrapper#2124
File: ocp_resources/user_defined_network.py:303-318
Timestamp: 2024-10-08T23:43:22.342Z
Learning: When reviewing `to_dict` methods in the `UserDefinedNetwork` subclasses, avoid suggesting refactoring if it adds complexity without significant code savings.
Learnt from: sbahar619
PR: RedHatQE/openshift-python-wrapper#2124
File: ocp_resources/user_defined_network.py:303-318
Timestamp: 2024-09-26T07:27:13.102Z
Learning: When reviewing `to_dict` methods in the `UserDefinedNetwork` subclasses, avoid suggesting refactoring if it adds complexity without significant code savings.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
fake_kubernetes_client/fake_dynamic_client.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
🧬 Code Graph Analysis (2)
tests/test_resources/test_scheduler.py (6)
fake_kubernetes_client/fake_dynamic_client.py (2)
  • FakeDynamicClient (1348-1553)
  • to_dict (186-188)
ocp_resources/scheduler.py (1)
  • Scheduler (7-93)
tests/test_resources/test_api_server.py (1)
  • client (9-10)
tests/test_resources/test_aaq.py (1)
  • client (9-10)
tests/test_resource.py (2)
  • deploy (17-18)
  • clean_up (20-21)
ocp_resources/resource.py (3)
  • exists (918-925)
  • kind (671-672)
  • labels (1158-1165)
fake_kubernetes_client/fake_dynamic_client.py (23)
ocp_resources/benchmark.py (1)
  • uuid (50-55)
tests/test_resources/test_api_server.py (1)
  • client (9-10)
tests/test_resources/test_aaq.py (1)
  • client (9-10)
tests/test_resources/test_authorino.py (1)
  • client (9-10)
tests/test_resources/test_cdi_config.py (1)
  • client (9-10)
tests/test_resources/test_cdi.py (1)
  • client (9-10)
tests/test_resources/test_cluster_resource_quota.py (1)
  • client (9-10)
tests/test_resources/test_cluster_user_defined_network.py (1)
  • client (9-10)
tests/test_resources/test_config_map.py (1)
  • client (9-10)
tests/test_resources/test_console_config_openshift_io.py (1)
  • client (9-10)
tests/test_resources/test_data_import_cron.py (1)
  • client (9-10)
tests/test_resources/test_data_science_cluster.py (1)
  • client (9-10)
tests/test_resources/test_csi_driver.py (1)
  • client (9-10)
tests/test_resources/test_console_operator_openshift_io.py (1)
  • client (9-10)
tests/test_resources/test_deployment.py (1)
  • client (9-10)
tests/test_resources/test_direct_volume_migration_progress.py (1)
  • client (9-10)
tests/test_resources/test_direct_volume_migration.py (1)
  • client (9-10)
ocp_resources/project_request.py (1)
  • to_dict (36-44)
tests/test_resources/test_namespace.py (1)
  • namespace (13-17)
tests/test_resource.py (1)
  • namespace (30-31)
ocp_resources/resource.py (3)
  • kind (671-672)
  • exists (918-925)
  • labels (1158-1165)
tests/test_resources/test_group.py (1)
  • group (13-18)
ocp_resources/route.py (1)
  • host (56-60)
🪛 Pylint (3.3.7)
tests/scripts/generate_pytest_test.py

[refactor] 66-66: Too many instance attributes (10/7)

(R0902)


[refactor] 227-243: Too many nested blocks (9/5)

(R1702)


[refactor] 93-93: Too few public methods (1/2)

(R0903)


[refactor] 300-300: Too few public methods (1/2)

(R0903)


[refactor] 408-419: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 390-390: Too many return statements (8/6)

(R0911)


[refactor] 451-480: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 506-517: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 482-482: Too many return statements (8/6)

(R0911)


[refactor] 523-523: Too many branches (26/12)

(R0912)


[refactor] 523-523: Too many statements (59/50)

(R0915)


[refactor] 357-357: Too few public methods (1/2)

(R0903)


[refactor] 815-815: Too many local variables (26/15)

(R0914)


[refactor] 815-815: Too many branches (16/12)

(R0912)


[refactor] 815-815: Too many statements (62/50)

(R0915)

fake_kubernetes_client/fake_dynamic_client.py

[refactor] 148-155: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 159-166: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 735-742: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 758-758: Too many local variables (16/15)

(R0914)


[refactor] 852-852: Too many arguments (6/5)

(R0913)


[refactor] 852-852: Too many positional arguments (6/5)

(R0917)


[refactor] 877-877: Too many local variables (18/15)

(R0914)


[refactor] 877-877: Too many return statements (8/6)

(R0911)


[refactor] 877-877: Too many branches (18/12)

(R0912)


[refactor] 971-971: Too many branches (16/12)

(R0912)


[refactor] 1154-1154: Too many arguments (6/5)

(R0913)


[refactor] 1154-1154: Too many positional arguments (6/5)

(R0917)


[refactor] 1181-1181: Too many arguments (6/5)

(R0913)


[refactor] 1181-1181: Too many positional arguments (6/5)

(R0917)


[refactor] 1250-1250: Too many branches (14/12)

(R0912)


[refactor] 1323-1323: Too few public methods (0/2)

(R0903)


[refactor] 1333-1333: Too few public methods (1/2)

(R0903)


[refactor] 1434-1437: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1441-1444: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1448-1451: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1455-1458: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1462-1465: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1469-1472: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1549-1553: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1577-1577: Too many local variables (17/15)

(R0914)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: conventional-title
  • GitHub Check: tox
  • GitHub Check: python-module-install
🔇 Additional comments (8)
fake_kubernetes_client/fake_dynamic_client.py (8)

47-100: Good exception compatibility strategy.

The conditional import with fallback exception classes provides good compatibility when the kubernetes module isn't available. The fallback exceptions maintain the same interface as the real ones.


251-324: Comprehensive resource creation logic.

The create() method provides thorough validation, metadata generation, and realistic status handling. The special case for ProjectRequest creating a corresponding Project resource accurately simulates real OpenShift behavior.


358-407: Resource-agnostic event generation is well designed.

The _generate_resource_events() method is completely generic and works for any resource type, generating realistic Kubernetes events with proper metadata structure.


796-798: Fix potential issue with continue statement.

The code shows continue instead of return None when is_namespaced is None. This was correctly fixed from the past review comment that mentioned "return None" here.


1212-1248: Label selector parsing is robust.

The label selector implementation correctly handles equality, inequality, and properly filters resources. The parsing logic is sound for the supported selector types.


1323-1346: Stub classes are appropriately minimal.

The FakeConfiguration and FakeKubernetesClient classes provide just enough functionality to satisfy the interface requirements. The "too few public methods" warnings are false positives for these stub classes.


1559-1572: Well-designed convenience functions.

The factory functions create_fake_client_with_resources() and create_fake_client_with_custom_resources() provide clean, reusable ways to set up test clients with specific data.


1577-1657: Comprehensive test demonstrates full capabilities.

The test_generic_resource_support() function provides excellent coverage of the fake client's capabilities, testing custom CRDs, cluster-scoped resources, complex API groups, and CRUD operations.

Copy link

@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: 1

♻️ Duplicate comments (2)
tests/scripts/generate_pytest_test.py (2)

227-243: Refactor deeply nested code for better readability

The method has 5 levels of nesting which makes it hard to read and maintain. Consider extracting the inner logic.

This matches the previous review comment about reducing nesting levels by extracting helper methods for processing raise statements and parameter extraction.


929-929: Fix cloup command invocation.

For cloup commands, the function should be called directly without the .main() attribute.

 if __name__ == "__main__":
-    main.main()
+    main()

Cloup commands are invoked directly as functions, not through a .main() method. The current approach may fail at runtime.

🧹 Nitpick comments (2)
tests/scripts/generate_pytest_test.py (2)

523-607: Consider refactoring the large _generate_test_data method.

This method has 26 branches and 59 statements, making it complex to maintain. Consider extracting resource-specific data generation into separate methods.

Example approach:

 def _generate_test_data(self, resource: ResourceInfo) -> dict[str, Any]:
     """Generate realistic test data for a resource"""
     data = {"name": f"test-{resource.name.lower()}"}
     
     if resource.base_class == "NamespacedResource":
         data["namespace"] = "default"
     
+    # Delegate to resource-specific generators
+    self._add_resource_specific_data(resource, data)
+    self._add_required_params(resource, data)
+    
+    return data
+
+def _add_resource_specific_data(self, resource: ResourceInfo, data: dict) -> None:
+    """Add resource-specific test data"""
+    # Move the large if/elif chain here
+    
+def _add_required_params(self, resource: ResourceInfo, data: dict) -> None:
+    """Add additional required parameters"""
+    # Move the required params logic here

34-46: Consider adding explicit imports for better type checking.

The Union type is used in the code but not imported, which could cause runtime errors.

 from typing import Any, get_type_hints, get_origin, get_args
+from typing import Union

This makes the Union type available for the type checking logic and improves code clarity.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f52b7e and 7a6d0d3.

📒 Files selected for processing (1)
  • tests/scripts/generate_pytest_test.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
tests/scripts/generate_pytest_test.py (8)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2209
File: ocp_resources/volume_snapshot_class.py:0-0
Timestamp: 2024-12-03T08:02:11.880Z
Learning: In generated code files like `ocp_resources/volume_snapshot_class.py`, avoid suggesting adding validation checks or modifications, as generated code should not be manually altered.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2154
File: ocp_resources/serving_runtime.py:16-32
Timestamp: 2024-10-09T18:44:30.628Z
Learning: The file `ocp_resources/serving_runtime.py` is auto-generated code.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:9-10
Timestamp: 2024-10-09T14:23:46.600Z
Learning: In the file `class_generator/tests/manifests/ServingRuntime/serving_runtime.py`, the `ServingRuntime` class is auto-generated code. Do not request adding descriptions to docstrings when reviewing auto-generated code containing placeholders like "No field description from API; please add description."
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2154
File: ocp_resources/serving_runtime.py:110-160
Timestamp: 2024-10-09T18:44:29.284Z
Learning: In `ocp_resources/serving_runtime.py`, the code is auto-generated and should not be manually modified.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:96-160
Timestamp: 2024-10-09T14:25:49.618Z
Learning: The code in the `class_generator/tests/manifests/ServingRuntime/serving_runtime.py` file is auto-generated. Avoid suggesting refactoring changes to auto-generated code in this path.
Learnt from: sbahar619
PR: RedHatQE/openshift-python-wrapper#2124
File: ocp_resources/user_defined_network.py:303-318
Timestamp: 2024-10-08T23:43:22.342Z
Learning: When reviewing `to_dict` methods in the `UserDefinedNetwork` subclasses, avoid suggesting refactoring if it adds complexity without significant code savings.
Learnt from: sbahar619
PR: RedHatQE/openshift-python-wrapper#2124
File: ocp_resources/user_defined_network.py:303-318
Timestamp: 2024-09-26T07:27:13.102Z
Learning: When reviewing `to_dict` methods in the `UserDefinedNetwork` subclasses, avoid suggesting refactoring if it adds complexity without significant code savings.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
🪛 Pylint (3.3.7)
tests/scripts/generate_pytest_test.py

[refactor] 66-66: Too many instance attributes (10/7)

(R0902)


[refactor] 227-243: Too many nested blocks (9/5)

(R1702)


[refactor] 93-93: Too few public methods (1/2)

(R0903)


[refactor] 300-300: Too few public methods (1/2)

(R0903)


[refactor] 408-419: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 390-390: Too many return statements (8/6)

(R0911)


[refactor] 451-480: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 506-517: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 482-482: Too many return statements (8/6)

(R0911)


[refactor] 523-523: Too many branches (26/12)

(R0912)


[refactor] 523-523: Too many statements (59/50)

(R0915)


[refactor] 357-357: Too few public methods (1/2)

(R0903)


[refactor] 815-815: Too many local variables (26/15)

(R0914)


[refactor] 815-815: Too many branches (16/12)

(R0912)


[refactor] 815-815: Too many statements (62/50)

(R0915)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: tox
  • GitHub Check: conventional-title
  • GitHub Check: python-module-install
🔇 Additional comments (2)
tests/scripts/generate_pytest_test.py (2)

1-32: Comprehensive documentation and feature overview.

The docstring provides excellent usage examples and feature documentation, making the script easy to understand and use.


612-736: Well-structured Jinja2 templates for test generation.

The templates provide comprehensive test coverage including CRUD operations and proper handling of ephemeral resources. The separation between regular and ephemeral resource templates is well-designed.

@myakove
Copy link
Collaborator Author

myakove commented Jul 6, 2025

/verified

Copy link

@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: 1

♻️ Duplicate comments (4)
tests/scripts/generate_pytest_test.py (2)

227-243: Refactor deeply nested code for better readability

The method has 5 levels of nesting which makes it hard to read and maintain. Consider extracting the inner logic.


497-503: Fix Union type detection logic to avoid incorrect handling of generic types

The current logic get_origin(param_type) is not None matches any generic type (List, Dict, etc.), not just Union types. This could cause incorrect parameter extraction for non-Union generics.

-        # Handle Union types (e.g., bool | None, str | None)
-        if type(param_type) is types.UnionType or get_origin(param_type) is not None:
+        # Handle Union types (e.g., bool | None, str | None)  
+        from typing import Union
+        if type(param_type) is types.UnionType or get_origin(param_type) is Union:
fake_kubernetes_client/fake_dynamic_client.py (2)

198-207: The confusing items() method behavior remains unaddressed.

As noted in previous reviews, this method returns the value of the 'items' key from data instead of the dictionary's items(), which is unexpected and could lead to bugs.


951-978: Method complexity issue remains unaddressed.

The _create_resource_def_from_mappings method still has excessive complexity with 18 local variables, 8 return statements, and 18 branches. As noted in previous reviews, this should be refactored into smaller helper methods for better maintainability and testability.

🧹 Nitpick comments (11)
tests/scripts/generate_pytest_test.py (6)

42-42: Import Union type at module level for consistent usage

The Union type is used in line 498 but needs to be imported. Move the import to the top level to avoid repeated imports in functions.

-from typing import Any, Union, get_type_hints, get_origin, get_args
+from typing import Any, Union, get_type_hints, get_origin, get_args

Note: Union is already imported, so the fix in lines 497-503 should simply use the existing import.


523-607: Consider breaking down complex test data generation method

The method has 26 branches and 59 statements, making it hard to maintain. Consider extracting resource-specific logic into separate methods.

For example, extract the resource-specific cases:

def _generate_test_data(self, resource: ResourceInfo) -> dict[str, Any]:
    """Generate realistic test data for a resource"""
    data = self._get_base_test_data(resource)
    self._add_resource_specific_data(resource, data)
    self._add_required_params_data(resource, data)
    return data

def _get_base_test_data(self, resource: ResourceInfo) -> dict[str, Any]:
    """Get base test data common to all resources"""
    data = {"name": f"test-{resource.name.lower()}"}
    if resource.base_class == "NamespacedResource":
        data["namespace"] = "default"
    return data

def _add_resource_specific_data(self, resource: ResourceInfo, data: dict[str, Any]) -> None:
    """Add resource-specific test data"""
    # Move the large if/elif chain here
    
def _add_required_params_data(self, resource: ResourceInfo, data: dict[str, Any]) -> None:
    """Add data for required parameters"""
    # Move the required params logic here

815-930: Consider breaking down the main function

The main function has 26 local variables, 16 branches, and 62 statements. Consider extracting the test generation and execution logic into separate methods.

Example structure:

def main(kind, check_coverage, generate_missing, dry_run):
    """Main entry point"""
    console.print("[bold blue]OCP Resources Pytest Test Generator[/bold blue]")
    
    resources, coverage = _initialize_and_scan()
    
    if check_coverage:
        print_coverage_report(coverage)
        return
    
    target_resources = _determine_target_resources(kind, generate_missing, resources, coverage)
    if not target_resources:
        return
        
    _generate_and_run_tests(target_resources, dry_run)

def _initialize_and_scan():
    """Initialize components and scan resources"""
    
def _determine_target_resources(kind, generate_missing, resources, coverage):
    """Determine which resources to generate tests for"""
    
def _generate_and_run_tests(target_resources, dry_run):
    """Generate tests and run them"""

57-62: Document the ephemeral resources mapping

Consider adding more documentation about how to identify and add new ephemeral resources to this mapping.

# Static mapping of ephemeral resources to their actual resource types
+# Ephemeral resources are those that don't persist but create other resources
+# To add new ephemeral resources:
+# 1. Identify the resource type created by the ephemeral resource
+# 2. Add mapping: "EphemeralResourceName": "ActualResourceType"
EPHEMERAL_RESOURCES = {
    "ProjectRequest": "Project",  # ProjectRequest creates Project
    # Add more ephemeral resources here as discovered:
    # "SomeOtherEphemeralResource": "ActualResourceType",
}

540-540: Security: Consider using a more generic secret value

The hardcoded password value could be flagged by security scanners despite the allowlist comment.

-            data["string_data"] = {"password": "secret123"}  # pragma: allowlist secret
+            data["string_data"] = {"password": "test-password"}  # pragma: allowlist secret

104-115: Add validation for Python file processing

Consider adding more robust validation when processing Python files to handle edge cases.

        for py_file in self.ocp_resources_path.glob("*.py"):
            if py_file.name in self.exclude_files:
                continue
+            
+            # Skip files that are too large or empty
+            try:
+                stat = py_file.stat()
+                if stat.st_size == 0 or stat.st_size > 1024 * 1024:  # Skip files > 1MB
+                    console.print(f"[yellow]Skipping {py_file}: invalid size[/yellow]")
+                    continue
+            except OSError:
+                console.print(f"[yellow]Warning: Cannot access {py_file}[/yellow]")
+                continue

            try:
                resource_info = self._analyze_resource_file(py_file)
fake_kubernetes_client/fake_dynamic_client.py (5)

148-155: Remove unnecessary elif after return.

Since line 149 has a return statement, the elif on line 150 is unnecessary and can be simplified to a regular if statement.

         if value is None:
             return FakeResourceField(data={})
-        elif isinstance(value, dict):
+        if isinstance(value, dict):
             return FakeResourceField(data=value)
-        elif isinstance(value, list):
+        if isinstance(value, list):
             return [FakeResourceField(data=item) if isinstance(item, dict) else item for item in value]
-        else:
-            return value
+        return value

735-742: Simplify plural generation logic.

Remove unnecessary elif statements after return to improve readability.

         if kind_lower.endswith("s"):
             return kind_lower
-        elif kind_lower.endswith("y"):
+        if kind_lower.endswith("y"):
             return kind_lower[:-1] + "ies"
-        elif kind_lower.endswith(("sh", "ch", "x", "z")):
+        if kind_lower.endswith(("sh", "ch", "x", "z")):
             return kind_lower + "es"
-        else:
-            return kind_lower + "s"
+        return kind_lower + "s"

1441-1481: Remove unnecessary else statements after return.

Multiple delegation methods have unnecessary else clauses after return statements. This pattern can be simplified for better readability.

Example for the get method:

     def get(self, resource, name=None, namespace=None, **kwargs):
         """Get resource(s) using resource definition"""
         if hasattr(resource, "get"):
             return resource.get(name=name, namespace=namespace, **kwargs)
-        else:
-            raise ValueError("Invalid resource definition")
+        raise ValueError("Invalid resource definition")

Apply the same pattern to all delegation methods (create, delete, patch, replace, watch).


1163-1171: Consider parameter object for storage operations.

The store_resource method has many parameters. Consider using a parameter object or dataclass to group related parameters and improve maintainability.

@dataclass
class ResourceStorageParams:
    kind: str
    api_version: str
    name: str
    namespace: Optional[str]
    resource: dict

def store_resource(self, params: ResourceStorageParams):
    """Store any resource type - completely resource-agnostic"""
    # Use params.kind, params.api_version, etc.

1586-1665: Consider breaking down large test function.

The test_generic_resource_support function has 17 local variables and tests multiple scenarios. Consider splitting it into focused test functions for better maintainability and debugging.

For example:

def test_custom_crd_support():
    """Test custom CRD functionality"""
    # Test 1 content

def test_cluster_scoped_resources():
    """Test cluster-scoped resource handling"""
    # Test 2 content

def test_complex_api_groups():
    """Test complex API group parsing"""
    # Test 3 content
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7a6d0d3 and 0cad015.

📒 Files selected for processing (2)
  • fake_kubernetes_client/fake_dynamic_client.py (1 hunks)
  • tests/scripts/generate_pytest_test.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
fake_kubernetes_client/fake_dynamic_client.py (1)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
tests/scripts/generate_pytest_test.py (8)
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2209
File: ocp_resources/volume_snapshot_class.py:0-0
Timestamp: 2024-12-03T08:02:11.880Z
Learning: In generated code files like `ocp_resources/volume_snapshot_class.py`, avoid suggesting adding validation checks or modifications, as generated code should not be manually altered.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2154
File: ocp_resources/serving_runtime.py:16-32
Timestamp: 2024-10-09T18:44:30.628Z
Learning: The file `ocp_resources/serving_runtime.py` is auto-generated code.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:9-10
Timestamp: 2024-10-09T14:23:46.600Z
Learning: In the file `class_generator/tests/manifests/ServingRuntime/serving_runtime.py`, the `ServingRuntime` class is auto-generated code. Do not request adding descriptions to docstrings when reviewing auto-generated code containing placeholders like "No field description from API; please add description."
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2154
File: ocp_resources/serving_runtime.py:110-160
Timestamp: 2024-10-09T18:44:29.284Z
Learning: In `ocp_resources/serving_runtime.py`, the code is auto-generated and should not be manually modified.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2152
File: class_generator/tests/manifests/ServingRuntime/serving_runtime.py:96-160
Timestamp: 2024-10-09T14:25:49.618Z
Learning: The code in the `class_generator/tests/manifests/ServingRuntime/serving_runtime.py` file is auto-generated. Avoid suggesting refactoring changes to auto-generated code in this path.
Learnt from: sbahar619
PR: RedHatQE/openshift-python-wrapper#2124
File: ocp_resources/user_defined_network.py:303-318
Timestamp: 2024-10-08T23:43:22.342Z
Learning: When reviewing `to_dict` methods in the `UserDefinedNetwork` subclasses, avoid suggesting refactoring if it adds complexity without significant code savings.
Learnt from: sbahar619
PR: RedHatQE/openshift-python-wrapper#2124
File: ocp_resources/user_defined_network.py:303-318
Timestamp: 2024-09-26T07:27:13.102Z
Learning: When reviewing `to_dict` methods in the `UserDefinedNetwork` subclasses, avoid suggesting refactoring if it adds complexity without significant code savings.
Learnt from: myakove
PR: RedHatQE/openshift-python-wrapper#2232
File: tests/test_resources.py:21-23
Timestamp: 2024-12-15T08:13:40.715Z
Learning: In the `pod` fixture in `tests/test_resources.py`, it is expected that there will always be at least one pod available, and the test should fail if there are none.
🧬 Code Graph Analysis (1)
fake_kubernetes_client/fake_dynamic_client.py (3)
tests/test_resources/test_namespace.py (1)
  • namespace (13-17)
tests/test_resource.py (1)
  • namespace (30-31)
ocp_resources/resource.py (2)
  • exists (918-925)
  • labels (1158-1165)
🪛 Pylint (3.3.7)
fake_kubernetes_client/fake_dynamic_client.py

[refactor] 148-155: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 159-166: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 735-742: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 758-758: Too many local variables (16/15)

(R0914)


[refactor] 852-852: Too many arguments (6/5)

(R0913)


[refactor] 852-852: Too many positional arguments (6/5)

(R0917)


[refactor] 980-980: Too many branches (16/12)

(R0912)


[refactor] 1163-1163: Too many arguments (6/5)

(R0913)


[refactor] 1163-1163: Too many positional arguments (6/5)

(R0917)


[refactor] 1190-1190: Too many arguments (6/5)

(R0913)


[refactor] 1190-1190: Too many positional arguments (6/5)

(R0917)


[refactor] 1259-1259: Too many branches (14/12)

(R0912)


[refactor] 1332-1332: Too few public methods (0/2)

(R0903)


[refactor] 1342-1342: Too few public methods (1/2)

(R0903)


[refactor] 1443-1446: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1450-1453: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1457-1460: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1464-1467: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1471-1474: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1478-1481: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1558-1562: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 1586-1586: Too many local variables (17/15)

(R0914)

tests/scripts/generate_pytest_test.py

[refactor] 66-66: Too many instance attributes (10/7)

(R0902)


[refactor] 227-243: Too many nested blocks (9/5)

(R1702)


[refactor] 93-93: Too few public methods (1/2)

(R0903)


[refactor] 300-300: Too few public methods (1/2)

(R0903)


[refactor] 408-419: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 390-390: Too many return statements (8/6)

(R0911)


[refactor] 451-480: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 506-517: Unnecessary "elif" after "return", remove the leading "el" from "elif"

(R1705)


[refactor] 482-482: Too many return statements (8/6)

(R0911)


[refactor] 523-523: Too many branches (26/12)

(R0912)


[refactor] 523-523: Too many statements (59/50)

(R0915)


[refactor] 357-357: Too few public methods (1/2)

(R0903)


[refactor] 815-815: Too many local variables (26/15)

(R0914)


[refactor] 815-815: Too many branches (16/12)

(R0912)


[refactor] 815-815: Too many statements (62/50)

(R0915)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: python-module-install
  • GitHub Check: conventional-title
  • GitHub Check: tox
🔇 Additional comments (3)
tests/scripts/generate_pytest_test.py (1)

929-929: LGTM: Correct cloup command invocation

The main function is correctly invoked using main.main() for cloup commands.

fake_kubernetes_client/fake_dynamic_client.py (2)

358-407: Excellent resource-agnostic event generation design.

The _generate_resource_events method is well-designed to automatically create realistic Kubernetes events for any resource type without hardcoded mappings, which maintains the fake client's flexibility.


409-556: Well-structured realistic status generation.

The dynamic status generation based on resource kind provides realistic test data while maintaining the resource-agnostic design principle. The fallback to generic status for unknown resource types is a good pattern.

@rnetser
Copy link
Collaborator

rnetser commented Jul 6, 2025

/approve

@rnetser rnetser enabled auto-merge (squash) July 6, 2025 11:20
@rnetser
Copy link
Collaborator

rnetser commented Jul 6, 2025

/lgtm

@rnetser rnetser merged commit cb14561 into main Jul 6, 2025
7 checks passed
@rnetser rnetser deleted the fake-client branch July 6, 2025 11:21
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.

6 participants