|
4 | 4 | from unittest.mock import AsyncMock, patch |
5 | 5 |
|
6 | 6 | import aiofiles |
7 | | -import m3u8 |
8 | 7 | import pytest |
9 | 8 | from m3u8 import M3U8 |
10 | 9 |
|
11 | 10 | from async_rutube_downloader.downloader import Downloader |
12 | 11 | from async_rutube_downloader.settings import ( |
13 | 12 | TEST_VIDEO_ID, |
14 | 13 | URL_FOR_ID_TEMPLATE, |
| 14 | + VIDEO_FORMAT, |
15 | 15 | FULL_HD_1080p, |
16 | 16 | ) |
17 | 17 | from async_rutube_downloader.utils.exceptions import ( |
|
20 | 20 | QualityError, |
21 | 21 | ) |
22 | 22 | from async_rutube_downloader.utils.type_hints import APIResponseDict, Qualities |
| 23 | +from tests.conftest import RUTUBE_LINK |
23 | 24 | from tests.test_utils import validate_qualities |
24 | 25 |
|
25 | 26 | # There is few protected methods calls, through mangled names, |
26 | 27 | # it's not a good practice. |
27 | 28 |
|
28 | 29 |
|
29 | 30 | @pytest.mark.asyncio |
30 | | -async def test_download_video( |
31 | | - downloader: Downloader, video_file_playlist_fixture: str |
32 | | -) -> None: |
33 | | - prev_get_calls = 2 # fetch_video_info and MasterPlaylist |
| 31 | +async def test_download_video(downloader: Downloader, tmp_path: Path) -> None: |
| 32 | + get_calls = 3 |
| 33 | + # 3 is _get_api_response, __get_master_playlist, and __get_selected_quality |
| 34 | + downloader._upload_directory = tmp_path |
34 | 35 | await downloader.fetch_video_info() |
35 | | - # FIXME: why is this necessary? autoselect_quality should do it. |
36 | | - downloader._selected_quality = m3u8.loads( |
37 | | - video_file_playlist_fixture, downloader.url |
38 | | - ) |
39 | 36 | with patch.object(aiofiles, "open") as aiofiles_open: |
40 | 37 | await downloader.download_video() |
41 | 38 | aiofiles_open.assert_called_once_with( |
42 | | - Path.cwd() / f"{downloader._filename}.mp4", mode="wb" |
| 39 | + tmp_path / f"{downloader._filename}.{VIDEO_FORMAT}", mode="wb" |
43 | 40 | ) |
44 | 41 | assert ( |
45 | 42 | downloader._session.get.call_count # type: ignore |
46 | | - == len(downloader._selected_quality.segments) + prev_get_calls |
| 43 | + == len(downloader._selected_quality.segments) + get_calls # type: ignore |
47 | 44 | ) |
48 | 45 |
|
49 | 46 |
|
@@ -72,7 +69,14 @@ async def test_select_quality_raise_error_master_playlist_not_initialized( |
72 | 69 |
|
73 | 70 | @pytest.mark.parametrize( |
74 | 71 | "value", |
75 | | - [("1920", "1080"), (list(), list()), (dict(), dict()), (object, object)], |
| 72 | + [ |
| 73 | + ("1920", "1080"), |
| 74 | + (1920.0, 1080.0), |
| 75 | + (list(), list()), |
| 76 | + (tuple(), tuple()), |
| 77 | + (dict(), dict()), |
| 78 | + (object, object), |
| 79 | + ], |
76 | 80 | ) |
77 | 81 | @pytest.mark.asyncio |
78 | 82 | async def test_validate_selected_quality( |
@@ -139,17 +143,17 @@ async def test_get_api_response( |
139 | 143 |
|
140 | 144 |
|
141 | 145 | @pytest.mark.asyncio |
142 | | -async def test_create_downloader(url: str, mocked_session: AsyncMock) -> None: |
| 146 | +async def test_create_downloader(mocked_session: AsyncMock) -> None: |
143 | 147 | """Create correct Downloader object.""" |
144 | 148 |
|
145 | 149 | def dummy_callback(arg: int, arg2: int): ... |
146 | 150 |
|
147 | 151 | loop = asyncio.new_event_loop() |
148 | 152 |
|
149 | | - obj = Downloader(url, loop, dummy_callback, session=mocked_session) |
| 153 | + obj = Downloader(RUTUBE_LINK, loop, dummy_callback, session=mocked_session) |
150 | 154 |
|
151 | 155 | assert isinstance(obj, Downloader) |
152 | | - assert obj.url == url |
| 156 | + assert obj.url == RUTUBE_LINK |
153 | 157 | assert obj._loop == loop |
154 | 158 | assert obj._callback == dummy_callback |
155 | 159 |
|
|
0 commit comments