test_erome.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python3
  2. # coding=utf-8
  3. import re
  4. from unittest.mock import MagicMock
  5. import pytest
  6. from bdfr.site_downloaders.erome import Erome
  7. @pytest.mark.online
  8. @pytest.mark.parametrize(('test_url', 'expected_urls'), (
  9. ('https://www.erome.com/a/vqtPuLXh', (
  10. r'https://[a-z]\d+.erome.com/\d{3}/vqtPuLXh/KH2qBT99_480p.mp4',
  11. )),
  12. ('https://www.erome.com/a/ORhX0FZz', (
  13. r'https://[a-z]\d+.erome.com/\d{3}/ORhX0FZz/9IYQocM9_480p.mp4',
  14. r'https://[a-z]\d+.erome.com/\d{3}/ORhX0FZz/9eEDc8xm_480p.mp4',
  15. r'https://[a-z]\d+.erome.com/\d{3}/ORhX0FZz/EvApC7Rp_480p.mp4',
  16. r'https://[a-z]\d+.erome.com/\d{3}/ORhX0FZz/LruobtMs_480p.mp4',
  17. r'https://[a-z]\d+.erome.com/\d{3}/ORhX0FZz/TJNmSUU5_480p.mp4',
  18. r'https://[a-z]\d+.erome.com/\d{3}/ORhX0FZz/X11Skh6Z_480p.mp4',
  19. r'https://[a-z]\d+.erome.com/\d{3}/ORhX0FZz/bjlTkpn7_480p.mp4'
  20. )),
  21. ))
  22. def test_get_link(test_url: str, expected_urls: tuple[str]):
  23. result = Erome. _get_links(test_url)
  24. assert all([any([re.match(p, r) for r in result]) for p in expected_urls])
  25. @pytest.mark.online
  26. @pytest.mark.slow
  27. @pytest.mark.parametrize(('test_url', 'expected_hashes_len'), (
  28. ('https://www.erome.com/a/vqtPuLXh', 1),
  29. ('https://www.erome.com/a/4tP3KI6F', 1),
  30. ))
  31. def test_download_resource(test_url: str, expected_hashes_len: int):
  32. # Can't compare hashes for this test, Erome doesn't return the exact same file from request to request so the hash
  33. # will change back and forth randomly
  34. mock_submission = MagicMock()
  35. mock_submission.url = test_url
  36. test_site = Erome(mock_submission)
  37. resources = test_site.find_resources()
  38. for res in resources:
  39. res.download()
  40. resource_hashes = [res.hash.hexdigest() for res in resources]
  41. assert len(resource_hashes) == expected_hashes_len