Add tests for GifDeliveryNetwork and Gfycat
This commit is contained in:
parent
a55f35c025
commit
4146f181c7
@ -22,7 +22,7 @@ class GifDeliveryNetwork(BaseDownloader):
|
||||
except IndexError:
|
||||
raise NotADownloadableLinkError("Could not read the page source")
|
||||
|
||||
return [Resource(self.post, media_url)]
|
||||
return [Resource(self.post, media_url, '.mp4')]
|
||||
|
||||
@staticmethod
|
||||
def _get_link(url: str) -> str:
|
||||
|
35
bulkredditdownloader/tests/downloaders/test_gfycat.py
Normal file
35
bulkredditdownloader/tests/downloaders/test_gfycat.py
Normal file
@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
# coding=utf-8
|
||||
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
|
||||
from bulkredditdownloader.resource import Resource
|
||||
from bulkredditdownloader.site_downloaders.gfycat import Gfycat
|
||||
|
||||
|
||||
@pytest.mark.online
|
||||
@pytest.mark.parametrize(('test_url', 'expected_url'), (
|
||||
('https://gfycat.com/definitivecaninecrayfish', 'https://giant.gfycat.com/DefinitiveCanineCrayfish.mp4'),
|
||||
('https://gfycat.com/dazzlingsilkyiguana', 'https://giant.gfycat.com/DazzlingSilkyIguana.mp4'),
|
||||
))
|
||||
def test_get_link(test_url: str, expected_url: str):
|
||||
result = Gfycat._get_link(test_url)
|
||||
assert result == expected_url
|
||||
|
||||
|
||||
@pytest.mark.online
|
||||
@pytest.mark.parametrize(('test_url', 'expected_hash'), (
|
||||
('https://gfycat.com/definitivecaninecrayfish', '48f9bd4dbec1556d7838885612b13b39'),
|
||||
('https://gfycat.com/dazzlingsilkyiguana', '808941b48fc1e28713d36dd7ed9dc648'),
|
||||
))
|
||||
def test_download_resource(test_url: str, expected_hash: str):
|
||||
mock_submission = Mock
|
||||
mock_submission.url = test_url
|
||||
test_site = Gfycat(mock_submission)
|
||||
resources = test_site.find_resources()
|
||||
assert len(resources) == 1
|
||||
assert isinstance(resources[0], Resource)
|
||||
resources[0].download()
|
||||
assert resources[0].hash.hexdigest() == expected_hash
|
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
# coding=utf-8
|
||||
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
|
||||
from bulkredditdownloader.resource import Resource
|
||||
from bulkredditdownloader.site_downloaders.gif_delivery_network import GifDeliveryNetwork
|
||||
|
||||
|
||||
@pytest.mark.online
|
||||
@pytest.mark.parametrize(('test_url', 'expected'), (
|
||||
('https://www.gifdeliverynetwork.com/handyunsightlydesertpupfish',
|
||||
'https://thumbs2.redgifs.com/HandyUnsightlyDesertpupfish.mp4'),
|
||||
('https://www.gifdeliverynetwork.com/lamelikelyhamadryad',
|
||||
'https://thumbs2.redgifs.com/LameLikelyHamadryad.mp4')
|
||||
))
|
||||
def test_get_link(test_url: str, expected: str):
|
||||
result = GifDeliveryNetwork._get_link(test_url)
|
||||
assert result == expected
|
||||
|
||||
|
||||
@pytest.mark.online
|
||||
@pytest.mark.parametrize(('test_url', 'expected_hash'), (
|
||||
('https://www.gifdeliverynetwork.com/handyunsightlydesertpupfish', 'd941460dcf4e0d09dd33abaa32e2d270'),
|
||||
('https://www.gifdeliverynetwork.com/lamelikelyhamadryad', '4806fe15f4991bb73581338793488daf'),
|
||||
))
|
||||
def test_download_resource(test_url: str, expected_hash: str):
|
||||
mock_submission = Mock
|
||||
mock_submission.url = test_url
|
||||
test_site = GifDeliveryNetwork(mock_submission)
|
||||
resources = test_site.find_resources()
|
||||
assert len(resources) == 1
|
||||
assert isinstance(resources[0], Resource)
|
||||
resources[0].download()
|
||||
assert resources[0].hash.hexdigest() == expected_hash
|
Loading…
Reference in New Issue
Block a user