forked from Nandaka/PixivUtil2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_PixivModel_whitecube.py
139 lines (118 loc) · 5.25 KB
/
test_PixivModel_whitecube.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
#!C:/Python37-32/python
# -*- coding: UTF-8 -*-
import json
import os
import unittest
import PixivConstant
import PixivHelper
from PixivArtist import PixivArtist
from PixivException import PixivException
PixivConstant.PIXIVUTIL_LOG_FILE = 'pixivutil.test.log'
class TestPixivModel_WhiteCube(unittest.TestCase):
currPath = os.path.abspath('.')
PixivHelper.get_logger()
testParseMemberImagesByTagsLastPageOffset = 48
# @pytest.mark.xfail
# def testParseImage(self):
# p = open('./test/work_details_modal_whitecube.json', 'r')
# image = PixivImage(59521621, p.read())
# self.assertIsNotNone(image)
# image.PrintInfo()
# self.assertEqual(image.imageMode, "big")
#
# @pytest.mark.xfail
# def testParseManga(self):
# p = open('./test/work_details_modal_whitecube-manga.json', 'r')
# image = PixivImage(59532028, p.read())
# self.assertIsNotNone(image)
# image.PrintInfo()
# self.assertEqual(image.imageMode, "manga")
def testParseMemberError(self):
p = open('./test/ajax-error.json', 'r')
try:
PixivArtist(14095911, p.read())
self.fail("Exception expected.")
except PixivException as ex:
self.assertTrue(ex.errorCode == PixivException.OTHER_MEMBER_ERROR)
def testParseMemberImages(self):
p = open('./test/all-14095911.json', 'r')
member = PixivArtist(14095911, p.read(), False, 0, 24)
self.assertIsNotNone(member)
p2 = open('./test/userdetail-14095911.json', 'r')
info = json.loads(p2.read())
member.ParseInfo(info, False, False)
member.PrintInfo()
self.assertEqual(member.artistId, 14095911)
self.assertTrue(member.haveImages)
self.assertFalse(member.isLastPage)
self.assertEqual(member.artistToken, 'p199451')
self.assertGreater(member.totalImages, 70)
self.assertEqual(member.artistAvatar, "https://i.pximg.net/user-profile/img/2018/02/01/23/55/46/13768317_dc1474fef3dc982ade71c1b2dbf32d9e.png")
def testParseMemberImages2(self):
p = open('./test/all-26357.json', 'r')
member = PixivArtist(26357, p.read(), False, 0, 24)
self.assertIsNotNone(member)
p2 = open('./test/userdetail-26357.json', 'r')
info = json.loads(p2.read())
member.ParseInfo(info, False, False)
member.PrintInfo()
self.assertEqual(member.artistId, 26357)
self.assertTrue(member.haveImages)
self.assertFalse(member.isLastPage)
self.assertEqual(member.artistToken, 'yukimaruko')
self.assertGreater(member.totalImages, 7)
self.assertEqual(member.artistAvatar, "https://s.pximg.net/common/images/no_profile.png")
# https://www.pixiv.net/ajax/user/14095911/profile/all
def testParseMemberImagesLastPage(self):
p = open('./test/all-14095911.json', 'r')
member = PixivArtist(14095911, p.read(), False, 144, 48)
self.assertIsNotNone(member)
p2 = open('./test/userdetail-14095911.json', 'r')
info = json.loads(p2.read())
member.ParseInfo(info, False, False)
member.PrintInfo()
self.assertEqual(member.totalImages, 183)
self.assertTrue(member.isLastPage)
self.assertEqual(member.artistId, 14095911)
self.assertTrue(member.haveImages)
# /ajax/user/14095911/illustmanga/tag?tag=R-18&offset=0&limit=48
def testParseMemberImagesByTags(self):
p = open('./test/tag-R-18-14095911.json', 'r')
member = PixivArtist(14095911, p.read(), False, 0, 24)
self.assertIsNotNone(member)
p2 = open('./test/userdetail-14095911.json', 'r')
info = json.loads(p2.read())
member.ParseInfo(info, False, False)
member.PrintInfo()
self.assertEqual(member.artistId, 14095911)
self.assertTrue(member.haveImages)
self.assertFalse(member.isLastPage)
# /ajax/user/14095911/illustmanga/tag?tag=R-18&offset=48&limit=48
def testParseMemberImagesByTagsLastPage(self):
p = open('./test/tag-R-18-14095911-lastpage.json', 'r')
member = PixivArtist(14095911, p.read(), False, self.testParseMemberImagesByTagsLastPageOffset, 48)
self.assertIsNotNone(member)
p2 = open('./test/userdetail-14095911.json', 'r')
info = json.loads(p2.read())
member.ParseInfo(info, False, False)
member.PrintInfo()
self.assertEqual(member.totalImages, 85)
self.assertTrue(member.isLastPage)
self.assertEqual(member.artistId, 14095911)
self.assertTrue(member.haveImages)
print(f"Last Image = {member.imageList[-1]}")
def testParseMemberBookmarksByTags(self):
p = open('./test/bookmarks-1039353.json', 'r')
member = PixivArtist(1039353, p.read(), False, 0, 24)
self.assertIsNotNone(member)
p2 = open('./test/userdetail-1039353.json', 'r')
info = json.loads(p2.read())
member.ParseInfo(info, False, True)
member.PrintInfo()
self.assertEqual(member.artistId, 1039353)
self.assertTrue(member.haveImages)
self.assertFalse(member.isLastPage)
if __name__ == '__main__':
# unittest.main()
suite = unittest.TestLoader().loadTestsFromTestCase(TestPixivModel_WhiteCube)
unittest.TextTestRunner(verbosity=5).run(suite)