Skip to content

Commit 17d6998

Browse files
add a simple unittest
1 parent 8daea5a commit 17d6998

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import unittest
2+
import requests
3+
from niconico_search_api_template import niconico_search
4+
5+
class TestNicoNicoSearch(unittest.TestCase):
6+
def test_niconico_search_good_request(self) -> None:
7+
response = requests.post("https://api.search.nicovideo.jp/api/v2/snapshot/video/contents/search",
8+
data={
9+
"q": "初音ミク",
10+
"targets": "title",
11+
"_sort": "-viewCounter",
12+
"_context": "Mac PC",
13+
"fields": "title,contentId",
14+
"_offset": "3",
15+
"_limit": "3"
16+
},
17+
headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac)"})
18+
self.assertEqual(response.status_code, 200)
19+
20+
def test_niconico_search_bad_request(self) -> None:
21+
response = requests.post("https://api.search.nicovideo.jp/api/v2/snapshot/video/contents/search",
22+
data={
23+
"q": "初音ミク",
24+
"targets": "title",
25+
"_sort": "-viewCounter",
26+
"_context": "Mac PC",
27+
"fields": "title,contentId",
28+
"_offset": "3",
29+
"_limit": "invalid_input"
30+
},
31+
headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac)"})
32+
self.assertEqual(response.status_code, 400)
33+
34+
if __name__ == '__main__':
35+
unittest.main()

0 commit comments

Comments
 (0)