Merge branch 'master' of gitea.suda.codes:sudacode/jimaku-dl
This commit is contained in:
@@ -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 – God’s 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."""
|
||||
|
||||
@@ -110,6 +110,36 @@ class TestParseFilename:
|
||||
# Simple number in season directory
|
||||
file_path = os.path.join("path", "to", "My Anime", "Season 2", "5.mkv")
|
||||
title, season, episode = downloader.parse_filename(file_path)
|
||||
# Mock _prompt_for_title_info to avoid reading from stdin for the entire test function
|
||||
with patch.object(self.downloader, "_prompt_for_title_info") as mock_prompt:
|
||||
# Configure mock to return appropriate values for different test cases
|
||||
mock_prompt.side_effect = [
|
||||
("Show Name", 1, 2), # First call return value
|
||||
("Show Name", 3, 4), # Second call return value
|
||||
("My Anime", 2, 5), # Third call return value
|
||||
("Long Anime Title With Spaces", 1, 3), # Fourth call return value
|
||||
]
|
||||
|
||||
# Standard Season-## format
|
||||
title, season, episode = self.downloader.parse_filename(
|
||||
"/path/to/Show Name/Season-1/Show Name - 02 [1080p].mkv"
|
||||
)
|
||||
assert title == "Show Name"
|
||||
assert season == 1
|
||||
assert episode == 2
|
||||
|
||||
# Season ## format
|
||||
title, season, episode = self.downloader.parse_filename(
|
||||
"/path/to/Show Name/Season 03/Episode 4.mkv"
|
||||
)
|
||||
assert title == "Show Name"
|
||||
assert season == 3
|
||||
assert episode == 4
|
||||
|
||||
# Simple number in season directory
|
||||
title, season, episode = self.downloader.parse_filename(
|
||||
"/path/to/My Anime/Season 2/5.mkv"
|
||||
)
|
||||
assert title == "My Anime"
|
||||
assert season == 2
|
||||
assert episode == 5
|
||||
@@ -124,6 +154,9 @@ class TestParseFilename:
|
||||
"Long Anime Title With Spaces - 03.mkv",
|
||||
)
|
||||
title, season, episode = downloader.parse_filename(file_path)
|
||||
title, season, episode = self.downloader.parse_filename(
|
||||
"/media/user/Anime/Long Anime Title With Spaces/Season-1/Long Anime Title With Spaces - 03.mkv"
|
||||
)
|
||||
assert title == "Long Anime Title With Spaces"
|
||||
assert season == 1
|
||||
assert episode == 3
|
||||
|
||||
Reference in New Issue
Block a user