diff options
author | Vitiko <[email protected]> | 2023-06-12 19:36:11 -0400 |
---|---|---|
committer | Vitiko <[email protected]> | 2023-06-12 19:36:11 -0400 |
commit | e3c4def89acc185bdbb67f8dcb7a12531e209df7 (patch) | |
tree | 0e37cb51b7a53fc65ac352722e3bdd32a5adc377 /tests | |
parent | 1c1caeb78bc156777b4f8a5f95ebc896a3922ab4 (diff) | |
download | bazarr-e3c4def89acc185bdbb67f8dcb7a12531e209df7.tar.gz bazarr-e3c4def89acc185bdbb67f8dcb7a12531e209df7.zip |
Subf2m Provider: add user-agent header configurationv1.2.2-beta.17
This change fixes empty queries.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/subliminal_patch/test_subf2m.py | 115 |
1 files changed, 54 insertions, 61 deletions
diff --git a/tests/subliminal_patch/test_subf2m.py b/tests/subliminal_patch/test_subf2m.py index 19275d48a..cdf201734 100644 --- a/tests/subliminal_patch/test_subf2m.py +++ b/tests/subliminal_patch/test_subf2m.py @@ -5,6 +5,15 @@ from subliminal_patch.providers.subf2m import Subf2mSubtitle from subzero.language import Language +_U_A = "Mozilla/5.0 (Linux; Android 10; SM-G996U Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36" + + +def provider(): + with Subf2mProvider(user_agent=_U_A) as provider: + yield provider + + @pytest.mark.parametrize( "title,year,expected_url", [ @@ -17,14 +26,13 @@ from subzero.language import Language ("Cure", 1997, "/subtitles/cure-kyua"), ], ) -def test_search_movie(movies, title, year, expected_url): +def test_search_movie(provider, movies, title, year, expected_url): movie = list(movies.values())[0] movie.title = title movie.year = year - with Subf2mProvider() as provider: - result = provider._search_movie(movie.title, movie.year) - assert result == expected_url + result = provider._search_movie(movie.title, movie.year) + assert result == expected_url @pytest.mark.parametrize( @@ -42,39 +50,33 @@ def test_search_movie(movies, title, year, expected_url): ), ], ) -def test_search_tv_show_season(series_title, season, year, expected_url): - with Subf2mProvider() as provider: - result = provider._search_tv_show_season(series_title, season, year) - assert result == expected_url +def test_search_tv_show_season(provider, series_title, season, year, expected_url): + result = provider._search_tv_show_season(series_title, season, year) + assert result == expected_url @pytest.mark.parametrize("language", [Language.fromalpha2("en"), Language("por", "BR")]) -def test_find_movie_subtitles(language): +def test_find_movie_subtitles(provider, language): path = "/subtitles/dune-2021" - with Subf2mProvider() as provider: - for sub in provider._find_movie_subtitles(path, language): - assert sub.language == language + for sub in provider._find_movie_subtitles(path, language): + assert sub.language == language @pytest.mark.parametrize("language", [Language.fromalpha2("en"), Language("por", "BR")]) -def test_find_episode_subtitles(language): +def test_find_episode_subtitles(provider, language): path = "/subtitles/breaking-bad-first-season" - with Subf2mProvider() as provider: - for sub in provider._find_episode_subtitles(path, 1, 1, language): - assert sub.language == language + for sub in provider._find_episode_subtitles(path, 1, 1, language): + assert sub.language == language -def test_find_episode_subtitles_from_complete_series_path(): +def test_find_episode_subtitles_from_complete_series_path(provider): path = "/subtitles/courage-the-cowardly-dog" - with Subf2mProvider() as provider: - for sub in provider._find_episode_subtitles( - path, 1, 1, Language.fromalpha2("en") - ): - assert sub.language == Language.fromalpha2("en") + for sub in provider._find_episode_subtitles(path, 1, 1, Language.fromalpha2("en")): + assert sub.language == Language.fromalpha2("en") -def test_list_and_download_subtitles_complete_series_pack(episodes): +def test_list_and_download_subtitles_complete_series_pack(provider, episodes): episode = list(episodes.values())[0] episode.series = "Sam & Max: Freelance Police" @@ -83,14 +85,13 @@ def test_list_and_download_subtitles_complete_series_pack(episodes): episode.season = 1 episode.episode = 21 - with Subf2mProvider() as provider: - subtitles = provider.list_subtitles(episode, {Language.fromalpha2("en")}) - assert subtitles + subtitles = provider.list_subtitles(episode, {Language.fromalpha2("en")}) + assert subtitles - subtitle = subtitles[0] - provider.download_subtitle(subtitle) + subtitle = subtitles[0] + provider.download_subtitle(subtitle) - assert subtitle.is_valid() + assert subtitle.is_valid() @pytest.fixture @@ -136,47 +137,40 @@ def test_subtitle_get_matches_episode(subtitle_episode, episodes): assert "source" not in matches -def test_list_subtitles_movie(movies): - with Subf2mProvider() as provider: - assert provider.list_subtitles(movies["dune"], {Language.fromalpha2("en")}) +def test_list_subtitles_movie(provider, movies): + assert provider.list_subtitles(movies["dune"], {Language.fromalpha2("en")}) -def test_list_subtitles_inexistent_movie(movies): - with Subf2mProvider() as provider: - assert ( - provider.list_subtitles(movies["inexistent"], {Language.fromalpha2("en")}) - == [] - ) +def test_list_subtitles_inexistent_movie(provider, movies): + assert ( + provider.list_subtitles(movies["inexistent"], {Language.fromalpha2("en")}) == [] + ) -def test_list_subtitles_episode(episodes): - with Subf2mProvider() as provider: - assert provider.list_subtitles( - episodes["breaking_bad_s01e01"], {Language.fromalpha2("en")} - ) +def test_list_subtitles_episode(provider, episodes): + assert provider.list_subtitles( + episodes["breaking_bad_s01e01"], {Language.fromalpha2("en")} + ) -def test_list_subtitles_inexistent_episode(episodes): - with Subf2mProvider() as provider: - assert ( - provider.list_subtitles(episodes["inexistent"], {Language.fromalpha2("en")}) - == [] - ) +def test_list_subtitles_inexistent_episode(provider, episodes): + assert ( + provider.list_subtitles(episodes["inexistent"], {Language.fromalpha2("en")}) + == [] + ) -def test_download_subtitle(subtitle): - with Subf2mProvider() as provider: - provider.download_subtitle(subtitle) - assert subtitle.is_valid() +def test_download_subtitle(provider, subtitle): + provider.download_subtitle(subtitle) + assert subtitle.is_valid() -def test_download_subtitle_episode(subtitle_episode): - with Subf2mProvider() as provider: - provider.download_subtitle(subtitle_episode) - assert subtitle_episode.is_valid() +def test_download_subtitle_episode(provider, subtitle_episode): + provider.download_subtitle(subtitle_episode) + assert subtitle_episode.is_valid() -def test_download_subtitle_episode_with_title(): +def test_download_subtitle_episode_with_title(provider): sub = Subf2mSubtitle( Language.fromalpha2("en"), "https://subf2m.co/subtitles/courage-the-cowardly-dog/english/2232402", @@ -185,9 +179,8 @@ def test_download_subtitle_episode_with_title(): ) sub.episode_title = "Feast of the Bullfrogs" - with Subf2mProvider() as provider: - provider.download_subtitle(sub) - assert sub.is_valid() + provider.download_subtitle(sub) + assert sub.is_valid() def test_get_episode_from_release(): |