Add download filter class

This commit is contained in:
Serene-Arc
2021-02-07 20:23:08 +10:00
committed by Ali Parlakci
parent f2415b6bd0
commit b1f0632a80
2 changed files with 93 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
#!/usr/bin/env python3
# coding=utf-8
import pytest
from bulkredditdownloader.download_filter import DownloadFilter
@pytest.fixture()
def download_filter() -> DownloadFilter:
return DownloadFilter(['mp4', 'mp3'], ['test.com', 'reddit.com'])
@pytest.mark.parametrize(('test_url', 'expected'), (('test.mp4', False),
('test.avi', True),
('test.random.mp3', False)
))
def test_filter_extension(test_url: str, expected: bool, download_filter: DownloadFilter):
result = download_filter._check_extension(test_url)
assert result == expected
@pytest.mark.parametrize(('test_url', 'expected'), (('test.mp4', True),
('http://reddit.com/test.mp4', False),
('http://reddit.com/test.gif', False),
('https://www.example.com/test.mp4', True),
('https://www.example.com/test.png', True),
))
def test_filter_domain(test_url: str, expected: bool, download_filter: DownloadFilter):
result = download_filter._check_domain(test_url)
assert result == expected
@pytest.mark.parametrize(('test_url', 'expected'), (('test.mp4', False),
('test.gif', True),
('https://www.example.com/test.mp4', False),
('https://www.example.com/test.png', True),
('http://reddit.com/test.mp4', False),
('http://reddit.com/test.gif', False),
))
def test_filter_all(test_url: str, expected: bool, download_filter: DownloadFilter):
result = download_filter.check_url(test_url)
assert result == expected
@pytest.mark.parametrize('test_url', ('test.mp3',
'test.mp4',
'http://reddit.com/test.mp4',
't',
))
def test_filter_empty_filter(test_url: str):
download_filter = DownloadFilter()
result = download_filter.check_url(test_url)
assert result is True