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)
 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)
 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)
 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 #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(NoPageError):
            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(NoPageError):
            Post.fromJSON(fake_topic, 'abc', {'posts': [], 'revisions': []})
 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 #7
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 #8
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(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 #9
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 #10
0
class TestTopicBasePageMethods(BasePageMethodsTestBase):
    """Test Flow topic pages using BasePage-defined methods."""

    family = 'mediawiki'
    code = 'mediawiki'

    def setUp(self):
        """Set up unit test."""
        self._page = Topic(self.site, 'Topic:Sh6wgo5tu3qui1w2')
        super(TestTopicBasePageMethods, self).setUp()

    def test_basepage_methods(self):
        """Test basic Page methods on a Flow topic page."""
        self._test_invoke()
        self._test_return_datatypes()
        self.assertFalse(self._page.isRedirectPage())
        self.assertEqual(self._page.latest_revision.parent_id, 0)

    def test_content_model(self):
        """Test Flow topic page content model."""
        self.assertEqual(self._page.content_model, 'flow-board')
class TestTopicBasePageMethods(BasePageMethodsTestBase):

    """Test Flow topic pages using BasePage-defined methods."""

    family = 'mediawiki'
    code = 'mediawiki'

    def setUp(self):
        """Set up unit test."""
        self._page = Topic(self.site, 'Topic:Sh6wgo5tu3qui1w2')
        super(TestTopicBasePageMethods, self).setUp()

    def test_basepage_methods(self):
        """Test basic Page methods on a Flow topic page."""
        self._test_invoke()
        self._test_return_datatypes()
        self.assertFalse(self._page.isRedirectPage())
        self.assertEqual(self._page.latest_revision.parent_id, 0)

    def test_content_model(self):
        """Test Flow topic page content model."""
        self.assertEqual(self._page.content_model, 'flow-board')
Example #12
0
 def setUp(self):
     """Set up unit test."""
     self._page = Topic(self.site, 'Topic:Sh6wgo5tu3qui1w2')
     super(TestTopicBasePageMethods, self).setUp()
Example #13
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)
 def setUp(self):
     """Set up unit test."""
     self._page = Topic(self.site, 'Topic:Sh6wgo5tu3qui1w2')
     super(TestTopicBasePageMethods, self).setUp()
Example #15
0
 def setUp(self):
     """Set up unit test."""
     self._page = Topic(self.site, 'Topic:Sh6wgo5tu3qui1w2')
     super().setUp()
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):
     """Setup tests."""
     super().setUp()
     self.topic = Topic(self.site, 'Topic:Sl4svodmrhzmpjjh')
     self.post = Post(self.topic, 'sq1qvoig1az8w7cd')