Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 def test_delete_post(self):
     """Delete 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)
     # Delete
     post.delete('Pywikibot test')
     self.assertTrue(post.is_moderated)
     # Restore
     post.restore('Pywikibot test')
     self.assertFalse(post.is_moderated)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
    def test_illegal_arguments(self):
        """Test illegal method arguments."""
        board = Board(self.site, 'Talk:Pywikibot test')
        real_topic = Topic(self.site, 'Topic:Slbktgav46omarsd')
        fake_topic = Topic(self.site, 'Topic:Abcdefgh12345678')
        # Topic.from_topiclist_data
        with self.assertRaises(TypeError):
            Topic.from_topiclist_data(self.site, '', {})
        with self.assertRaises(TypeError):
            Topic.from_topiclist_data(board, 521, {})
        with self.assertRaises(TypeError):
            Topic.from_topiclist_data(board, 'slbktgav46omarsd', [0, 1, 2])
        with self.assertRaises(NoPage):
            Topic.from_topiclist_data(board, 'abc', {'stuff': 'blah'})

        # Post.fromJSON
        with self.assertRaises(TypeError):
            Post.fromJSON(board, 'abc', {})
        with self.assertRaises(TypeError):
            Post.fromJSON(real_topic, 1234, {})
        with self.assertRaises(TypeError):
            Post.fromJSON(real_topic, 'abc', [])
        with self.assertRaises(NoPage):
            Post.fromJSON(fake_topic, 'abc', {'posts': [], 'revisions': []})
Exemplo n.º 6
0
 def setUp(self):
     """Setup tests."""
     super().setUp()
     self.topic = Topic(self.site, 'Topic:Sl4svodmrhzmpjjh')
     self.post = Post(self.topic, 'sq1qvoig1az8w7cd')