test_pornhub.py 1.2 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 SiteDownloaderError
  6. from bdfr.resource import Resource
  7. from bdfr.site_downloaders.pornhub import PornHub
  8. @pytest.mark.online
  9. @pytest.mark.slow
  10. @pytest.mark.parametrize(('test_url', 'expected_hash'), (
  11. ('https://www.pornhub.com/view_video.php?viewkey=ph6074c59798497', 'd9b99e4ebecf2d8d67efe5e70d2acf8a'),
  12. ('https://www.pornhub.com/view_video.php?viewkey=ph5ede121f0d3f8', ''),
  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 = PornHub(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.pornhub.com/view_video.php?viewkey=ph5ede121f0d3f8',
  26. ))
  27. def test_find_resources_good(test_url: str):
  28. test_submission = MagicMock()
  29. test_submission.url = test_url
  30. downloader = PornHub(test_submission)
  31. with pytest.raises(SiteDownloaderError):
  32. downloader.find_resources()