Пример #1
0
def test_perform_args_on_youtube(youtube_item):
    parser = argparse.ArgumentParser()
    args = parse_args(parser, ["http://youtube_item.com/watch?v=9bZkp7q19f0"])
    cli._parse_args = MagicMock(return_value=args)
    cli._perform_args_on_youtube = MagicMock()
    cli.main()
    youtube_item.assert_called()
    cli._perform_args_on_youtube.assert_called()
Пример #2
0
def test_download_by_resolution_flag(youtube_item, download_by_resolution):
    parser = argparse.ArgumentParser()
    args = parse_args(
        parser, ["http://youtube_item.com/watch?v=9bZkp7q19f0", "-r", "320p"])
    cli._parse_args = MagicMock(return_value=args)
    cli.main()
    youtube_item.assert_called()
    download_by_resolution.assert_called()
Пример #3
0
def test_main_download_caption(youtube_item):
    parser = argparse.ArgumentParser()
    args = parse_args(parser,
                      ["http://youtube_item.com/watch?v=9bZkp7q19f0", "-c"])
    cli._parse_args = MagicMock(return_value=args)
    cli.download_caption = MagicMock()
    cli.main()
    youtube_item.assert_called()
    cli.download_caption.assert_called()
Пример #4
0
def test_main_display_streams(youtube_item):
    parser = argparse.ArgumentParser()
    args = parse_args(parser,
                      ["http://youtube_item.com/watch?v=9bZkp7q19f0", "-l"])
    cli._parse_args = MagicMock(return_value=args)
    cli.display_streams = MagicMock()
    cli.main()
    youtube_item.assert_called()
    cli.display_streams.assert_called()
Пример #5
0
def test_main_logging_setup(setup_logger):
    # Given
    parser = argparse.ArgumentParser()
    args = parse_args(parser, ["http://fakeurl", "-v"])
    cli._parse_args = MagicMock(return_value=args)
    # When
    with pytest.raises(SystemExit):
        cli.main()
    # Then
    setup_logger.assert_called_with(40)
Пример #6
0
def test_download_audio_args(youtube_item, download_audio):
    # Given
    parser = argparse.ArgumentParser()
    args = parse_args(
        parser, ["http://youtube_item.com/watch?v=9bZkp7q19f0", "-a", "mp4"])
    cli._parse_args = MagicMock(return_value=args)
    # When
    cli.main()
    # Then
    youtube_item.assert_called()
    download_audio.assert_called()
Пример #7
0
def test_main_build_playback_report(youtube_item):
    parser = argparse.ArgumentParser()
    args = parse_args(parser, [
        "http://youtube_item.com/watch?v=9bZkp7q19f0",
        "--build-playback-report"
    ])
    cli._parse_args = MagicMock(return_value=args)
    cli.build_playback_report = MagicMock()
    cli.main()
    youtube_item.assert_called()
    cli.build_playback_report.assert_called()
Пример #8
0
def test_main_invalid_url(_parse_args):
    parser = argparse.ArgumentParser()
    args = parse_args(
        parser,
        [
            "crikey",
        ],
    )
    _parse_args.return_value = args
    with pytest.raises(SystemExit):
        cli.main()
Пример #9
0
def test_download_with_playlist(perform_args_on_youtube, playlist,
                                youtube_item):
    # Given
    cli.safe_filename = MagicMock(return_value="safe_title")
    parser = argparse.ArgumentParser()
    args = parse_args(parser,
                      ["https://www.youtube_item.com/playlist?list=PLyn"])
    cli._parse_args = MagicMock(return_value=args)
    videos = [youtube_item]
    playlist_instance = playlist.return_value
    playlist_instance.videos = videos
    # When
    cli.main()
    # Then
    playlist.assert_called()
    perform_args_on_youtube.assert_called_with(youtube_item, args)
Пример #10
0
def test_download_with_playlist_video_error(perform_args_on_youtube, playlist,
                                            youtube_item, capsys):
    # Given
    cli.safe_filename = MagicMock(return_value="safe_title")
    parser = argparse.ArgumentParser()
    args = parse_args(parser,
                      ["https://www.youtube_item.com/playlist?list=PLyn"])
    cli._parse_args = MagicMock(return_value=args)
    videos = [youtube_item]
    playlist_instance = playlist.return_value
    playlist_instance.videos = videos
    perform_args_on_youtube.side_effect = PytubeError()
    # When
    cli.main()
    # Then
    playlist.assert_called()
    captured = capsys.readouterr()
    assert "There was an error with video" in captured.out