2021-02-27 11:30:52 +13:00
|
|
|
#!/usr/bin/env python3
|
2022-12-20 12:32:37 +13:00
|
|
|
# -*- coding: utf-8 -*-
|
2021-02-27 11:30:52 +13:00
|
|
|
|
|
|
|
from unittest.mock import Mock
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2021-04-12 19:58:32 +12:00
|
|
|
from bdfr.resource import Resource
|
|
|
|
from bdfr.site_downloaders.direct import Direct
|
2021-02-27 11:30:52 +13:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.online
|
2022-12-03 18:11:17 +13:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
("test_url", "expected_hash"),
|
|
|
|
(
|
2023-01-31 08:52:08 +13:00
|
|
|
("https://i.redd.it/q6ebualjxzea1.jpg", "6ec154859c777cb401132bb991cb3635"),
|
|
|
|
(
|
|
|
|
"https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3",
|
|
|
|
"3caa342e241ddb7d76fd24a834094101",
|
|
|
|
),
|
2022-12-03 18:11:17 +13:00
|
|
|
),
|
|
|
|
)
|
2021-02-27 11:30:52 +13:00
|
|
|
def test_download_resource(test_url: str, expected_hash: str):
|
2021-03-26 00:51:31 +13:00
|
|
|
mock_submission = Mock()
|
2021-02-27 11:30:52 +13:00
|
|
|
mock_submission.url = test_url
|
|
|
|
test_site = Direct(mock_submission)
|
|
|
|
resources = test_site.find_resources()
|
|
|
|
assert len(resources) == 1
|
|
|
|
assert isinstance(resources[0], Resource)
|
2021-07-27 15:39:49 +12:00
|
|
|
resources[0].download()
|
2021-02-27 11:30:52 +13:00
|
|
|
assert resources[0].hash.hexdigest() == expected_hash
|