|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | # coding=utf-8 |
3 | | - |
| 3 | +import re |
4 | 4 | from unittest.mock import MagicMock |
5 | 5 |
|
6 | 6 | import pytest |
|
11 | 11 | @pytest.mark.online |
12 | 12 | @pytest.mark.parametrize(('test_url', 'expected_urls'), ( |
13 | 13 | ('https://www.erome.com/a/vqtPuLXh', ( |
14 | | - 'https://s11.erome.com/365/vqtPuLXh/KH2qBT99_480p.mp4', |
| 14 | + r'https://s\d+.erome.com/365/vqtPuLXh/KH2qBT99_480p.mp4', |
15 | 15 | )), |
16 | 16 | ('https://www.erome.com/a/ORhX0FZz', ( |
17 | | - 'https://s15.erome.com/355/ORhX0FZz/9IYQocM9_480p.mp4', |
18 | | - 'https://s15.erome.com/355/ORhX0FZz/9eEDc8xm_480p.mp4', |
19 | | - 'https://s15.erome.com/355/ORhX0FZz/EvApC7Rp_480p.mp4', |
20 | | - 'https://s15.erome.com/355/ORhX0FZz/LruobtMs_480p.mp4', |
21 | | - 'https://s15.erome.com/355/ORhX0FZz/TJNmSUU5_480p.mp4', |
22 | | - 'https://s15.erome.com/355/ORhX0FZz/X11Skh6Z_480p.mp4', |
23 | | - 'https://s15.erome.com/355/ORhX0FZz/bjlTkpn7_480p.mp4' |
| 17 | + r'https://s\d+.erome.com/355/ORhX0FZz/9IYQocM9_480p.mp4', |
| 18 | + r'https://s\d+.erome.com/355/ORhX0FZz/9eEDc8xm_480p.mp4', |
| 19 | + r'https://s\d+.erome.com/355/ORhX0FZz/EvApC7Rp_480p.mp4', |
| 20 | + r'https://s\d+.erome.com/355/ORhX0FZz/LruobtMs_480p.mp4', |
| 21 | + r'https://s\d+.erome.com/355/ORhX0FZz/TJNmSUU5_480p.mp4', |
| 22 | + r'https://s\d+.erome.com/355/ORhX0FZz/X11Skh6Z_480p.mp4', |
| 23 | + r'https://s\d+.erome.com/355/ORhX0FZz/bjlTkpn7_480p.mp4' |
24 | 24 | )), |
25 | 25 | )) |
26 | 26 | def test_get_link(test_url: str, expected_urls: tuple[str]): |
27 | 27 | result = Erome. _get_links(test_url) |
28 | | - assert set(result) == set(expected_urls) |
| 28 | + assert all([any([re.match(p, r) for r in result]) for p in expected_urls]) |
29 | 29 |
|
30 | 30 |
|
31 | 31 | @pytest.mark.online |
32 | 32 | @pytest.mark.slow |
33 | | -@pytest.mark.parametrize(('test_url', 'expected_hashes'), ( |
34 | | - ('https://www.erome.com/a/vqtPuLXh', { |
35 | | - '5da2a8d60d87bed279431fdec8e7d72f' |
36 | | - }), |
37 | | - ('https://www.erome.com/a/lGrcFxmb', { |
38 | | - '0e98f9f527a911dcedde4f846bb5b69f', |
39 | | - '25696ae364750a5303fc7d7dc78b35c1', |
40 | | - '63775689f438bd393cde7db6d46187de', |
41 | | - 'a1abf398cfd4ef9cfaf093ceb10c746a', |
42 | | - 'bd9e1a4ea5ef0d6ba47fb90e337c2d14' |
43 | | - }), |
| 33 | +@pytest.mark.parametrize(('test_url', 'expected_hashes_len'), ( |
| 34 | + ('https://www.erome.com/a/vqtPuLXh', 1), |
| 35 | + ('https://www.erome.com/a/4tP3KI6F', 1), |
44 | 36 | )) |
45 | | -def test_download_resource(test_url: str, expected_hashes: tuple[str]): |
| 37 | +def test_download_resource(test_url: str, expected_hashes_len: int): |
46 | 38 | # Can't compare hashes for this test, Erome doesn't return the exact same file from request to request so the hash |
47 | 39 | # will change back and forth randomly |
48 | 40 | mock_submission = MagicMock() |
49 | 41 | mock_submission.url = test_url |
50 | 42 | test_site = Erome(mock_submission) |
51 | 43 | resources = test_site.find_resources() |
52 | | - [res.download() for res in resources] |
| 44 | + for res in resources: |
| 45 | + res.download() |
53 | 46 | resource_hashes = [res.hash.hexdigest() for res in resources] |
54 | | - assert len(resource_hashes) == len(expected_hashes) |
| 47 | + assert len(resource_hashes) == expected_hashes_len |
0 commit comments