Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/test_mwdeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_check_up_debug() -> None:


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)
Comment on lines 157 to +158

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.



def test_get_staging_path() -> None:
Expand Down