add filename and skip tests
Browse files- tests/test_streams.py +46 -0
tests/test_streams.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
|
|
|
| 2 |
import random
|
| 3 |
|
| 4 |
from unittest import mock
|
|
@@ -58,6 +59,51 @@ def test_download_with_prefix(cipher_signature, mocker):
|
|
| 58 |
assert file_path == "/target/prefixPSY - GANGNAM STYLE(강남스타일) MV.mp4"
|
| 59 |
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
def test_progressive_streams_return_includes_audio_track(cipher_signature):
|
| 62 |
stream = cipher_signature.streams.filter(progressive=True).first()
|
| 63 |
assert stream.includes_audio_track
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
+
import os
|
| 3 |
import random
|
| 4 |
|
| 5 |
from unittest import mock
|
|
|
|
| 59 |
assert file_path == "/target/prefixPSY - GANGNAM STYLE(강남스타일) MV.mp4"
|
| 60 |
|
| 61 |
|
| 62 |
+
def test_download_with_filename(cipher_signature, mocker):
|
| 63 |
+
mocker.patch.object(request, "headers")
|
| 64 |
+
request.headers.return_value = {"content-length": "16384"}
|
| 65 |
+
mocker.patch.object(request, "stream")
|
| 66 |
+
request.stream.return_value = iter([str(random.getrandbits(8 * 1024))])
|
| 67 |
+
streams.target_directory = MagicMock(return_value="/target")
|
| 68 |
+
with mock.patch("pytube.streams.open", mock.mock_open(), create=True):
|
| 69 |
+
stream = cipher_signature.streams.first()
|
| 70 |
+
file_path = stream.download(filename="cool name bro")
|
| 71 |
+
assert file_path == "/target/cool name bro.mp4"
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def test_download_with_existing(cipher_signature, mocker):
|
| 75 |
+
mocker.patch.object(request, "headers")
|
| 76 |
+
request.headers.return_value = {"content-length": "16384"}
|
| 77 |
+
mocker.patch.object(request, "stream")
|
| 78 |
+
streams.target_directory = MagicMock(return_value="/target")
|
| 79 |
+
mocker.patch.object(os.path, "isfile")
|
| 80 |
+
os.path.isfile.return_value = True
|
| 81 |
+
with mock.patch("pytube.streams.open", mock.mock_open(), create=True):
|
| 82 |
+
stream = cipher_signature.streams.first()
|
| 83 |
+
mocker.patch.object(os.path, "getsize")
|
| 84 |
+
os.path.getsize.return_value = stream.filesize
|
| 85 |
+
file_path = stream.download()
|
| 86 |
+
assert file_path == "/target/PSY - GANGNAM STYLE(강남스타일) MV.mp4"
|
| 87 |
+
assert not request.stream.called
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def test_download_with_existing_no_skip(cipher_signature, mocker):
|
| 91 |
+
mocker.patch.object(request, "headers")
|
| 92 |
+
request.headers.return_value = {"content-length": "16384"}
|
| 93 |
+
mocker.patch.object(request, "stream")
|
| 94 |
+
request.stream.return_value = iter([str(random.getrandbits(8 * 1024))])
|
| 95 |
+
streams.target_directory = MagicMock(return_value="/target")
|
| 96 |
+
mocker.patch.object(os.path, "isfile")
|
| 97 |
+
os.path.isfile.return_value = True
|
| 98 |
+
with mock.patch("pytube.streams.open", mock.mock_open(), create=True):
|
| 99 |
+
stream = cipher_signature.streams.first()
|
| 100 |
+
mocker.patch.object(os.path, "getsize")
|
| 101 |
+
os.path.getsize.return_value = stream.filesize
|
| 102 |
+
file_path = stream.download(skip_existing=False)
|
| 103 |
+
assert file_path == "/target/PSY - GANGNAM STYLE(강남스타일) MV.mp4"
|
| 104 |
+
assert request.stream.called
|
| 105 |
+
|
| 106 |
+
|
| 107 |
def test_progressive_streams_return_includes_audio_track(cipher_signature):
|
| 108 |
stream = cipher_signature.streams.filter(progressive=True).first()
|
| 109 |
assert stream.includes_audio_track
|