Skip to content

Conversation

onmete
Copy link
Contributor

@onmete onmete commented Jul 23, 2025

Description

Use patches in test_is_feedback_enabled and test_is_feedback_disabled to not modify global config value.

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Related Tickets & Documents

https://issues.redhat.com/browse/LCORE-175

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Summary by CodeRabbit

  • Tests
    • Improved test reliability by updating feedback configuration tests to use temporary overrides during execution.

Copy link
Contributor

coderabbitai bot commented Jul 23, 2025

Walkthrough

The unit tests for the is_feedback_enabled function were updated to use unittest.mock.patch for temporarily overriding the feedback_enabled configuration flag during test execution. The patch is applied as a context manager to ensure the original configuration is restored after each test.

Changes

File(s) Change Summary
tests/unit/app/endpoints/test_feedback.py Updated tests to use unittest.mock.patch for overriding feedback_enabled instead of direct set.

Estimated code review effort

1 (~2 minutes)

Poem

In the warren of tests, a patch hopped in,
To mock the config flag with a whiskered grin.
No more direct tweaks, just context and care,
Feedback now toggles with elegance rare.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

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

Support

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

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

CodeRabbit Commands (Invoked using PR comments)

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

Other keywords and placeholders

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

CodeRabbit Configuration File (.coderabbit.yaml)

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

Documentation and Community

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/unit/app/endpoints/test_feedback.py (1)

107-107: Consider extending the patching approach to other tests for consistency.

While the main objective of this PR has been achieved, there are still other tests in this file that directly modify global configuration values (lines 107 and 138). For better test isolation and consistency, consider applying the same patching approach to these tests as well.

For example, test_store_feedback could use:

with patch("app.endpoints.feedback.configuration.user_data_collection_configuration.feedback_storage", "fake-path"):

And test_feedback_status could use:

with patch("app.endpoints.feedback.configuration.user_data_collection_configuration.feedback_enabled", True):

Also applies to: 138-138

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f9a17ea and 4b33967.

📒 Files selected for processing (1)
  • tests/unit/app/endpoints/test_feedback.py (2 hunks)
🧬 Code Graph Analysis (1)
tests/unit/app/endpoints/test_feedback.py (1)
src/app/endpoints/feedback.py (1)
  • is_feedback_enabled (41-47)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/unit/app/endpoints/test_feedback.py (1)
src/app/endpoints/feedback.py (1)
  • is_feedback_enabled (41-47)
🔇 Additional comments (3)
tests/unit/app/endpoints/test_feedback.py (3)

3-3: LGTM: Import addition is correct and necessary.

The import of patch from unittest.mock is properly added to support the refactored test methods.


20-24: Excellent refactoring: Improved test isolation with proper patching.

The use of patch context manager instead of direct global config modification is a significant improvement. This ensures the original configuration is automatically restored after the test, preventing side effects on other tests.


29-33: LGTM: Consistent implementation with the enabled test.

The patching approach is correctly applied here as well, maintaining consistency with the test_is_feedback_enabled function while testing the opposite scenario.

@onmete
Copy link
Contributor Author

onmete commented Jul 23, 2025

/retest

@onmete onmete changed the title OLS-1946: Use patches to not modify global config value in test_feedback LCORE-175: Use patches to not modify global config value in test_feedback Jul 23, 2025
@tisnik
Copy link
Contributor

tisnik commented Jul 23, 2025

@matysek anything we should worry about ^? It seems to be related with the new Python image

@onmete
Copy link
Contributor Author

onmete commented Jul 23, 2025

I think the error was in my other PR too, but was fixed by retest after I pushed some changes there. Can you try to hit the retest? It seems I don't have that option.

Copy link
Contributor

@umago umago left a comment

Choose a reason for hiding this comment

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

The error in the CI seems unrelated:

Error: creating build container: initializing source docker://registry.access.redhat.com/ubi9/python-312-minimal:latest: reading manifest latest in registry.access.redhat.com/ubi9/python-312-minimal: received unexpected HTTP status: 500 Internal Server Error

Copy link
Contributor

@umago umago left a comment

Choose a reason for hiding this comment

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

Actually, fat fingered the approve. I think we should use pytest instead of the built-in module for consistency

@@ -1,5 +1,7 @@
"""Unit tests for the /feedback REST API endpoint."""

from unittest.mock import patch
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use pytest

)


def test_is_feedback_enabled():
Copy link
Contributor

Choose a reason for hiding this comment

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

def test_is_feedback_enabled(mocker):
...
    with mocker.patch(....

assert is_feedback_enabled() is True, "Feedback should be enabled"


def test_is_feedback_disabled():
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto, let's use mocker instead of built-in mock since we already use pytest

@tisnik
Copy link
Contributor

tisnik commented Jul 24, 2025

/retest

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants