test_vidble.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.vidble import Vidble
  7. @pytest.mark.parametrize(('test_url', 'expected'), (
  8. ('/RDFbznUvcN_med.jpg', '/RDFbznUvcN.jpg'),
  9. ))
  10. def test_change_med_url(test_url: str, expected: str):
  11. result = Vidble.change_med_url(test_url)
  12. assert result == expected
  13. @pytest.mark.online
  14. @pytest.mark.parametrize(('test_url', 'expected'), (
  15. ('https://www.vidble.com/show/UxsvAssYe5', {
  16. 'https://www.vidble.com/UxsvAssYe5.gif',
  17. }),
  18. ('https://vidble.com/show/RDFbznUvcN', {
  19. 'https://www.vidble.com/RDFbznUvcN.jpg',
  20. }),
  21. ('https://vidble.com/album/h0jTLs6B', {
  22. 'https://www.vidble.com/XG4eAoJ5JZ.jpg',
  23. 'https://www.vidble.com/IqF5UdH6Uq.jpg',
  24. 'https://www.vidble.com/VWuNsnLJMD.jpg',
  25. 'https://www.vidble.com/sMmM8O650W.jpg',
  26. }),
  27. ('https://www.vidble.com/pHuwWkOcEb', {
  28. 'https://www.vidble.com/pHuwWkOcEb.jpg',
  29. }),
  30. ))
  31. def test_get_links(test_url: str, expected: set[str]):
  32. results = Vidble.get_links(test_url)
  33. assert results == expected
  34. @pytest.mark.online
  35. @pytest.mark.parametrize(('test_url', 'expected_hashes'), (
  36. ('https://www.vidble.com/show/UxsvAssYe5', {
  37. '0ef2f8e0e0b45936d2fb3e6fbdf67e28',
  38. }),
  39. ('https://vidble.com/show/RDFbznUvcN', {
  40. 'c2dd30a71e32369c50eed86f86efff58',
  41. }),
  42. ('https://vidble.com/album/h0jTLs6B', {
  43. '3b3cba02e01c91f9858a95240b942c71',
  44. 'dd6ecf5fc9e936f9fb614eb6a0537f99',
  45. 'b31a942cd8cdda218ed547bbc04c3a27',
  46. '6f77c570b451eef4222804bd52267481',
  47. }),
  48. ('https://www.vidble.com/pHuwWkOcEb', {
  49. '585f486dd0b2f23a57bddbd5bf185bc7',
  50. }),
  51. ))
  52. def test_find_resources(test_url: str, expected_hashes: set[str]):
  53. mock_download = Mock()
  54. mock_download.url = test_url
  55. downloader = Vidble(mock_download)
  56. results = downloader.find_resources()
  57. assert all([isinstance(res, Resource) for res in results])
  58. [res.download() for res in results]
  59. hashes = set([res.hash.hexdigest() for res in results])
  60. assert hashes == set(expected_hashes)