Beispiel #1
0
    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"
        )
Beispiel #2
0
    def test_returns_setting(self, monkeypatch: MonkeyPatch) -> None:
        monkeypatch.setattr(settings, "SUBTITLE_LANGS", "eng,ger")

        assert get_subtitle_language() == ["eng", "ger"]
Beispiel #3
0
    def test_when_setting_is_empty(self, monkeypatch: MonkeyPatch) -> None:
        monkeypatch.setattr(settings, "SUBTITLE_LANGS", "")

        assert get_subtitle_language() == []
Beispiel #4
0
    def test_when_no_settings(self, monkeypatch: MonkeyPatch) -> None:
        monkeypatch.delattr(settings, "SUBTITLE_LANGS", raising=True)

        assert get_subtitle_language() == []