jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/939632 )

Change subject: [feat] Implement Flow topic summaries
......................................................................

[feat] Implement Flow topic summaries

Bug: T109443
Change-Id: Icc6d4a040f322cae52d307c747128344a7294cfd
---
M pywikibot/site/_extensions.py
M tests/flow_edit_tests.py
M pywikibot/flow.py
3 files changed, 65 insertions(+), 0 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/pywikibot/flow.py b/pywikibot/flow.py
index 76b090f..ce653ed 100644
--- a/pywikibot/flow.py
+++ b/pywikibot/flow.py
@@ -318,6 +318,23 @@
         self.site.restore_topic(self, reason)
         self._reload()

+    def summary(self) -> Union[str, None]:
+        """Get this topic summary, if any.
+
+        :return: summary or None
+        """
+        if 'summary' in self.root._current_revision.keys():
+            return self.root._current_revision['summary']['revision'][
+                'content']['content']
+
+    def summarize(self, summary: str) -> None:
+        """Summarize this topic.
+
+        :param summary: The summary that will be added to the topic.
+        """
+        self.site.summarize_topic(self, summary)
+        self._reload()
+

 # Flow non-page-like objects
 class Post:
diff --git a/pywikibot/site/_extensions.py b/pywikibot/site/_extensions.py
index f252c5d..b762d87 100644
--- a/pywikibot/site/_extensions.py
+++ b/pywikibot/site/_extensions.py
@@ -546,6 +546,28 @@
         data = req.submit()
         return data['flow']['moderate-topic']['committed']['topic']

+    def summarize_topic(self, page, summary):
+        """
+        Add summary to Flow topic.
+
+        :param page: A Flow topic
+        :type page: Topic
+        :param summary: The text of the summary
+        :type symmary: str
+        :return: Metadata returned by the API
+        :rtype: dict
+        """
+        token = self.tokens['csrf']
+        params = {'action': 'flow', 'page': page, 'token': token,
+                  'submodule': 'edit-topic-summary', 'etssummary': summary,
+                  'etsformat': 'wikitext'}
+        if 'summary' in page.root._current_revision.keys():
+            params['etsprev_revision'] = page.root._current_revision[
+                'summary']['revision']['revisionId']
+        req = self._request(parameters=params, use_get=False)
+        data = req.submit()
+        return data['flow']['edit-topic-summary']['committed']['topicsummary']
+
     @need_right('flow-delete')
     @need_extension('Flow')
     def delete_topic(self, page, reason):
diff --git a/tests/flow_edit_tests.py b/tests/flow_edit_tests.py
index cca627f..51bee7c 100755
--- a/tests/flow_edit_tests.py
+++ b/tests/flow_edit_tests.py
@@ -39,6 +39,22 @@
         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)
+

 class TestFlowReply(TestCase):


--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/939632
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Icc6d4a040f322cae52d307c747128344a7294cfd
Gerrit-Change-Number: 939632
Gerrit-PatchSet: 2
Gerrit-Owner: Framawiki <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to