test_vreddit.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. # coding=utf-8
  3. from unittest.mock import MagicMock
  4. import pytest
  5. from bdfr.exceptions import NotADownloadableLinkError
  6. from bdfr.resource import Resource
  7. from bdfr.site_downloaders.vreddit import VReddit
  8. @pytest.mark.online
  9. @pytest.mark.slow
  10. @pytest.mark.parametrize(('test_url', 'expected_hash'), (
  11. ('https://www.reddit.com/user/Xomb_Forever/comments/u5p2kj/hold_up/', '379ef5cd87203544d51caee31e72d210'),
  12. ))
  13. def test_find_resources_good(test_url: str, expected_hash: str):
  14. test_submission = MagicMock()
  15. test_submission.url = test_url
  16. downloader = VReddit(test_submission)
  17. resources = downloader.find_resources()
  18. assert len(resources) == 1
  19. assert isinstance(resources[0], Resource)
  20. resources[0].download()
  21. assert resources[0].hash.hexdigest() == expected_hash
  22. @pytest.mark.online
  23. @pytest.mark.parametrize('test_url', (
  24. 'https://www.polygon.com/disney-plus/2020/5/14/21249881/gargoyles-animated-series-disney-plus-greg-weisman'
  25. '-interview-oj-simpson-goliath-chronicles',
  26. ))
  27. def test_find_resources_bad(test_url: str):
  28. test_submission = MagicMock()
  29. test_submission.url = test_url
  30. downloader = VReddit(test_submission)
  31. with pytest.raises(NotADownloadableLinkError):
  32. downloader.find_resources()