This repository has been archived on 2023-10-01. You can view files and clone it, but cannot push or open issues or pull requests.
PyNyaaTa/tests/filters_test.py

57 lines
1.4 KiB
Python

from pydantic_factories import ModelFactory
from pynyaata2.filters import blacklist, danger, duplicate, inactive, trusted
from pynyaata2.types import Color, RemoteFile
from pytest import MonkeyPatch
class RemoteFileFactory(ModelFactory[RemoteFile]):
__model__ = RemoteFile
color = Color.DEFAULT
def test_blacklist(monkeypatch: MonkeyPatch):
monkeypatch.setenv("BLACKLIST_WORDS", "one,two")
remotes = RemoteFileFactory.batch(10)
remotes[0].name = "oui one non"
remotes[1].name = "non two oui"
assert len(blacklist(remotes)) == 8
def test_danger():
remotes = RemoteFileFactory.batch(10)
remotes[0].color = Color.DANGER
assert len(danger(remotes)) == 9
def test_duplicate():
remotes = RemoteFileFactory.batch(10)
remotes[0].id = 1
remotes[1].id = 1
assert len(duplicate(remotes)) == 9
def test_inactive():
remotes = RemoteFileFactory.batch(10)
remotes[0].seeds = 0
remotes[0].downloads = 0
assert len(inactive(remotes)) == 9
def test_trusted(monkeypatch: MonkeyPatch):
monkeypatch.setenv("TRUSTED_WORDS", "one,two")
remotes = RemoteFileFactory.batch(10)
remotes[0].name = "oui one non"
remotes[1].name = "non two oui"
alter_remotes = trusted(remotes)
assert alter_remotes[0].color == Color.PRIMARY
assert alter_remotes[1].color == Color.PRIMARY
assert alter_remotes[2].color == Color.DEFAULT