def test_post_lifecycle(self): # create a post object post = WordPressPost() post.title = 'Test post' post.slug = 'test-post' post.content = 'This is test post using the XML-RPC API.' post.comment_status = 'open' post.user = self.userid # create the post as a draft post_id = self.client.call(posts.NewPost(post)) self.assertTrue(post_id) # fetch the newly-created post post2 = self.client.call(posts.GetPost(post_id)) self.assertTrue(isinstance(post2, WordPressPost)) self.assertEqual(str(post2.id), post_id) # update the post post2.content += '<br><b>Updated:</b> This post has been updated.' post2.post_status = 'publish' response = self.client.call(posts.EditPost(post_id, post2)) self.assertTrue(response) # delete the post response = self.client.call(posts.DeletePost(post_id)) self.assertTrue(response)
def test_revisions(self): original_title = 'Revisions test' post = WordPressPost() post.title = original_title post.slug = 'revisions-test' post.content = 'This is a test post using the XML-RPC API.' post_id = self.client.call(posts.NewPost(post)) self.assertTrue(post_id) post.title = 'Revisions test updated' post.content += ' This is a second revision.' response = self.client.call(posts.EditPost(post_id, post)) self.assertTrue(response) # test wp.getRevisions revision_list = self.client.call(posts.GetRevisions(post_id, ['post'])) self.assert_list_of_classes(revision_list, WordPressPost) # workaround for WP bug #22686/22687 # an auto-draft revision will survive wp.newPost, so pick the 2nd revision self.assertEqual(2, len(revision_list)) real_rev = revision_list[1] self.assertTrue(real_rev) self.assertNotEquals(post_id, real_rev.id) # test wp.restoreRevision response2 = self.client.call(posts.RestoreRevision(real_rev.id)) self.assertTrue(response2) post2 = self.client.call(posts.GetPost(post_id)) self.assertEquals(original_title, post2.title) # cleanup self.client.call(posts.DeletePost(post_id))
def assemble_post(self, estate, old_post, published=True): post = WordPressPost() post_id = None post.comment_status = 'open' description = self.render_post_description(estate) if old_post: post_id = old_post.id post.custom_fields = [ {'key': '_aioseop_description', 'value': description}, {'key': '_aioseop_title', 'value': self.render_seo_post_title(estate)}, {'key': '_aioseop_keywords', 'value': u','.join(self.render_post_tags(estate))}, ] post.custom_fields.extend(self.render_custom_fields(estate)) if post_id: for custom_field in post.custom_fields: custom_field['id'] = self.get_custom_field_id(old_post.custom_fields, custom_field.get('key')) post.title = self.render_post_title(estate) post_images = self.render_post_images(estate, post_id) images = u''.join(post_images) post.content = self.render_post_body(estate, description, images) post.terms_names = {'post_tag': self.render_post_tags(estate)} post.terms = self.render_post_category(estate) post.date = estate.history.modificated - datetime.timedelta(hours=4) if published: post.post_status = 'publish' return post
def assemble_post(self, estate, old_post, published=True): post = WordPressPost() post_id = None post.comment_status = 'open' description = self.render_post_description(estate) if old_post: post_id = old_post.id post.custom_fields = [ { 'key': '_aioseop_description', 'value': description }, { 'key': '_aioseop_title', 'value': self.render_seo_post_title(estate) }, { 'key': '_aioseop_keywords', 'value': u','.join(self.render_post_tags(estate)) }, ] post.custom_fields.extend(self.render_custom_fields(estate)) if post_id: for custom_field in post.custom_fields: custom_field['id'] = self.get_custom_field_id( old_post.custom_fields, custom_field.get('key')) post.title = self.render_post_title(estate) post_images = self.render_post_images(estate, post_id) images = u''.join(post_images) post.content = self.render_post_body(estate, description, images) post.terms_names = {'post_tag': self.render_post_tags(estate)} post.terms = self.render_post_category(estate) post.date = estate.history.modificated - datetime.timedelta(hours=4) if published: post.post_status = 'publish' return post