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/bridge/test_nyaa.py

90 lines
3.3 KiB
Python
Raw Normal View History

2023-01-06 21:01:11 +00:00
# flake8: noqa: E501
2023-01-06 17:19:59 +00:00
from typing import List
from pynyaata.bridge.nyaa import Nyaa
2023-01-06 21:01:11 +00:00
from pynyaata.types import Color, RemoteFile
2023-01-06 17:19:59 +00:00
from pytest import mark
import requests
from requests_mock import Mocker
2023-01-06 21:01:11 +00:00
def normalize(remotes: List[RemoteFile]):
for i in range(len(remotes)):
remotes[i].seeds = 1
remotes[i].leechs = 10
remotes[i].downloads = 100
return remotes
2023-01-06 17:19:59 +00:00
def test_search_url():
assert (
Nyaa().search_url()
== "https://nyaa.si?f=0&c=1_3&q=%28+vf%29%7C%28+vostfr%29%7C%28+multi%29%7C%28+fre%29&s=id&o=desc&p=1"
)
assert (
Nyaa().search_url("", 2)
== "https://nyaa.si?f=0&c=1_3&q=%28+vf%29%7C%28+vostfr%29%7C%28+multi%29%7C%28+fre%29&s=id&o=desc&p=2"
)
assert (
Nyaa().search_url("test", 1)
== "https://nyaa.si?f=0&c=1_3&q=%28test+vf%29%7C%28test+vostfr%29%7C%28test+multi%29%7C%28test+fre%29&s=size&o=desc&p=1"
)
assert (
Nyaa().search_url("test", 2)
== "https://nyaa.si?f=0&c=1_3&q=%28test+vf%29%7C%28test+vostfr%29%7C%28test+multi%29%7C%28test+fre%29&s=size&o=desc&p=2"
)
@mark.asyncio
async def test_search(requests_mock: Mocker):
requests_mock.real_http = True
requests_mock.get(
Nyaa().search_url(), text=requests.get("https://nyaa.si/user/Chaussette33").text
)
2023-01-06 21:01:11 +00:00
remotes: List[RemoteFile] = [
RemoteFile(
bridge="Nyaa",
id=1080919,
category="Anime - Non-English-translated",
color=Color.DEFAULT,
name="Heroic Age intégrale VOSTFR",
link="https://nyaa.si/view/1080919",
comment=4,
comment_url="https://nyaa.si/view/1080919#comments",
magnet="magnet:?xt=urn:btih:f610a3cd6360a36c789d1166e5efc12e3a3bb3ca&dn=Heroic%20Age%20int%C3%A9grale%20VOSTFR&tr=http%3A%2F%2Fnyaa.tracker.wf%3A7777%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce",
torrent="https://nyaa.si/download/1080919.torrent",
size=4509715660,
date="2018-10-04 16:26:30",
seeds=1,
leechs=10,
downloads=100,
nb_pages=1,
),
RemoteFile(
bridge="Nyaa",
id=1080916,
category="Anime - Non-English-translated",
color=Color.DEFAULT,
name="Nisekoi VOSTFR S1 + S2 1080p",
link="https://nyaa.si/view/1080916",
comment=3,
comment_url="https://nyaa.si/view/1080916#comments",
magnet="magnet:?xt=urn:btih:11c4b4d513260bf293975f1d24d8752ac5073fb1&dn=Nisekoi%20VOSTFR%20S1%20%2B%20S2%201080p&tr=http%3A%2F%2Fnyaa.tracker.wf%3A7777%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce",
torrent="https://nyaa.si/download/1080916.torrent",
size=9878424780,
date="2018-10-04 16:17:56",
seeds=1,
leechs=10,
downloads=100,
nb_pages=1,
),
]
2023-01-06 17:19:59 +00:00
2023-01-06 21:01:11 +00:00
assert normalize(await Nyaa().search()) == remotes