forked from maxcutler/python-wordpress-xmlrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_comments.py
More file actions
77 lines (58 loc) · 2.62 KB
/
Copy pathtest_comments.py
File metadata and controls
77 lines (58 loc) · 2.62 KB
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
import random
from nose.plugins.attrib import attr
from tests import WordPressTestCase
from wordpress_xmlrpc.methods import comments, posts
from wordpress_xmlrpc.wordpress import WordPressComment, WordPressPost
class TestComments(WordPressTestCase):
def setUp(self):
super(TestComments, self).setUp()
post = WordPressPost()
post.title = 'Comments Test Post'
post.slug = 'comments-test-post'
post.user = self.userid
self.post_id = self.client.call(posts.NewPost(post, True))
@attr('comments')
def test_get_comment_status_list(self):
status_list = self.client.call(comments.GetCommentStatusList())
self.assertTrue(isinstance(status_list, dict))
@attr('comments')
def test_comment_lifecycle(self):
comment = WordPressComment()
comment.content = 'This is a test comment.'
comment.user = self.userid
# create comment
comment_id = self.client.call(comments.NewComment(self.post_id, comment))
self.assertTrue(comment_id)
# edit comment
comment.content = 'This is an edited comment.'
response = self.client.call(comments.EditComment(comment_id, comment))
self.assertTrue(response)
# delete comment
response = self.client.call(comments.DeleteComment(comment_id))
self.assertTrue(response)
@attr('comments')
def test_post_comments(self):
# create a bunch of comments
comment_list = []
counter = 0
for i in range(1, random.randint(6, 15)):
comment = WordPressComment()
comment.content = 'Comment #%s' % counter
comment.user = self.userid
comment_id = self.client.call(comments.NewComment(self.post_id, comment))
comment_list.append(comment_id)
counter += 1
# retrieve comment count
comment_counts = self.client.call(comments.GetCommentCount(self.post_id))
self.assertEqual(comment_counts['total_comments'], counter)
# fetch a subset of the comments
num_comments = 5
post_comments = self.client.call(comments.GetComments({'post_id': self.post_id, 'number': num_comments}))
self.assert_list_of_classes(post_comments, WordPressComment)
self.assertEqual(num_comments, len(post_comments))
# cleanup
for comment in comment_list:
self.client.call(comments.DeleteComment(comment))
def tearDown(self):
self.client.call(posts.DeletePost(self.post_id))
super(WordPressTestCase, self).tearDown()