6 WordPress xml-rpc client library
9 Copyright (C) 2005 Michele Ferretti
11 http://www.blackbirdblog.it
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License
15 as published by the Free Software Foundation; either version 2
16 of the License, or any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 __author__
= "Michele Ferretti <black.bird@tiscali.it>"
30 __version__
= "$Revision: 1.0 $"
31 __date__
= "$Date: 2005/05/02 $"
32 __copyright__
= "Copyright (c) 2005 Michele Ferretti"
39 class TestWordPressClient(unittest
.TestCase
):
42 self
.wp
= wordpresslib
.WordPressClient('http://www.site.com/wordpress/xmlrpc.php', 'username', 'password')
46 def ifEmpty(self
, obj
, msg
):
47 self
.failUnless( '%s is None' % msg
)
48 self
.failIf( obj
== '', '%s is empty' % msg
)
50 def testGetUserInfo(self
):
51 user
= self
.wp
.getUserInfo()
52 self
.ifEmpty(user
, 'user')
53 self
.ifEmpty(user
.id, 'user id')
55 def testGetUsersBlogs(self
):
56 blogs
= self
.wp
.getUsersBlogs()
57 self
.failUnless( blogs
, 'blogs is None')
59 self
.failUnless( blog
, 'blog is None')
60 self
.ifEmpty(blog
.id, 'blog id')
61 self
.ifEmpty(blog
.url
, 'blog url')
63 def testGetRecentPosts(self
):
64 for post
in self
.wp
.getRecentPosts(self
.recentPosts
):
65 self
.ifEmpty(post
, 'post')
66 self
.ifEmpty(post
.id, 'post id')
68 def testGetCategoryList(self
):
69 categories
= tuple(self
.wp
.getCategoryList())
70 self
.failUnless( categories
, 'blog categories are None')
72 self
.ifEmpty(i
, 'category item')
73 self
.ifEmpty(i
.id, 'category id')
74 self
.ifEmpty(i
.name
, 'category name')
76 def testNewPost(self
):
77 categories
= tuple(self
.wp
.getCategoryList())
78 p
= wordpresslib
.WordPressPost()
80 p
.description
= u
'Questo \xe8 una stringa unicode'
81 p
.categories
= (self
.wp
.getCategoryIdFromName('Progetti'),)
82 idNewPost
= self
.wp
.newPost(p
, True)
83 self
.ifEmpty(idNewPost
, 'new post id')
84 self
.failIf( idNewPost
< 1 , 'new post id is less than 0')
86 result
= self
.wp
.deletePost(idNewPost
)
87 self
.failUnless( result
, 'deletePost %d failed, return=%s' % (idNewPost
, str(result
)) )
89 def testGetPost(self
):
91 lastPost
= self
.wp
.getLastPost()
92 self
.failUnless( lastPost
, 'last post is None')
93 for i
in range(lastPost
.id, 0,-1):
95 post
= self
.wp
.getPost(i
)
97 self
.fail('post id = %d eccezione %s' % (i
,ex
))
98 self
.ifEmpty( post
, 'post')
99 self
.ifEmpty( post
.id, 'post id')
100 self
.ifEmpty( post
.title
, 'post title')
101 self
.ifEmpty( post
.permaLink
, 'post permaLink')
102 self
.ifEmpty( post
.description
, 'post description')
103 self
.ifEmpty( post
.user
, 'post user')
104 self
.ifEmpty( post
.date
, 'post date')
105 self
.ifEmpty( post
.categories
, 'post categories')
107 def testGetNotFoundPost(self
):
108 # gest not found post
110 post
= self
.wp
.getPost(10000000)
111 except Exception, ex
:
112 self
.failIf(ex
.id != 404, 'Post not found response is not 404')
114 def testGetPostCategories(self
):
115 lastPost
= self
.wp
.getLastPost()
116 self
.failUnless( lastPost
, 'last post is None')
118 for cat
in self
.wp
.getPostCategories(lastPost
.id):
120 self
.failIf( cat
.isPrimary
!= 1, 'first post category is not isPrimary')
121 self
.ifEmpty( cat
, 'post category')
122 self
.ifEmpty( cat
.name
, 'post category name')
125 def testDeletePost(self
):
126 lastPost
= self
.wp
.getLastPost()
127 self
.failUnless( lastPost
, 'last post is None')
128 result
= self
.wp
.deletePost(lastPost
.id)
129 self
.failUnless( result
, 'deletePost %d failed, return=%s' % (lastPost
.id, str(result
)) )
131 def testGetLastPost(self
):
132 lastPost
= self
.wp
.getLastPost()
133 self
.failUnless( lastPost
, 'last post is None')
134 self
.ifEmpty( lastPost
.id, 'post id')
135 self
.ifEmpty( lastPost
.title
, 'post title')
136 self
.ifEmpty( lastPost
.permaLink
, 'post permaLink')
137 self
.ifEmpty( lastPost
.description
, 'post description')
138 self
.ifEmpty( lastPost
.user
, 'post user')
139 self
.ifEmpty( lastPost
.date
, 'post date')
140 self
.ifEmpty( lastPost
.categories
, 'post categories')
142 def testEditPost(self
):
143 categories
= tuple(self
.wp
.getCategoryList())
144 lastPost
= self
.wp
.getLastPost()
145 self
.failUnless( lastPost
, 'last post is None')
146 p
= wordpresslib
.WordPressPost()
147 p
.title
= lastPost
.title
+' (modificato)'
149 p
.description
= lastPost
.description
+ u
'<br><br><em>Questa \xe8 una stringa unicode modificata</em>'
150 p
.categories
= map(self
.wp
.getCategoryIdFromName
, ('Python', 'Progetti'))
151 self
.wp
.editPost(lastPost
.id, p
, True)
153 def testPublishPost(self
):
154 lastPost
= self
.wp
.getLastPost()
155 self
.failUnless( lastPost
, 'last post is None')
156 result
= self
.wp
.publishPost(lastPost
.id)
157 self
.failUnless( result
, 'publishPost %d failed, return=%s' % (lastPost
.id, str(result
)) )
159 def testNewMediaObject(self
):
160 result
= self
.wp
.newMediaObject('python.jpg')
161 self
.failUnless( result
, 'newMediaObject result is None')
163 if __name__
== '__main__':
166 suite = unittest.makeSuite(TestWordPressClient)
167 unittest.TextTestRunner(verbosity=2).run(suite)