test_gfycat.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python3
  2. # coding=utf-8
  3. from unittest.mock import Mock
  4. import pytest
  5. from bdfr.resource import Resource
  6. from bdfr.site_downloaders.gfycat import Gfycat
  7. @pytest.mark.online
  8. @pytest.mark.parametrize(('test_url', 'expected_url'), (
  9. ('https://gfycat.com/definitivecaninecrayfish', 'https://giant.gfycat.com/DefinitiveCanineCrayfish.mp4'),
  10. ('https://gfycat.com/dazzlingsilkyiguana', 'https://giant.gfycat.com/DazzlingSilkyIguana.mp4'),
  11. ))
  12. def test_get_link(test_url: str, expected_url: str):
  13. result = Gfycat._get_link(test_url)
  14. assert result.pop() == expected_url
  15. @pytest.mark.online
  16. @pytest.mark.parametrize(('test_url', 'expected_hash'), (
  17. ('https://gfycat.com/definitivecaninecrayfish', '48f9bd4dbec1556d7838885612b13b39'),
  18. ('https://gfycat.com/dazzlingsilkyiguana', '808941b48fc1e28713d36dd7ed9dc648'),
  19. ))
  20. def test_download_resource(test_url: str, expected_hash: str):
  21. mock_submission = Mock()
  22. mock_submission.url = test_url
  23. test_site = Gfycat(mock_submission)
  24. resources = test_site.find_resources()
  25. assert len(resources) == 1
  26. assert isinstance(resources[0], Resource)
  27. resources[0].download()
  28. assert resources[0].hash.hexdigest() == expected_hash