test_youtube.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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.youtube import Youtube
  8. @pytest.mark.online
  9. @pytest.mark.slow
  10. @pytest.mark.parametrize(('test_url', 'expected_hash'), (
  11. ('https://www.youtube.com/watch?v=uSm2VDgRIUs', '2d60b54582df5b95ec72bb00b580d2ff'),
  12. ('https://www.youtube.com/watch?v=GcI7nxQj7HA', '5db0fc92a0a7fb9ac91e63505eea9cf0'),
  13. ))
  14. def test_find_resources_good(test_url: str, expected_hash: str):
  15. test_submission = MagicMock()
  16. test_submission.url = test_url
  17. downloader = Youtube(test_submission)
  18. resources = downloader.find_resources()
  19. assert len(resources) == 1
  20. assert isinstance(resources[0], Resource)
  21. resources[0].download()
  22. assert resources[0].hash.hexdigest() == expected_hash
  23. @pytest.mark.online
  24. @pytest.mark.parametrize('test_url', (
  25. 'https://www.polygon.com/disney-plus/2020/5/14/21249881/gargoyles-animated-series-disney-plus-greg-weisman'
  26. '-interview-oj-simpson-goliath-chronicles',
  27. ))
  28. def test_find_resources_bad(test_url: str):
  29. test_submission = MagicMock()
  30. test_submission.url = test_url
  31. downloader = Youtube(test_submission)
  32. with pytest.raises(NotADownloadableLinkError):
  33. downloader.find_resources()