def test_post_contents(self): """Test retrieval of Flow post contents.""" # Load topic = Topic(self.site, 'Topic:Sh6wgo5tu3qui1w2') post = Post(topic, 'sh6wgoagna97q0ia') # Wikitext wikitext = post.get(format='wikitext') self.assertIn('wikitext', post._content) self.assertNotIn('html', post._content) self.assertIsInstance(wikitext, unicode) self.assertNotEqual(wikitext, '') # HTML html = post.get(format='html') self.assertIn('html', post._content) self.assertIn('wikitext', post._content) self.assertIsInstance(html, unicode) self.assertNotEqual(html, '') # Caching (hit) post._content['html'] = 'something' html = post.get(format='html') self.assertIsInstance(html, unicode) self.assertEqual(html, 'something') self.assertIn('html', post._content) # Caching (reload) post._content['html'] = 'something' html = post.get(format='html', force=True) self.assertIsInstance(html, unicode) self.assertNotEqual(html, 'something') self.assertIn('html', post._content)
def test_post_uuid(self): """Test retrieval of Flow post UUID. This doesn't really "load" anything from the API. It just tests the property to make sure the UUID passed to the constructor is stored properly. """ topic = Topic(self.site, 'Topic:Sh6wgo5tu3qui1w2') post = Post(topic, 'sh6wgoagna97q0ia') self.assertEqual(post.uuid, 'sh6wgoagna97q0ia')
def test_suppress_post(self): """Suppress and restore a test post.""" # Setup topic = Topic(self.site, 'Topic:Sl4svodmrhzmpjjh') post = Post(topic, 'sq1qvoig1az8w7cd') if post.is_moderated: post.restore('Pywikibot test') self.assertFalse(post.is_moderated) # Suppress post.suppress('Pywikibot test') self.assertTrue(post.is_moderated) # Restore post.restore('Pywikibot test') self.assertFalse(post.is_moderated)
def test_reply_to_post(self): """Test replying to an ordinary post.""" # Setup content = 'I am a nested reply to a regular post. Still going strong!' topic = Topic(self.site, self._topic_title) root_post = Post(topic, 'stf5bamzx32rj1gt') old_replies = root_post.replies(force=True)[:] # Reply reply_post = root_post.reply(content, 'wikitext') # Test content wikitext = reply_post.get(format='wikitext') self.assertIn('wikitext', reply_post._content) self.assertNotIn('html', reply_post._content) self.assertIsInstance(wikitext, unicode) self.assertEqual(wikitext, content) # Test reply list in topic new_replies = root_post.replies(force=True) self.assertEqual(len(new_replies), len(old_replies) + 1)
def setUp(self): """Setup tests.""" super().setUp() self.topic = Topic(self.site, 'Topic:Sl4svodmrhzmpjjh') self.post = Post(self.topic, 'sq1qvoig1az8w7cd')