Merge branch 'master' of gitea.suda.codes:sudacode/jimaku-dl

This commit is contained in:
2025-03-12 20:40:41 -07:00
5 changed files with 86 additions and 16 deletions

View File

@@ -96,9 +96,16 @@ class TestJimakuDownloader:
# Make sure the response object has a working raise_for_status method
mock_requests["response"].raise_for_status = MagicMock()
# Test with special characters in the title
result = downloader.query_anilist(
"KonoSuba Gods blessing on this wonderful world!! (2016)", season=3
)
assert result == 123456
# Patch requests.post directly to use our mock
with patch("jimaku_dl.downloader.requests_post", return_value=mock_requests["response"]):
with patch(
"jimaku_dl.downloader.requests_post", return_value=mock_requests["response"]
):
# Test the function with title and season
result = downloader.query_anilist("Test Anime", season=1)
assert result == 123456
@@ -152,7 +159,9 @@ class TestJimakuDownloader:
mock_requests["response"].raise_for_status = MagicMock()
# Patch requests.post directly to use our mock
with patch("jimaku_dl.downloader.requests_post", return_value=mock_requests["response"]):
with patch(
"jimaku_dl.downloader.requests_post", return_value=mock_requests["response"]
):
# Test the function with title and season - should work even without API token
result = downloader.query_anilist("Test Anime", season=1)
assert result == 123456
@@ -315,16 +324,18 @@ class TestJimakuDownloader:
mock_requests["response"].json.side_effect = None
mock_requests["response"].json.return_value = mock_jimaku_entries_response
mock_requests["get"].return_value = mock_requests["response"]
# Make sure the response object has a working raise_for_status method
mock_requests["response"].raise_for_status = MagicMock()
# Patch the requests.get function directly to use our mock
with patch("jimaku_dl.downloader.requests_get", return_value=mock_requests["response"]):
with patch(
"jimaku_dl.downloader.requests_get", return_value=mock_requests["response"]
):
# Call the function and check the result
result = downloader.query_jimaku_entries(123456)
assert result == mock_jimaku_entries_response
# We won't assert on mock_requests["get"] here since it's not reliable
# due to the patching approach
@@ -335,22 +346,24 @@ class TestJimakuDownloader:
# Set the mock response
mock_requests["response"].json.side_effect = None
mock_requests["response"].json.return_value = mock_jimaku_files_response
# Create a direct mock for requests_get to verify it's called correctly
mock_get = MagicMock(return_value=mock_requests["response"])
# Patch the requests_get function directly
with patch("jimaku_dl.downloader.requests_get", mock_get):
# Call the function and check the result
result = downloader.get_entry_files(1)
assert result == mock_jimaku_files_response
# Verify proper headers were set in the API call
mock_get.assert_called_once()
url = mock_get.call_args[0][0]
assert "entries/1/files" in url
headers = mock_get.call_args[1].get('headers', {})
assert headers.get('Authorization') == 'test_token' # Changed from 'Bearer test_token'
headers = mock_get.call_args[1].get("headers", {})
assert (
headers.get("Authorization") == "test_token"
) # Changed from 'Bearer test_token'
def test_get_entry_files_no_token(self, monkeypatch):
"""Test getting entry files without API token."""