jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1057383?usp=email )
Change subject: [flow] remove flow_edit_tests.py and flow_thanks_tests.py ...................................................................... [flow] remove flow_edit_tests.py and flow_thanks_tests.py Flow is disabled on test-wiki, therefore most tests cannot run there. Remove flow_edit_tests.py and flow_thanks_tests.py and move TestFlowEditFailure to flow_tests.py file. Also update flow module documentation. Bug: T371180 Change-Id: I70cf82ccbf9b600a7455903070e69261b57acc04 --- M docs/api_ref/flow.rst M pywikibot/flow.py M tests/__init__.py D tests/flow_edit_tests.py M tests/flow_tests.py D tests/flow_thanks_tests.py 6 files changed, 49 insertions(+), 375 deletions(-) Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified diff --git a/docs/api_ref/flow.rst b/docs/api_ref/flow.rst index adfb422..be9b2a7 100644 --- a/docs/api_ref/flow.rst +++ b/docs/api_ref/flow.rst @@ -1,6 +1,6 @@ -***************************** -:mod:`flow` --- Flow Entities -***************************** +*********************************************** +:mod:`flow` --- Structured Discussions Entities +*********************************************** .. automodule:: flow - :synopsis: Objects representing Flow entities, like boards, topics, and posts + :synopsis: Objects representing Structured Discussions entities, like boards, topics, and posts diff --git a/pywikibot/flow.py b/pywikibot/flow.py index 2d58130..15e7f12 100644 --- a/pywikibot/flow.py +++ b/pywikibot/flow.py @@ -1,4 +1,20 @@ -"""Objects representing Flow entities, like boards, topics, and posts.""" +"""Objects representing Structured Discussions entities. + +Structured Discussions was formerly known as Flow. Flow was renamed in +2017 as the focus was scoped to user-to-user discussions. + +.. versionadded:: 3.0.20170403 +.. caution:: Structured Discussions support previously known as Flow is + no longer tested because the test environment was disabled. Please + use this module with care. +.. deprecated:: 9.4 + Structured Discussions extension is not maintained and will be + removed. Users are encouraged to stop using it. (:phab:`T371180`) +.. seealso:: + - https://www.mediawiki.org/wiki/Structured_Discussions + - https://www.mediawiki.org/wiki/Structured_Discussions/Wikis + - https://www.mediawiki.org/wiki/Extension:StructuredDiscussions +""" # # (C) Pywikibot team, 2015-2024 # @@ -339,14 +355,12 @@ self._reload() -# Flow non-page-like objects class Post: - """A post to a Flow discussion topic.""" + """A post to a Flow discussion topic. This is a non-page-like object.""" def __init__(self, page: Topic, uuid: str) -> None: - """ - Initializer. + """Initializer. :param page: Flow topic :param uuid: UUID of a Flow post diff --git a/tests/__init__.py b/tests/__init__.py index 34944b3..cf3b51c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -85,8 +85,6 @@ 'file', 'fixes', 'flow', - 'flow_edit', - 'flow_thanks', 'gui', 'http', 'i18n', diff --git a/tests/flow_edit_tests.py b/tests/flow_edit_tests.py deleted file mode 100755 index b84ca6c..0000000 --- a/tests/flow_edit_tests.py +++ /dev/null @@ -1,298 +0,0 @@ -#!/usr/bin/env python3 -"""Edit tests for the flow module.""" -# -# (C) Pywikibot team, 2015-2024 -# -# Distributed under the terms of the MIT license. -# -from __future__ import annotations - -import unittest -from contextlib import contextmanager, suppress - -from pywikibot.exceptions import LockedPageError, TimeoutError -from pywikibot.flow import Board, Post, Topic -from tests.aspects import TestCase -from tests.utils import skipping - -MODERATION_REASON = 'Pywikibot test' - - -@unittest.skip('T371112: Structured Discussion was disabled on test-wiki') -class TestFlowCreateTopic(TestCase): - - """Test the creation of Flow topics.""" - - family = 'wikipedia' - code = 'test' - write = True - - def test_create_topic(self): - """Test creation of topic.""" - content = 'If you can read this, the Flow code in Pywikibot works!' - board = Board(self.site, 'Talk:Pywikibot test') - topic = board.new_topic(MODERATION_REASON, content, 'wikitext') - first_post = topic.replies()[0] - wikitext = first_post.get(content_format='wikitext') - self.assertIn('wikitext', first_post._content) - self.assertNotIn('html', first_post._content) - self.assertIsInstance(wikitext, str) - self.assertEqual(wikitext, content) - - def test_summarize_topic(self): - """Test summarize topic we just created.""" - board = Board(self.site, 'Talk:Pywikibot test') - topic = next(board.topics(total=1)) - self.assertIsNone(topic.summary()) - - content = 'That was (and is still) a test' - topic.summarize(content) - self.assertIsInstance(topic.summary(), str) - self.assertEqual(topic.summary(), content) - - content = 'That works' - topic.summarize(content) - self.assertIsInstance(topic.summary(), str) - self.assertEqual(topic.summary(), content) - - -@unittest.skip('T371112: Structured Discussion was disabled on test-wiki') -class TestFlowReply(TestCase): - - """Test replying to existing posts.""" - - family = 'wikipedia' - code = 'test' - write = True - - @classmethod - def setUpClass(cls): - """Set up class.""" - super().setUpClass() - cls._topic_title = 'Topic:Stf56oxx0sd4dkj1' - - 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) - with skipping(TimeoutError): - old_replies = topic.replies(force=True)[:] - # Reply - reply_post = topic.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.replies(force=True) - self.assertLength(new_replies, len(old_replies) + 1) - - 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) - with skipping(TimeoutError): - 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) - - 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') - with skipping(TimeoutError): - old_replies = root_post.replies(force=True)[:] - # Reply - reply_post = root_post.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 = root_post.replies(force=True) - self.assertLength(new_replies, len(old_replies) + 1) - - 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) - with skipping(TimeoutError): - 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(content_format='wikitext') - self.assertIn('wikitext', first_reply_post._content) - self.assertNotIn('html', first_reply_post._content) - self.assertIsInstance(first_wikitext, str) - self.assertEqual(first_wikitext, first_content) - # Test reply list in topic - new_root_replies = topic_root.replies(force=True) - self.assertLength(new_root_replies, len(old_root_replies) + 1) - - # Nested reply - old_nested_replies = first_reply_post.replies(force=True)[:] - self.assertEqual(old_nested_replies, []) - second_reply_post = first_reply_post.reply(second_content, - 'wikitext') - # Test nested reply's content - second_wikitext = second_reply_post.get(content_format='wikitext') - self.assertIn('wikitext', second_reply_post._content) - self.assertNotIn('html', second_reply_post._content) - self.assertIsInstance(second_wikitext, str) - 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.assertLength(new_nested_replies, len(old_nested_replies) + 1) - - # Current test for nested reply list - self.assertEqual(old_nested_replies, []) - more_root_replies = topic_root.replies(force=True) - self.assertLength(more_root_replies, len(new_root_replies) + 1) - - -@unittest.skip('T371112: Structured Discussion was disabled on test-wiki') -class TestFlowLockTopic(TestCase): - - """Locking and unlocking topics.""" - - family = 'wikipedia' - code = 'test' - write = True - - 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) - - -class TestFlowEditFailure(TestCase): - - """Flow-related edit failure tests.""" - - family = 'wikipedia' - code = 'test' - write = True - - 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') - - -class FlowTests(TestCase): - - """Flow tests base class.""" - - family = 'wikipedia' - code = 'test' - write = True - - def setUp(self): - """Setup tests.""" - super().setUp() - self.topic = Topic(self.site, 'Topic:Sl4svodmrhzmpjjh') - self.post = Post(self.topic, 'sq1qvoig1az8w7cd') - - @contextmanager - def restored(self, flow): - """Setup and restore test.""" - # Setup - if flow.is_moderated: - flow.restore(MODERATION_REASON) - self.assertFalse(flow.is_moderated) - try: - yield flow - finally: - # Restore - flow.restore(MODERATION_REASON) - self.assertFalse(flow.is_moderated) - - -@unittest.skip('T371112: Structured Discussion was disabled on test-wiki') -class TestFlowHide(FlowTests): - - """Hiding topics and posts.""" - - def test_hide(self): - """Hide and restore a test topic and post.""" - for flow in (self.topic, self.post): - with self.subTest(flow=flow.__class__.__name__), \ - self.restored(flow): - # Hide - flow.hide(MODERATION_REASON) - self.assertTrue(flow.is_moderated) - - -class TestFlowSysop(FlowTests): - - """Deleting and Suppressing topics and posts.""" - - rights = 'flow-delete,flow-suppress' - - def test_delete(self): - """Delete and restore a test topic and post.""" - for flow in (self.topic, self.post): - with self.subTest(flow=flow.__class__.__name__), \ - self.restored(flow): - # Delete - flow.delete_mod(MODERATION_REASON) - self.assertTrue(flow.is_moderated) - - def test_suppress(self): - """Suppress and restore a test topic and post.""" - for flow in (self.topic, self.post): - with self.subTest(flow=flow.__class__.__name__), \ - self.restored(flow): - # Suppress - flow.suppress(MODERATION_REASON) - self.assertTrue(flow.is_moderated) - - -if __name__ == '__main__': - with suppress(SystemExit): - unittest.main() diff --git a/tests/flow_tests.py b/tests/flow_tests.py index 0d21e3e..56da2aa 100755 --- a/tests/flow_tests.py +++ b/tests/flow_tests.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """Tests for the flow module.""" # -# (C) Pywikibot team, 2015-2023 +# (C) Pywikibot team, 2015-2024 # # Distributed under the terms of the MIT license. # @@ -11,7 +11,7 @@ from contextlib import suppress from pywikibot import config -from pywikibot.exceptions import NoPageError +from pywikibot.exceptions import LockedPageError, NoPageError from pywikibot.flow import Board, Post, Topic from tests.aspects import TestCase from tests.basepage import ( @@ -263,6 +263,30 @@ self.assertTrue(topic_hidden.is_moderated) +class TestFlowEditFailure(TestCase): + + """Flow-related edit failure tests.""" + + family = 'wikipedia' + code = 'test' + write = True + + 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') + + if __name__ == '__main__': with suppress(SystemExit): unittest.main() diff --git a/tests/flow_thanks_tests.py b/tests/flow_thanks_tests.py deleted file mode 100755 index 5f1cced..0000000 --- a/tests/flow_thanks_tests.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env python3 -"""Tests for thanks-related code.""" -# -# (C) Pywikibot team, 2016-2024 -# -# Distributed under the terms of the MIT license. -# -from __future__ import annotations - -import unittest -from contextlib import suppress - -from pywikibot.flow import Topic -from tests.aspects import TestCase - -NO_THANKABLE_POSTS = 'There is no recent post which can be test thanked.' - - -@unittest.skip('T371112: Structured Discussion was disabled on test-wiki') -class TestThankFlowPost(TestCase): - - """Test thanks for Flow posts.""" - - family = 'wikipedia' - code = 'test' - - write = True - - @classmethod - def setUpClass(cls): - """Set up class.""" - super().setUpClass() - cls._topic_title = 'Topic:Tvkityksg1ukyrrw' - - @unittest.expectedFailure # T367308 - def test_thank_post(self): - """Test thanks for Flow posts.""" - 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) - self.assertTrue(bool(next(log_entries, None))) - - 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) - - -if __name__ == '__main__': - with suppress(SystemExit): - unittest.main() -- To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1057383?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Change-Id: I70cf82ccbf9b600a7455903070e69261b57acc04 Gerrit-Change-Number: 1057383 Gerrit-PatchSet: 3 Gerrit-Owner: Xqt <i...@gno.de> Gerrit-Reviewer: Xqt <i...@gno.de> Gerrit-Reviewer: jenkins-bot
_______________________________________________ Pywikibot-commits mailing list -- pywikibot-commits@lists.wikimedia.org To unsubscribe send an email to pywikibot-commits-le...@lists.wikimedia.org