added test
Browse files- tests/test_cli.py +21 -6
tests/test_cli.py
CHANGED
@@ -264,25 +264,40 @@ def test_download_with_playlist_video_error(
|
|
264 |
@mock.patch("pytube.cli.YouTube")
|
265 |
@mock.patch("pytube.StreamQuery")
|
266 |
@mock.patch("pytube.Stream")
|
267 |
-
|
|
|
|
|
268 |
stream_query.get_by_resolution.return_value = stream
|
269 |
youtube.streams = stream_query
|
270 |
-
|
271 |
cli.download_by_resolution(youtube=youtube, resolution="320p", target="test_target")
|
272 |
-
|
|
|
273 |
|
274 |
|
275 |
@mock.patch("pytube.cli.YouTube")
|
276 |
@mock.patch("pytube.StreamQuery")
|
277 |
-
|
|
|
278 |
stream_query.get_by_resolution.return_value = None
|
279 |
youtube.streams = stream_query
|
280 |
-
cli._download = MagicMock()
|
281 |
with pytest.raises(SystemExit):
|
282 |
cli.download_by_resolution(
|
283 |
youtube=youtube, resolution="DOESNT EXIST", target="test_target"
|
284 |
)
|
285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
|
287 |
|
288 |
@mock.patch("pytube.cli.YouTube")
|
|
|
264 |
@mock.patch("pytube.cli.YouTube")
|
265 |
@mock.patch("pytube.StreamQuery")
|
266 |
@mock.patch("pytube.Stream")
|
267 |
+
@mock.patch("pytube.cli._download")
|
268 |
+
def test_download_by_resolution(download, stream, stream_query, youtube):
|
269 |
+
# Given
|
270 |
stream_query.get_by_resolution.return_value = stream
|
271 |
youtube.streams = stream_query
|
272 |
+
# When
|
273 |
cli.download_by_resolution(youtube=youtube, resolution="320p", target="test_target")
|
274 |
+
# Then
|
275 |
+
download.assert_called_with(stream, target="test_target")
|
276 |
|
277 |
|
278 |
@mock.patch("pytube.cli.YouTube")
|
279 |
@mock.patch("pytube.StreamQuery")
|
280 |
+
@mock.patch("pytube.cli._download")
|
281 |
+
def test_download_by_resolution_not_exists(download, stream_query, youtube):
|
282 |
stream_query.get_by_resolution.return_value = None
|
283 |
youtube.streams = stream_query
|
|
|
284 |
with pytest.raises(SystemExit):
|
285 |
cli.download_by_resolution(
|
286 |
youtube=youtube, resolution="DOESNT EXIST", target="test_target"
|
287 |
)
|
288 |
+
download.assert_not_called()
|
289 |
+
|
290 |
+
|
291 |
+
@mock.patch("pytube.Stream")
|
292 |
+
def test_download_stream_file_exists(stream, capsys):
|
293 |
+
# Given
|
294 |
+
stream.exists_at_path.return_value = True
|
295 |
+
# When
|
296 |
+
cli._download(stream=stream)
|
297 |
+
# Then
|
298 |
+
captured = capsys.readouterr()
|
299 |
+
assert "Already downloaded at" in captured.out
|
300 |
+
stream.download.assert_not_called()
|
301 |
|
302 |
|
303 |
@mock.patch("pytube.cli.YouTube")
|