def test_raises_when_movie_content_full_path_not_exists(self) -> None: movie_content: MovieContent = MovieContentFactory() with pytest.raises(FileNotFoundError) as exc: fetch_subtitles(movie_content.id) assert ( str(exc.value) == f"{movie_content.full_path} does not exist for MovieContent {movie_content.id}" )
def test_fetches_subtitles( self, tmp_path: PosixPath, mocker: MockerFixture ) -> None: mocker.patch("panel.tasks.subtitles.requests", MockRequest) mocker.patch("panel.tasks.subtitles.get_hash", lambda x: "somehash") mocker.patch( "panel.tasks.subtitles._get_response_from_api", _mock_get_response_from_api ) mocker.patch.object(settings, "SUBTITLE_LANGS", "eng,ger") subtitle = tmp_path / "test.srt" subtitle.touch() subtitle_dir: str = "vtt_subtitles" movie_content: MovieContent = MovieContentFactory(full_path=str(tmp_path)) MovieFactory.create(movie_content=[movie_content]) langs: List[str] = get_subtitle_language() assert not movie_content.movie_subtitle.exists() fetch_subtitles( movie_content_id=movie_content.id, limit=2, delete_original=True ) assert (tmp_path / subtitle_dir).is_dir() for lang in langs: assert (tmp_path / subtitle_dir / f"{lang}1.vtt").is_file() assert (tmp_path / subtitle_dir / f"{lang}2.vtt").is_file() assert not (tmp_path / subtitle_dir / f"{lang}1.srt").is_file() assert not (tmp_path / subtitle_dir / f"{lang}2.srt").is_file() assert not (tmp_path / subtitle_dir / f"{lang}3.vtt").is_file() assert not (tmp_path / subtitle_dir / f"{lang}3.srt").is_file() assert movie_content.movie_subtitle.count() == 5 assert movie_content.movie_subtitle.first().full_path == str( tmp_path / subtitle_dir / f"{langs[0]}1.vtt" ) assert {i.full_path for i in movie_content.movie_subtitle.all()}.issubset( {str(i) for i in (tmp_path / subtitle_dir).iterdir()} ) assert movie_content.movie_subtitle.last().full_path == str( tmp_path / subtitle_dir / "org1.vtt" )
def test_raises_when_no_movie_content(self): with pytest.raises(MovieContent.DoesNotExist) as exc: fetch_subtitles(-999) assert str(exc.value) == "MovieContent matching query does not exist."