Spaces:
Runtime error
Runtime error
File size: 3,491 Bytes
e67043b |
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
from fastapi.testclient import TestClient
from .api import build_tool, DoubanAPI, ComingMovieInfo, PlayingMovieInfo
from typing import List
class DoubanMock(DoubanAPI):
def __init__(self) -> None:
pass
def get_coming(self) -> List[ComingMovieInfo]:
return [
ComingMovieInfo(
date="2020-12-12",
title="test1",
cate="test1",
region="test1",
wantWatchPeopleNum="1",
link="test1",
),
ComingMovieInfo(
date="2021-12-12",
title="test2",
cate="test2",
region="test2",
wantWatchPeopleNum="2",
link="test2",
),
ComingMovieInfo(
date="2022-12-12",
title="test3",
cate="test3",
region="test3",
wantWatchPeopleNum="3",
link="test3",
),
]
def get_now_playing(self) -> List[PlayingMovieInfo]:
return [
PlayingMovieInfo(
title="test1",
score="1.1",
region="test1",
director="test1",
actors="test1",
link="test1",
),
PlayingMovieInfo(
title="test2",
score="2.2",
region="test2",
director="test2",
actors="test2",
link="test2",
),
PlayingMovieInfo(
title="test3",
score="3.3",
region="test3",
director="test3",
actors="test3",
link="test3",
),
]
def get_movie_detail(self, url: str) -> str:
return url
app = build_tool({"debug": True, "douban_api": DoubanMock()})
client = TestClient(app)
def test_get_coming():
response = client.get("/coming_out_filter", params={"args": "全部, 全部, 2, True"})
assert response.status_code == 200
assert response.json() == {
"date": {
"1": "2021-12-12",
"0": "2022-12-12",
},
"title": {
"1": "test2",
"0": "test3",
},
"cate": {
"1": "test2",
"0": "test3",
},
"region": {
"1": "test2",
"0": "test3",
},
"wantWatchPeopleNum": {
"1": "2人",
"0": "3人",
},
}
def test_get_playing():
response = client.get("/now_playing_out_filter", params={"args": "全部, 3, False"})
assert response.status_code == 200
assert response.json() == {
"title": {
"0": "test1",
"1": "test2",
"2": "test3",
},
"score": {
"0": "1.1",
"1": "2.2",
"2": "3.3",
},
"region": {
"0": "test1",
"1": "test2",
"2": "test3",
},
"director": {
"0": "test1",
"1": "test2",
"2": "test3",
},
"actors": {
"0": "test1",
"1": "test2",
"2": "test3",
},
}
def test_detail():
response = client.get("/print_detail", params={"args": "test1"})
assert response.status_code == 200
assert response.json() == "test1test1"
|