Example #1
0
 def test_suppress_topic(self):
     """Suppress and restore a test topic."""
     # Setup
     topic = Topic(self.site, 'Topic:Sl4svodmrhzmpjjh')
     if topic.is_moderated:
         topic.restore('Pywikibot test')
     self.assertFalse(topic.is_moderated)
     # Suppress
     topic.suppress('Pywikibot test')
     self.assertTrue(topic.is_moderated)
     # Restore
     topic.restore('Pywikibot test')
     self.assertFalse(topic.is_moderated)
Example #2
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
        self.assertRaises(TypeError, Topic.from_topiclist_data, self.site, '',
                          {})
        self.assertRaises(TypeError, Topic.from_topiclist_data, board, 521, {})
        self.assertRaises(TypeError, Topic.from_topiclist_data, board,
                          'slbktgav46omarsd', [0, 1, 2])
        self.assertRaises(NoPage, Topic.from_topiclist_data, board, 'abc',
                          {'stuff': 'blah'})

        # Post.fromJSON
        self.assertRaises(TypeError, Post.fromJSON, board, 'abc', {})
        self.assertRaises(TypeError, Post.fromJSON, real_topic, 1234, {})
        self.assertRaises(TypeError, Post.fromJSON, real_topic, 'abc', [])
        self.assertRaises(NoPage, Post.fromJSON, fake_topic, 'abc', {
            'posts': [],
            'revisions': []
        })
Example #3
0
 def test_delete_topic(self):
     """Delete and restore a test topic."""
     # Setup
     topic = Topic(self.site, 'Topic:Sl4svodmrhzmpjjh')
     if topic.is_moderated:
         topic.restore('Pywikibot test')
     self.assertFalse(topic.is_moderated)
     # Delete
     topic.delete_mod('Pywikibot test')
     self.assertTrue(topic.is_moderated)
     # Restore
     topic.restore('Pywikibot test')
     self.assertFalse(topic.is_moderated)
Example #4
0
 def test_lock_unlock_topic(self):
     """Lock and unlock a test topic."""
     # Setup
     topic = Topic(self.site, 'Topic:Sn12rdih4iducjsd')
     if topic.is_locked:
         topic.unlock()
     self.assertFalse(topic.is_locked)
     # Lock topic
     topic.lock('Pywikibot test')
     self.assertTrue(topic.is_locked)
     # Unlock topic
     topic.unlock('Pywikibot test')
     self.assertFalse(topic.is_locked)
Example #5
0
 def test_lock_unlock_topic(self):
     """Lock and unlock a test topic."""
     # Setup
     topic = Topic(self.site, 'Topic:Sn12rdih4iducjsd')
     if topic.is_locked:
         topic.unlock(MODERATION_REASON)
     self.assertFalse(topic.is_locked)
     # Lock topic
     topic.lock(MODERATION_REASON)
     self.assertTrue(topic.is_locked)
     # Unlock topic
     topic.unlock(MODERATION_REASON)
     self.assertFalse(topic.is_locked)
Example #6
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)
Example #7
0
 def test_reply_to_locked_topic(self):
     """Test replying to locked topic (should raise exception)."""
     # Setup
     content = 'I am a reply to a locked topic. This is not good!'
     topic = Topic(self.site, 'Topic:Smxnipjfs8umm1wt')
     # Reply (should raise a LockedPageError exception)
     with self.assertRaises(LockedPageError):
         topic.reply(content, 'wikitext')
     topic_root = topic.root
     with self.assertRaises(LockedPageError):
         topic_root.reply(content, 'wikitext')
     topic_reply = topic.root.replies(force=True)[0]
     with self.assertRaises(LockedPageError):
         topic_reply.reply(content, 'wikitext')
Example #8
0
 def test_reply_to_topic(self):
     """Test replying to "topic" (really the topic's root post)."""
     # Setup
     content = 'I am a reply to the topic. Replying works!'
     topic = Topic(self.site, self._topic_title)
     old_replies = topic.replies(force=True)[:]
     # Reply
     reply_post = topic.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 = topic.replies(force=True)
     self.assertEqual(len(new_replies), len(old_replies) + 1)
Example #9
0
 def test_reply_to_topic_root(self):
     """Test replying to the topic's root post directly."""
     # Setup
     content = "I am a reply to the topic's root post. Replying still works!"
     topic = Topic(self.site, 'Topic:Sl4ssgh123c3e1bh')
     topic_root = topic.root
     old_replies = topic_root.replies(force=True)[:]
     # Reply
     reply_post = topic_root.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 = topic_root.replies(force=True)
     self.assertEqual(len(new_replies), len(old_replies) + 1)
