# flake8: noqa: E501 from typing import List from pynyaata2.bridge.nyaa import Nyaa, EraiRaws from pynyaata2.types import Color, RemoteFile from pytest import mark import requests from requests_mock import Mocker 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 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") == "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" ) assert ( EraiRaws().search_url() == "https://nyaa.si/user/Erai-raws?f=0&c=1_2&q=+fre&s=id&o=desc&p=1" ) assert ( EraiRaws().search_url("", 2) == "https://nyaa.si/user/Erai-raws?f=0&c=1_2&q=+fre&s=id&o=desc&p=2" ) assert ( EraiRaws().search_url("test") == "https://nyaa.si/user/Erai-raws?f=0&c=1_2&q=test+fre&s=size&o=desc&p=1" ) assert ( EraiRaws().search_url("test", 2) == "https://nyaa.si/user/Erai-raws?f=0&c=1_2&q=test+fre&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 ) assert normalize(await Nyaa().search()) == [ 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, ), ]