forked from maxcutler/python-wordpress-xmlrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_categories.py
More file actions
71 lines (56 loc) · 2.48 KB
/
Copy pathtest_categories.py
File metadata and controls
71 lines (56 loc) · 2.48 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
from nose.plugins.attrib import attr
from tests import WordPressTestCase
from wordpress_xmlrpc.methods import categories, posts
from wordpress_xmlrpc.wordpress import WordPressCategory, WordPressTag, WordPressPost
class TestCategories(WordPressTestCase):
@attr('categories')
def test_get_tags(self):
tags = self.client.call(categories.GetTags())
self.assert_list_of_classes(tags, WordPressTag)
@attr('categories')
def test_get_categories(self):
cats = self.client.call(categories.GetCategories())
self.assert_list_of_classes(cats, WordPressCategory)
@attr('categories')
def test_category_lifecycle(self):
# Create category object
cat = WordPressCategory()
cat.name = 'Test Category'
# Create the category in WordPress
cat_id = self.client.call(categories.NewCategory(cat))
self.assertTrue(cat_id)
cat.cat_id = cat_id
# Check that the new category shows in category suggestions
suggestions = self.client.call(categories.SuggestCategories('test', 10))
self.assertTrue(isinstance(suggestions, list))
found = False
for suggestion in suggestions:
if suggestion['category_id'] == str(cat_id):
found = True
break
self.assertTrue(found)
# Delete the category
response = self.client.call(categories.DeleteCategory(cat_id))
self.assertTrue(response)
@attr('categories')
def test_category_post(self):
# create a test post
post = WordPressPost()
post.title = 'Test Post'
post.slug = 'test-post'
post.user = self.userid
post_id = self.client.call(posts.NewPost(post, False))
# create a test category
cat = WordPressCategory()
cat.name = 'Test Category'
cat.cat_id = self.client.call(categories.NewCategory(cat))
# set category on post
response = self.client.call(categories.SetPostCategories(post_id, [cat.struct]))
self.assertTrue(response)
# fetch categories for the post to verify
post_cats = self.client.call(categories.GetPostCategories(post_id))
self.assert_list_of_classes(post_cats, WordPressCategory)
self.assertEqual(post_cats[0].cat_id, str(cat.cat_id))
# cleanup
self.client.call(categories.DeleteCategory(cat.cat_id))
self.client.call(posts.DeletePost(post_id))