-
Notifications
You must be signed in to change notification settings - Fork 18
/
test.py
232 lines (185 loc) · 8.5 KB
/
test.py
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncio
import os
import io
import sys
import time
import unittest
from pixivpy_async import utils
from pixivpy_async.net import Net
from pixivpy_async.sync import *
sys.dont_write_bytecode = True
# get your refresh_token, and replace _TOKEN
# https://gist.github.com/ZipFile/c9ebedb224406f4f11845ab700124362
_TOKEN = "0zeYA-PllRYp1tfrsq_w3vHGU1rPy237JMf5oDt73c4"
aapi = AppPixivAPI()
aapi.login(refresh_token=_TOKEN)
t = time.time()
class TestMethods(unittest.TestCase):
def test_login(self):
newaapi = AppPixivAPI(bypass=True)
# newpapi = PixivAPI()
# self.assertIsNotNone(newaapi.login(_USERNAME, _PASSWORD))
credential = newaapi.login(refresh_token=_TOKEN)
self.assertIsNotNone(credential)
self.assertIsNotNone(credential.access_token)
self.assertIsNotNone(credential.refresh_token)
# self.assertIsNotNone(newpapi.login(_USERNAME, _PASSWORD))
def test_bypass(self):
newaapi = AppPixivAPI(bypass=True)
credential = newaapi.login(refresh_token=_TOKEN)
self.assertIsNotNone(credential)
self.assertIsNotNone(credential.access_token)
self.assertIsNotNone(credential.refresh_token)
detail = newaapi.user_detail(275527)
self.assertIsNotNone(detail)
self.assertIsNotNone(detail.user)
self.assertEqual(detail.user.id, 275527)
def test_bypass_2(self):
newaapi = AppPixivAPI(bypass=True, proxy="socks5://127.0.0.1:9011")
credential = newaapi.login(refresh_token=_TOKEN)
self.assertIsNotNone(credential)
self.assertIsNotNone(credential.access_token)
self.assertIsNotNone(credential.refresh_token)
detail = newaapi.user_detail(275527)
self.assertIsNotNone(detail)
self.assertIsNotNone(detail.user)
self.assertEqual(detail.user.id, 275527)
def test_socks_1(self):
newaapi = AppPixivAPI(proxy="socks5://127.0.0.1:9011")
credential = newaapi.login(refresh_token=_TOKEN)
self.assertIsNotNone(credential)
self.assertIsNotNone(credential.access_token)
self.assertIsNotNone(credential.refresh_token)
detail = newaapi.user_detail(275527)
self.assertIsNotNone(detail)
self.assertIsNotNone(detail.user)
self.assertEqual(detail.user.id, 275527)
def test_socks_2(self):
os.environ['ALL_PROXY'] = "socks5://127.0.0.1:9011"
newaapi = AppPixivAPI(env=True)
credential = newaapi.login(refresh_token=_TOKEN)
self.assertIsNotNone(credential)
self.assertIsNotNone(credential.access_token)
self.assertIsNotNone(credential.refresh_token)
detail = newaapi.user_detail(275527)
self.assertIsNotNone(detail)
self.assertIsNotNone(detail.user)
self.assertEqual(detail.user.id, 275527)
def test_new_illusts(self):
self.assertIsNotNone(aapi.illust_new())
def test_illust_1(self):
illust = aapi.illust_detail(59580629)
self.assertIsNotNone(illust)
self.assertIsNotNone(illust, illust)
self.assertEqual(illust.illust.id, 59580629)
self.assertIsNotNone(illust.illust.image_urls)
def test_illust_2(self):
self.assertIsNotNone(aapi.illust_comments(59580629))
def test_illust_3(self):
self.assertIsNotNone(aapi.ugoira_metadata(51815717))
def test_illust_4(self):
self.assertIsNotNone(aapi.illust_related(59580629))
def test_illust_5(self):
self.assertIsNotNone(aapi.illust_bookmark_detail(59580629))
def test_page(self):
self.assertIsNotNone(aapi.illust_recommended(
bookmark_illust_ids=[59580629], req_auth=False))
self.assertIsNotNone(aapi.illust_recommended(
bookmark_illust_ids=[59580629]))
json_result = aapi.illust_recommended(bookmark_illust_ids=[59580629])
# page down in some case
self.assertIsNotNone(aapi.parse_qs(json_result.next_url))
next_qs = aapi.parse_qs(json_result.next_url)
self.assertIsNotNone(aapi.illust_recommended(**next_qs))
def test_user_1(self):
self.assertIsNotNone(aapi.user_detail(275527))
def test_user_2(self):
self.assertIsNotNone(aapi.user_illusts(275527))
def test_user_3(self):
self.assertIsNotNone(aapi.user_list(2088434))
def test_user_4(self):
self.assertIsNotNone(aapi.user_related(7314824))
def test_user_5(self):
self.assertIsNotNone(aapi.search_user('ほし'))
self.assertIsNotNone(aapi.user_bookmark_tags_illust())
def test_bookmark(self):
self.assertIsNotNone(aapi.user_bookmarks_illust(2088434))
# def test_bookmark_1(self):
# self.assertIsNotNone(aapi.user_bookmark_tags_illust(2088434))
# def test_showcase(self):
# self.assertIsNotNone(aapi.showcase_article(4616))
def test_follow_1(self):
self.assertIsNotNone(aapi.user_following(7314824))
def test_follow_2(self):
self.assertIsNotNone(aapi.user_follower(275527))
def test_follow_3(self):
self.assertIsNotNone(aapi.user_mypixiv(275527))
def test_add(self):
self.assertIsNot(aapi.user_follow_add(24687177), {})
def test_del(self):
self.assertIsNot(aapi.user_follow_del(24687177), {})
def test_novel(self):
self.assertIsNotNone(aapi.search_novel('abc'))
self.assertIsNotNone(aapi.user_novels(2748828))
self.assertIsNotNone(aapi.novel_series(0))
self.assertIsNotNone(aapi.novel_detail(14588477))
self.assertIsNotNone(aapi.novel_text(14588477))
def test_tag(self):
self.assertIsNotNone(aapi.trending_tags_illust())
first_tag = None
response = aapi.trending_tags_illust()
for trend_tag in response.trend_tags[:10]:
if not first_tag:
first_tag = trend_tag.tag
self.assertIsNotNone(aapi.search_illust(
first_tag, search_target='partial_match_for_tags'))
def test_ranking(self):
self.assertIsNotNone(aapi.illust_ranking('day_male'))
self.assertIsNotNone(aapi.illust_follow(req_auth=True))
self.assertIsNotNone(aapi.illust_recommended(req_auth=True))
def test_bookmark_add(self):
illust_id = 74187223
tags = ['Fate/GO', '50000users 入り', '私服']
self.assertIsNotNone(aapi.illust_bookmark_add(illust_id, tags=tags))
self.assertIsNotNone(aapi.illust_bookmark_delete(illust_id))
self.assertIsNotNone(aapi.illust_bookmark_detail(illust_id))
def test_download(self):
self.assertIsNotNone(aapi.illust_ranking('day', date='2016-08-01'))
json_result = aapi.illust_ranking('day', date='2019-08-01')
# Disabled due to Rate Limit
for illust in json_result.illusts[:5]:
image_url = illust.meta_single_page.get(
'original_image_url', illust.image_urls.large)
url_basename = os.path.basename(image_url)
extension = os.path.splitext(url_basename)[1]
name = "illust_id_%d_%s%s" % (illust.id, illust.title, extension)
aapi.download(image_url, path='.', name=name)
aapi.download(image_url, path='.', fname=io.BytesIO())
self.assertTrue(os.path.exists(name))
def test_others(self):
newaapi0 = AppPixivAPI()
# self.assertIsNotNone(newaapi0.login(_USERNAME, _PASSWORD))
self.assertIsNotNone(newaapi0.login(refresh_token=_TOKEN))
newaapi = AppPixivAPI()
self.assertRaises(error.NoLoginError, newaapi.login, None)
newaapi2 = AppPixivAPI()
self.assertRaises(error.AuthTokenError,
newaapi2.login, refresh_token='89urwei')
newaapi3 = AppPixivAPI()
self.assertRaises(error.LoginError, newaapi3.login,
username='89urwei', password='97324yuieh')
self.assertIsNone(newaapi.set_auth('None', 'None'))
self.assertIsNone(newaapi.set_client('None', 'None'))
self.assertIsNone(newaapi.set_accept_language('ja-jp'))
self.assertIsNotNone(utils.Utils().set_params(fsadf=[1, 2, 3]))
self.assertIsNone(utils.Utils().parse_qs(None))
def test_http_methods(self):
loop = asyncio.get_event_loop()
self.assertIsNotNone(loop.run_until_complete(Net().post(
'https://httpbin.org/post', None, {'accept': 'application/json'}, None)))
self.assertIsNotNone(loop.run_until_complete(Net().delete(
'https://httpbin.org/delete', {'accept': 'application/json'}, None)))
if __name__ == '__main__':
unittest.main()