Skip to content

Fix test_check_up_debug_fail - #157

Merged
Universal-Omega merged 1 commit into
miraheze:mainfrom
BlankEclair:mwdeploy-fix-test
Jul 14, 2025
Merged

Fix test_check_up_debug_fail#157
Universal-Omega merged 1 commit into
miraheze:mainfrom
BlankEclair:mwdeploy-fix-test

Conversation

@BlankEclair

@BlankEclair BlankEclair commented Jul 14, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Tests
    • Updated a test to use a different domain for simulating a failure scenario.

@coderabbitai

coderabbitai Bot commented Jul 14, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A test in the tests/test_mwdeploy.py file was updated to use a different domain when invoking the mwdeploy.check_up function. The domain argument was changed from 'httpstat.us/500' to 'meta.miraheze.org/cache', while the expected assertion outcome remains unchanged.

Changes

File(s) Change Summary
tests/test_mwdeploy.py Updated test to use a different domain in the test_check_up_debug_fail test case.

Poem

A bunny hopped through lines of code,
Swapping domains on the testing road.
From errors of five hundred, it did dash,
To Miraheze's cache in a flash!
Tests still pass or fail as planned,
With every change, the code is scanned.
🐇

✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8270d1d and 8a3bc6a.

📒 Files selected for processing (1)
  • tests/test_mwdeploy.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: RhinosF1
PR: miraheze/python-functions#4
File: tests/test_iaupload.py:50-59
Timestamp: 2024-07-26T21:00:05.787Z
Learning: When testing the `upload` method of the `ArchiveUploader` class, mock the `internetarchive.get_item` and other network-related calls to make the tests more reliable and faster.
Learnt from: RhinosF1
PR: miraheze/python-functions#4
File: tests/test_iaupload.py:50-59
Timestamp: 2024-10-08T17:05:15.088Z
Learning: When testing the `upload` method of the `ArchiveUploader` class, mock the `internetarchive.get_item` and other network-related calls to make the tests more reliable and faster.
Learnt from: BlankEclair
PR: miraheze/python-functions#119
File: miraheze/mediawiki/mwimport.py:59-66
Timestamp: 2025-03-07T09:54:27.055Z
Learning: The MediaWiki import tools in miraheze/python-functions are specifically designed to run only on mw* servers, where system dependencies like `/usr/local/bin/getMWVersion` and `/usr/local/bin/logsalmsg` are available.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build (3.14-dev)

Comment thread tests/test_mwdeploy.py
Comment on lines 157 to +158
def test_check_up_debug_fail() -> None:
assert not mwdeploy.check_up(nolog=True, Debug='mwtask181', domain='httpstat.us/500', force=True)
assert not mwdeploy.check_up(nolog=True, Debug='mwtask181', domain='meta.miraheze.org/cache', force=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider mocking network calls instead of relying on external services.

Changing from httpstat.us/500 to meta.miraheze.org/cache introduces network dependency that can make the test unreliable. The real endpoint may return successful responses, potentially causing the test to fail unexpectedly since it expects check_up to return False.

For more reliable testing, consider mocking the network call to ensure consistent behaviour regardless of external service availability.

-def test_check_up_debug_fail() -> None:
-    assert not mwdeploy.check_up(nolog=True, Debug='mwtask181', domain='meta.miraheze.org/cache', force=True)
+@patch('miraheze.mediawiki.mwdeploy.requests.get')
+def test_check_up_debug_fail(mock_get) -> None:
+    mock_get.return_value.status_code = 500
+    assert not mwdeploy.check_up(nolog=True, Debug='mwtask181', domain='meta.miraheze.org/cache', force=True)

🏁 Script executed:

#!/bin/bash
# Locate the definition of check_up and its HTTP call
rg -n "def check_up" -A5
# Locate where requests is imported in mwdeploy
rg -n "import requests" -A2

Length of output: 776


🏁 Script executed:

#!/bin/bash
# Show the full body of check_up to confirm how HTTP requests are made
sed -n '178,260p' miraheze/mediawiki/mwdeploy.py

Length of output: 3449


Mock the HTTP request in test_check_up_debug_fail to remove external dependencies

Relying on a live endpoint makes this test fragile. Instead, patch requests.get so you can control the response:

• Import the patch decorator:

from unittest.mock import patch

• In the test, set up the fake response to return a 500 status and empty body/headers so check_up(..., force=True) cleanly returns False without hitting the network.

Suggested diff:

-from tests/test_mwdeploy.py
+from unittest.mock import patch
+
 @patch('miraheze.mediawiki.mwdeploy.requests.get')
 def test_check_up_debug_fail(mock_get) -> None:
-    # direct network call to meta.miraheze.org/cache is flaky
-    assert not mwdeploy.check_up(nolog=True, Debug='mwtask181',
-                                 domain='meta.miraheze.org/cache', force=True)
+    # simulate an HTTP 500 from the server
+    mock_resp = mock_get.return_value
+    mock_resp.status_code = 500
+    mock_resp.text = ''
+    mock_resp.headers = {}
+
+    assert not mwdeploy.check_up(
+        nolog=True,
+        Debug='mwtask181',
+        domain='meta.miraheze.org/cache',
+        force=True
+    )

This ensures the test is deterministic and fast, without relying on external services.

🤖 Prompt for AI Agents
In tests/test_mwdeploy.py at lines 157-158, the test_check_up_debug_fail
function currently makes a real HTTP request, causing fragility. To fix this,
import patch from unittest.mock and decorate the test function to mock
requests.get. Configure the mock to return a response with status code 500 and
empty content and headers, ensuring check_up returns False without making an
actual network call. This will make the test deterministic and remove external
dependencies.

@Universal-Omega
Universal-Omega merged commit a33eae3 into miraheze:main Jul 14, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants