class TestUpdateArticle(unittest.TestCase): """ Test method VimBlogger.update_article """ def setUp(self): """ Create VimBlogger object """ self.vimob = VimBlogger(None, shared.LOGIN, shared.PASS) for bid, bname in {1: 'one', 3: 'test', 7: 'blog_name'}.items(): blog = shared.MockBlog(bname, bid) self.vimob.feed.entry.append(blog) self.vimob._set_blog('test') def test_wrong_argument_types(self): """ Test update_article method with wrong argument types """ self.assertRaises(TypeError, self.vimob.update_article, None, None) def test_no_id_in_attrs(self): """ Test update_article method with no id in attrs """ self.assertRaises(Exception, self.vimob.update_article, '<p>update</p>', []) def test_update(self): """ Test update_article method with no id in attrs """ attrs = {'id': 1234567890, 'title': 'update', 'date': '2001-01-01T00:02:19.001+01:00', 'tags': "tag1, tag2, tag3"} post = self.vimob.update_article('<p>update</p>', attrs) self.assertEqual(post.title.text, 'update') self.assertEqual(post.id.text, '1234567890') self.assertEqual(post.content.text, '<p>update</p>') self.assertTrue(post.updated.text is not None)
def post(self): """ Do post article """ bufcontent = "\n".join(self.buff) html, attrs = blogArticleString(bufcontent) parse_msg = self._check_html(html, True) if parse_msg: self._open_qf(parse_msg) return "There are errors in generated document" if not self.password: self.password = \ vim.eval('inputsecret("Enter your gmail password: "******"Article '%s' has been updated" % post.title.text) msg = msg.encode(self.vim_encoding) else: post = blog.create_article(html, attrs=attrs) msg = "New article with id %s has been created" % \ post.get_post_id() for item, value in (('id', post.get_post_id()), ('date', post.published.text), ('title', post.title.text), ('modified', post.updated.text), ('tags', ", ".join([cat.term for cat in post.category]))): self._update_docinfo(item, value) return msg