def test_raises_if_no_movie_torrent(self): movie_content: MovieContent = MovieContentFactory() with pytest.raises(Exception) as exc: _get_root_path(movie_content.id) assert (str(exc.value) == f"MovieTorrent could not be found for {movie_content.id}")
def test_raises_if_no_torrents(self, mocker: MockerFixture) -> None: mocker.patch("panel.tasks.torrent.Client", MockClient) movie_torrent: MovieTorrent = MovieTorrentFactory(id=999) with pytest.raises(Exception) as exc: _get_root_path(movie_torrent.movie_content.id) assert ( str(exc.value) == f"Torrent could not be found for movie content: {movie_torrent.movie_content.id}" )
def test_if_full_path_is_a_file(self, tmp_path: PosixPath) -> None: new_file: PosixPath = tmp_path / "test.mp4" new_file.touch() movie_content: MovieContent = MovieContentFactory() movie_content.full_path = str(new_file) movie_content.save() assert _get_root_path(movie_content.id) == str(tmp_path)
def test_main_folder_is_defined_but_not_full_path( self, tmp_path: PosixPath, mocker: MockerFixture) -> None: mocker.patch.object(settings, "MEDIA_FOLDER", str(tmp_path)) folder: PosixPath = tmp_path / "folder" folder.mkdir(exist_ok=True) movie_content: MovieContent = MovieContentFactory() movie_content.main_folder = folder.name movie_content.save() assert _get_root_path(movie_content.id) == str(folder)
def test_full_path_as_file_and_main_folder_as_file( self, tmp_path: PosixPath, mocker: MockerFixture) -> None: mocker.patch.object(settings, "MEDIA_FOLDER", str(tmp_path)) new_file: PosixPath = tmp_path / "test.mp4" new_file.touch() movie_content: MovieContent = MovieContentFactory() movie_content.full_path = str(new_file) movie_content.main_folder = new_file.name movie_content.save() assert _get_root_path(movie_content.id) == str(tmp_path)
def test_returns_torrent_content_path(self, tmp_path: PosixPath, mocker: MockerFixture) -> None: _torrents: List[Dict[str, Any]] = copy.deepcopy(TORRENTS) new_folder: PosixPath = tmp_path / "folder" new_folder.mkdir(exist_ok=True) new_file: PosixPath = new_folder / "test.mp4" new_file.touch() _torrents[0]["content_path"] = str(new_folder) _torrents[1]["content_path"] = str(new_file) mocker.patch.object(panel.tasks.tests.mocks, "TORRENTS", _torrents) mocker.patch("panel.tasks.torrent.Client", MockClient) movie_torrent: MovieTorrent = MovieTorrentFactory(id=1) result: str = _get_root_path(movie_torrent.movie_content.id) assert result == str((tmp_path / "folder"))
def test_returns_folder_under_media_folder(self, tmp_path: PosixPath, mocker: MockerFixture) -> None: mocker.patch("panel.tasks.torrent.Client", MockClient) mocker.patch.object(settings, "MEDIA_FOLDER", str(tmp_path)) _torrents: List[Dict[str, Any]] = copy.deepcopy(TORRENTS) torrent_folder: PosixPath = tmp_path / "new folder" torrent_folder.mkdir(exist_ok=True) (tmp_path / _hash(torrent_folder.name)).mkdir(exist_ok=True) movie_torrent: MovieTorrent = MovieTorrentFactory(id=1) _torrents[0][ "content_path"] = "/some/nonexist/folder/" + torrent_folder.name mocker.patch.object(panel.tasks.tests.mocks, "TORRENTS", _torrents) mocker.patch("panel.tasks.torrent.Client", MockClient) result: str = _get_root_path(movie_torrent.movie_content.id) assert result == str(tmp_path / _hash(torrent_folder.name))
def test_if_full_path_is_a_dir(self, tmp_path: PosixPath) -> None: movie_content: MovieContent = MovieContentFactory() movie_content.full_path = str(tmp_path) movie_content.save() assert _get_root_path(movie_content.id) == str(tmp_path)