1
0
Fork 0
mirror of synced 2024-05-18 03:02:48 +12:00
bulk-downloader-for-reddit/tests/test_download_filter.py
OMEGARAZER 2bafb1b99b
Consolidate flake8 settings
Consolidates sane flake8 settings to pyproject with the Flake8-pyproject plugin.

Does not change logic of test workflow but allows base settings to live in pyproject for anyone using flake8 as an external linter (e.g. vscode)

Also fixes some flake8 errors that were not being picked up by current testing, mostly unused imports.
2022-12-28 10:00:43 -05:00

80 lines
2.2 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from unittest.mock import MagicMock
import pytest
from bdfr.download_filter import DownloadFilter
from bdfr.resource import Resource
@pytest.fixture()
def download_filter() -> DownloadFilter:
return DownloadFilter(["mp4", "mp3"], ["test.com", "reddit.com", "img.example.com"])
@pytest.mark.parametrize(
("test_extension", "expected"),
(
(".mp4", False),
(".avi", True),
(".random.mp3", False),
("mp4", False),
),
)
def test_filter_extension(test_extension: str, expected: bool, download_filter: DownloadFilter):
result = download_filter._check_extension(test_extension)
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),
("https://i.example.com/test.png", True),
("https://img.example.com/test.png", False),
("https://i.test.com/test.png", False),
),
)
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):
test_resource = Resource(MagicMock(), test_url, lambda: None)
result = download_filter.check_resource(test_resource)
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()
test_resource = Resource(MagicMock(), test_url, lambda: None)
result = download_filter.check_resource(test_resource)
assert result