File size: 2,273 Bytes
0a1b571
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from math import inf

import pytest
from fastapi.testclient import TestClient


@pytest.fixture(scope="package")
def client():
    from hibiapi.app import app, application

    application.RATE_LIMIT_MAX = inf

    with TestClient(app, base_url="http://testserver/api/wallpaper/") as client:
        client.headers["Cache-Control"] = "no-cache"
        yield client


def test_wallpaper(client: TestClient):
    response = client.get("wallpaper", params={"category": "girl"})
    assert response.status_code == 200
    assert response.json().get("msg") == "success"


def test_wallpaper_limit(client: TestClient):
    response = client.get("wallpaper", params={"category": "girl", "limit": "21"})

    assert response.status_code == 200
    assert response.json()["msg"] == "success"
    assert len(response.json()["res"]["wallpaper"]) == 21


def test_wallpaper_skip(client: TestClient):
    response_1 = client.get(
        "wallpaper", params={"category": "girl", "limit": "20", "skip": "20"}
    )
    response_2 = client.get(
        "wallpaper", params={"category": "girl", "limit": "40", "skip": "0"}
    )

    assert response_1.status_code == 200 and response_2.status_code == 200
    assert (
        response_1.json()["res"]["wallpaper"][0]["id"]
        == response_2.json()["res"]["wallpaper"][20]["id"]
    )


def test_vertical(client: TestClient):
    response = client.get("vertical", params={"category": "girl"})
    assert response.status_code == 200
    assert response.json().get("msg") == "success"


def test_vertical_limit(client: TestClient):
    response = client.get("vertical", params={"category": "girl", "limit": "21"})
    assert response.status_code == 200
    assert response.json().get("msg") == "success"
    assert len(response.json()["res"]["vertical"]) == 21


def test_vertical_skip(client: TestClient):
    response_1 = client.get(
        "vertical", params={"category": "girl", "limit": "20", "skip": "20"}
    )
    response_2 = client.get(
        "vertical", params={"category": "girl", "limit": "40", "skip": "0"}
    )

    assert response_1.status_code == 200 and response_2.status_code == 200
    assert (
        response_1.json()["res"]["vertical"][0]["id"]
        == response_2.json()["res"]["vertical"][20]["id"]
    )