示例#1
0
    def test_retries_if_torrent_not_complete(self,
                                             mocker: MockerFixture) -> None:
        mocker.patch("panel.tasks.torrent.Client", MockClient)
        mocker.patch("panel.tasks.torrent.process_videos_in_folder")
        movie_torrent: MovieTorrent = MovieTorrentFactory(id=2)

        with pytest.raises(celery.exceptions.Retry):
            check_and_process_torrent(movie_torrent.id)
示例#2
0
    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}"
        )
示例#3
0
    def test_without_any_torrent(self, mocker: MockerFixture) -> None:
        mocker.patch("panel.tasks.torrent.Client", MockClient)
        movie_torrent: MovieTorrent = MovieTorrentFactory(id=9999)

        with pytest.raises(Exception) as exc:
            is_torrent_complete(movie_torrent.id)

        assert (
            str(exc.value) ==
            f"Movie torrent {movie_torrent.id} does not have any torrent associated with"
        )
示例#4
0
    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"))
示例#5
0
    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))
示例#6
0
    def test_if_torrent_is_complete(self, tmp_path: PosixPath,
                                    mocker: MockerFixture) -> None:
        mocker.patch("panel.tasks.torrent.Client", MockClient)
        mocker.patch("shutil.move")
        mocker.patch("panel.tasks.torrent.process_videos_in_folder")
        mocker.patch.object(settings, "MEDIA_FOLDER", str(tmp_path))
        movie_torrent: MovieTorrent = MovieTorrentFactory(id=1)
        torrents: List[Dict[str, Any]] = MockClient().torrents(
            category=str(movie_torrent.id))

        check_and_process_torrent(movie_torrent.id)

        movie_torrent.refresh_from_db()

        assert movie_torrent.is_complete is True
        assert movie_torrent.movie_content.full_path == torrents[0][
            "content_path"]
        assert movie_torrent.movie_content.main_folder == torrents[0][
            "content_path"]
示例#7
0
    def test_is_not_torrent_complete(self, mocker: MockerFixture) -> None:
        mocker.patch("panel.tasks.torrent.Client", MockClient)
        movie_torrent: MovieTorrent = MovieTorrentFactory(id=2)

        assert is_torrent_complete(movie_torrent.id) is False
示例#8
0
    def test_returns_none_if_torrent_is_complete(self) -> None:
        movie_torrent: MovieTorrent = MovieTorrentFactory()
        movie_torrent.is_complete = True
        movie_torrent.save()

        assert check_and_process_torrent(movie_torrent.id) is None