File size: 992 Bytes
d2c119a
cd0bfbf
d2c119a
0bbb369
 
d2c119a
0bbb369
d2c119a
 
82321d6
846239d
 
5afc31c
82321d6
5afc31c
9fb6343
 
 
 
25de36d
 
 
 
 
 
9fb6343
0bbb369
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-
from unittest import mock

import pytest

from pytube import YouTube
from pytube.exceptions import VideoUnavailable


@mock.patch("pytube.__main__.YouTube")
def test_prefetch_deferred(youtube):
    instance = youtube.return_value
    instance.prefetch_descramble.return_value = None
    YouTube("https://www.youtube.com/watch?v=9bZkp7q19f0", True)
    assert not instance.prefetch_descramble.called


@mock.patch("urllib.request.install_opener")
def test_install_proxy(opener):
    proxies = {"http": "http://www.example.com:3128/"}
    YouTube(
        "https://www.youtube.com/watch?v=9bZkp7q19f0",
        defer_prefetch_init=True,
        proxies=proxies,
    )
    opener.assert_called()


@mock.patch("pytube.request.get")
def test_video_unavailable(get):
    get.return_value = None
    youtube = YouTube(
        "https://www.youtube.com/watch?v=9bZkp7q19f0", defer_prefetch_init=True
    )
    with pytest.raises(VideoUnavailable):
        youtube.prefetch()