Example #10
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)
Example #11
0
    def test_nested_reply(self):
        """Test replying to a previous reply to a topic."""
        # Setup
        first_content = 'I am a reply to the topic with my own replies. Great!'
        second_content = ('I am a nested reply. This conversation is '
                          'getting pretty good!')
        topic = Topic(self.site, self._topic_title)
        topic_root = topic.root
        # First reply
        old_root_replies = topic_root.replies(force=True)[:]
        first_reply_post = topic_root.reply(first_content, 'wikitext')
        # Test first reply's content
        first_wikitext = first_reply_post.get(format='wikitext')
        self.assertIn('wikitext', first_reply_post._content)
        self.assertNotIn('html', first_reply_post._content)
        self.assertIsInstance(first_wikitext, unicode)
        self.assertEqual(first_wikitext, first_content)
        # Test reply list in topic
        new_root_replies = topic_root.replies(force=True)
        self.assertEqual(len(new_root_replies), len(old_root_replies) + 1)

        # Nested reply
        old_nested_replies = first_reply_post.replies(force=True)[:]
        self.assertListEqual(old_nested_replies, [])
        second_reply_post = first_reply_post.reply(second_content,
                                                   'wikitext')
        # Test nested reply's content
        second_wikitext = second_reply_post.get(format='wikitext')
        self.assertIn('wikitext', second_reply_post._content)
        self.assertNotIn('html', second_reply_post._content)
        self.assertIsInstance(second_wikitext, unicode)
        self.assertEqual(second_wikitext, second_content)

        # Test reply list in first reply
        # Broken due to current Flow reply structure (T105438)
        # new_nested_replies = first_reply_post.replies(force=True)
        # self.assertEqual(len(new_nested_replies),
        #                  len(old_nested_replies) + 1)

        # Current test for nested reply list
        self.assertListEqual(old_nested_replies, [])
        more_root_replies = topic_root.replies(force=True)
        self.assertEqual(len(more_root_replies), len(new_root_replies) + 1)
Example #12
0
 def test_reply_to_topic_root(self):
     """Test replying to the topic's root post directly."""
     # Setup
     content = ("I am a reply to the topic's root post. "
                'Replying still works!')
     topic = Topic(self.site, self._topic_title)
     topic_root = topic.root
     old_replies = topic_root.replies(force=True)[:]
     # Reply
     reply_post = topic_root.reply(content, 'wikitext')
     # Test content
     wikitext = reply_post.get(content_format='wikitext')
     self.assertIn('wikitext', reply_post._content)
     self.assertNotIn('html', reply_post._content)
     self.assertIsInstance(wikitext, str)
     self.assertEqual(wikitext, content)
     # Test reply list in topic
     new_replies = topic_root.replies(force=True)
     self.assertLength(new_replies, len(old_replies) + 1)
Example #13
0
 def test_thank_post(self):
     """Test thanks for Flow posts."""
     found_log = False
     site = self.get_site()
     topic = Topic(site, self._topic_title)
     for post in reversed(topic.replies()):
         user = post.creator
         if site.user() == user.username:
             continue
         if user.is_thankable:
             break
     else:
         self.skipTest(NO_THANKABLE_POSTS)
     before_time = site.getcurrenttimestamp()
     post.thank()
     log_entries = site.logevents(logtype='thanks', total=5, page=user,
                                  start=before_time, reverse=True)
     for __ in log_entries:
         found_log = True
         break
     self.assertTrue(found_log)
Example #14
0
 def setUp(self):
     """Set up unit test."""
     self._page = Topic(self.site, 'Topic:Sh6wgo5tu3qui1w2')
     super().setUp()
Example #15
0
 def test_self_thank(self):
     """Test that thanking one's own Flow post causes an error."""
     site = self.get_site()
     topic = Topic(site, self._topic_title)
     my_reply = topic.reply('My attempt to thank myself.')
     self.assertAPIError('invalidrecipient', None, my_reply.thank)
Example #16
0
 def test_topic_uuid(self):
     """Test retrieval of Flow topic UUID."""
     topic = Topic(self.site, 'Topic:Sh6wgo5tu3qui1w2')
     self.assertEqual(topic.uuid, 'sh6wgo5tu3qui1w2')
Example #17
0
 def setUp(self):
     """Set up unit test."""
     self._page = Topic(self.site, 'Topic:Sh6wgo5tu3qui1w2')
     super(TestTopicBasePageMethods, self).setUp()
Example #18
0
 def setUp(self):
     """Setup tests."""
     super().setUp()
     self.topic = Topic(self.site, 'Topic:Sl4svodmrhzmpjjh')
     self.post = Post(self.topic, 'sq1qvoig1az8w7cd')