forked from Nandaka/PixivUtil2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.PixivHelper.py
154 lines (133 loc) · 7.51 KB
/
test.PixivHelper.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
#!/c/Python27/python.exe
# -*- coding: UTF-8 -*-
import PixivHelper
import os
import unittest
from PixivModel import PixivImage, PixivArtist
from BeautifulSoup import BeautifulSoup
class TestPixivHelper(unittest.TestCase):
currPath = unicode(os.path.abspath('.'))
def testSanitizeFilename(self):
rootDir = '.'
filename = '12345.jpg'
currentDir = os.path.abspath('.')
expected = currentDir + os.sep + filename
result = PixivHelper.sanitizeFilename(filename, rootDir)
self.assertEqual(result, expected)
self.assertTrue(len(result) < 255)
def testSanitizeFilename2(self):
rootDir = '.'
filename = '12345.jpg'
currentDir = os.path.abspath('.')
expected = currentDir + os.sep + filename
result = PixivHelper.sanitizeFilename(filename, rootDir)
self.assertEqual(result, expected)
self.assertTrue(len(result) < 255)
def testCreateMangaFilename(self):
p = open('./test/test-image-manga.htm', 'r')
page = BeautifulSoup(p.read())
imageInfo = PixivImage(28820443, page)
imageInfo.imageCount = 100
page.decompose()
del page
##print imageInfo.PrintInfo()
nameFormat = '%member_token% (%member_id%)\%urlFilename% %page_number% %works_date_only% %works_res% %works_tools% %title% - %tags%'
expected = unicode(u'ffei (554800)\\28865189_p0 001 7-23-2012 Manga 2P Photoshop C82おまけ本 「沙耶は俺の嫁」サンプル - C82 R-18 おっぱい ぶっかけ 学園黙示録 漫画 眼鏡 高城沙耶.jpg')
result = PixivHelper.makeFilename(nameFormat, imageInfo, artistInfo=None, tagsSeparator=' ', fileUrl='http://i2.pixiv.net/img26/img/ffei/28865189_p0.jpg')
##print result
self.assertEqual(result, expected)
expected = unicode(u'ffei (554800)\\28865189_p14 015 7-23-2012 Manga 2P Photoshop C82おまけ本 「沙耶は俺の嫁」サンプル - C82 R-18 おっぱい ぶっかけ 学園黙示録 漫画 眼鏡 高城沙耶.jpg')
result = PixivHelper.makeFilename(nameFormat, imageInfo, artistInfo=None, tagsSeparator=' ', fileUrl='http://i2.pixiv.net/img26/img/ffei/28865189_p14.jpg')
##print result
self.assertEqual(result, expected)
expected = unicode(u'ffei (554800)\\28865189_p921 922 7-23-2012 Manga 2P Photoshop C82おまけ本 「沙耶は俺の嫁」サンプル - C82 R-18 おっぱい ぶっかけ 学園黙示録 漫画 眼鏡 高城沙耶.jpg')
result = PixivHelper.makeFilename(nameFormat, imageInfo, artistInfo=None, tagsSeparator=' ', fileUrl='http://i2.pixiv.net/img26/img/ffei/28865189_p921.jpg')
##print result
self.assertEqual(result, expected)
def testCreateFilenameUnicode(self):
p = open('./test/test-image-unicode.htm', 'r')
page = BeautifulSoup(p.read())
imageInfo = PixivImage(2493913, page)
page.decompose()
del page
nameFormat = '%member_token% (%member_id%)\%urlFilename% %works_date_only% %works_res% %works_tools% %title% - %tags%'
expected = unicode(u'balzehn (267014)\\2493913 12-23-2008 852x1200 Photoshop SAI つけペン アラクネのいる日常2 - R-18 これは萌える アラクネ ツンデレ ピロートークの上手さに定評のある兄弟 モンスター娘 モン娘のいる日常シリーズ 人外 魔物娘 魔界全土喝采.jpg')
result = PixivHelper.makeFilename(nameFormat, imageInfo, artistInfo=None, tagsSeparator=' ', fileUrl='http://i2.pixiv.net/img16/img/balzehn/2493913.jpg')
##print result
self.assertEqual(result, expected)
def testCreateAvatarFilenameFormatNoSubfolderNoRootDir(self):
p = open('./test/test-helper-avatar-name.htm', 'r')
page = BeautifulSoup(p.read())
artist = PixivArtist(mid=1107124, page=page)
filenameFormat = '%image_id% - %title%'
tagsSeparator = ' '
tagsLimit = 0
targetDir = ''
filename = PixivHelper.CreateAvatarFilename(filenameFormat, tagsSeparator, tagsLimit, artist, targetDir)
##print filename
self.assertEqual(filename, self.currPath + os.sep + u'folder.jpg')
def testCreateAvatarFilenameFormatWithSubfolderNoRootDir(self):
p = open('./test/test-helper-avatar-name.htm', 'r')
page = BeautifulSoup(p.read())
artist = PixivArtist(mid=1107124, page=page)
filenameFormat = '%member_token% (%member_id%)\%R-18%\%image_id% - %title% - %tags%'
tagsSeparator = ' '
tagsLimit = 0
targetDir = ''
filename = PixivHelper.CreateAvatarFilename(filenameFormat, tagsSeparator, tagsLimit, artist, targetDir)
##print filename
self.assertEqual(filename, self.currPath + os.sep + u'kirabara29 (1107124)\\folder.jpg')
def testCreateAvatarFilenameFormatNoSubfolderWithRootDir(self):
p = open('./test/test-helper-avatar-name.htm', 'r')
page = BeautifulSoup(p.read())
artist = PixivArtist(mid=1107124, page=page)
filenameFormat = '%image_id% - %title%'
tagsSeparator = ' '
tagsLimit = 0
targetDir = os.path.abspath('.')
filename = PixivHelper.CreateAvatarFilename(filenameFormat, tagsSeparator, tagsLimit, artist, targetDir)
##print filename
self.assertEqual(filename, targetDir + os.sep + u'folder.jpg')
def testCreateAvatarFilenameFormatWithSubfolderWithRootDir(self):
p = open('./test/test-helper-avatar-name.htm', 'r')
page = BeautifulSoup(p.read())
artist = PixivArtist(mid=1107124, page=page)
filenameFormat = '%member_token% (%member_id%)\%R-18%\%image_id% - %title% - %tags%'
tagsSeparator = ' '
tagsLimit = 0
targetDir = os.path.abspath('.')
filename = PixivHelper.CreateAvatarFilename(filenameFormat, tagsSeparator, tagsLimit, artist, targetDir)
##print filename
self.assertEqual(filename, targetDir + os.sep + u'kirabara29 (1107124)\\folder.jpg')
def testCreateAvatarFilenameFormatNoSubfolderWithCustomRootDir(self):
p = open('./test/test-helper-avatar-name.htm', 'r')
page = BeautifulSoup(p.read())
artist = PixivArtist(mid=1107124, page=page)
filenameFormat = '%image_id% - %title%'
tagsSeparator = ' '
tagsLimit = 0
targetDir = 'C:\\images'
filename = PixivHelper.CreateAvatarFilename(filenameFormat, tagsSeparator, tagsLimit, artist, targetDir)
##print filename
self.assertEqual(filename, u'C:\\images\\folder.jpg')
def testCreateAvatarFilenameFormatWithSubfolderWithCustomRootDir(self):
p = open('./test/test-helper-avatar-name.htm', 'r')
page = BeautifulSoup(p.read())
artist = PixivArtist(mid=1107124, page=page)
filenameFormat = '%member_token% (%member_id%)\%R-18%\%image_id% - %title% - %tags%'
tagsSeparator = ' '
tagsLimit = 0
targetDir = 'C:\\images'
filename = PixivHelper.CreateAvatarFilename(filenameFormat, tagsSeparator, tagsLimit, artist, targetDir)
##print filename
self.assertEqual(filename, u'C:\\images\\kirabara29 (1107124)\\folder.jpg')
def testParseLoginError(self):
p = open('./test/test-login-error.htm', 'r')
page = BeautifulSoup(p.read())
r = page.findAll('span', attrs={'class':'error'})
self.assertTrue(len(r)>0)
self.assertEqual(u'Please ensure your pixiv ID, email address and password is entered correctly.', r[0].string)
if __name__ == '__main__':
#unittest.main()
suite = unittest.TestLoader().loadTestsFromTestCase(TestPixivHelper)
unittest.TextTestRunner(verbosity=5).run(suite)