def test_raises_if_root_folder_is_not_folder(self, mocker: MockerFixture) -> None: mocker.patch("panel.tasks.subtitles.requests", MockRequest) root_path: str = "/some/folder/location" with pytest.raises(Exception) as exc: download_and_extract_subtitle( url="http://test", root_path=root_path, subtitle_name="subtitle.srt" ) assert str(exc.value) == f"{root_path} is not a folder"
def test_raises_when_api_returns_error(self, tmp_path: PosixPath, mocker: MockerFixture) -> None: mocker.patch("panel.tasks.subtitles.requests", MockRequest) url: str = "tor://test" with pytest.raises(Exception) as exc: download_and_extract_subtitle(url=url, root_path=str(tmp_path), subtitle_name="subtitle.srt") assert str(exc.value) == f"Subtitle could not be downloaded for {url}"
def test_writes_contents_to_new_file(self, tmp_path: PosixPath, mocker: MockerFixture) -> None: mocker.patch("panel.tasks.subtitles.requests", MockRequest) new_file: PosixPath = tmp_path / "subtitle.vtt" download_and_extract_subtitle(url="http://test", root_path=str(tmp_path), subtitle_name=new_file.name) assert new_file.is_file() with open(str(new_file), "rb") as f: assert f.read() == MockRequest._content
def test_does_not_raise_when_api_returns_error( self, tmp_path: PosixPath, mocker: MockerFixture ) -> None: mocker.patch("panel.tasks.subtitles.requests", MockRequest) url: str = "tor://test" try: download_and_extract_subtitle( url=url, root_path=str(tmp_path), subtitle_name="subtitle.srt" ) except Exception: pytest.fail("API errors should not raise errors.")