jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1354263?usp=email )

Change subject: patrol: Only report successful patrols
......................................................................

patrol: Only report successful patrols

Only log success when site.patrol() returns a result.

Add regression tests for successful and empty patrol responses.

Bug: T439789
Change-Id: I4585ca0d78cd409d167af28ecb8e7903ac1498f1
---
M scripts/patrol.py
M tests/patrolbot_tests.py
2 files changed, 34 insertions(+), 3 deletions(-)

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




diff --git a/scripts/patrol.py b/scripts/patrol.py
index 9939154..6e24a08 100755
--- a/scripts/patrol.py
+++ b/scripts/patrol.py
@@ -321,9 +321,9 @@
         # Patrol the page
         if choice:
             # list() iterates over patrol() which returns a generator
-            list(self.site.patrol(rcid))
-            pywikibot.info(
-                f'Patrolled {title} (rcid {rcid}) by user {username}')
+            if list(self.site.patrol(rcid)):
+                pywikibot.info(
+                    f'Patrolled {title} (rcid {rcid}) by user {username}')
         else:
             verbose_output('Skipped')

diff --git a/tests/patrolbot_tests.py b/tests/patrolbot_tests.py
index 63315d3..13fa1cd 100755
--- a/tests/patrolbot_tests.py
+++ b/tests/patrolbot_tests.py
@@ -9,6 +9,7 @@

 import unittest
 from contextlib import suppress
+from unittest.mock import patch

 from scripts.patrol import PatrolBot
 from tests.aspects import DefaultSiteTestCase
@@ -72,6 +73,36 @@
         self.assertTrue(self.bot.in_list({'', 'Foobar'}, 'Foo'))
         self.assertTrue(self.bot.in_list({'', 'Foo'}, 'Foo'))

+    def _treat_page(self, patrol_result):
+        """Treat a whitelisted page and return the info mock."""
+        page = {
+            'user': 'Test user',
+            'rcid': 1,
+            'title': 'Page 1',
+            'ns': 0,
+        }
+        self.bot.last_rcid = 1
+        self.bot.whitelist = {'Test user': {'Page 1'}}
+
+        with patch.object(
+            self.bot.site, 'patrol', return_value=iter(patrol_result)
+        ) as patrol, patch('pywikibot.info') as info:
+            self.bot.treat(page)
+
+        patrol.assert_called_once_with(1)
+        return info
+
+    def test_treat_reports_successful_patrol(self) -> None:
+        """Test that a successful patrol is reported."""
+        info = self._treat_page([{'rcid': 1}])
+        info.assert_called_once_with(
+            'Patrolled Page 1 (rcid 1) by user Test user')
+
+    def test_treat_does_not_report_disabled_patrol(self) -> None:
+        """Test that a disabled patrol is not reported as successful."""
+        info = self._treat_page([])
+        info.assert_not_called()
+

 if __name__ == '__main__':
     with suppress(SystemExit):

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1354263?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: I4585ca0d78cd409d167af28ecb8e7903ac1498f1
Gerrit-Change-Number: 1354263
Gerrit-PatchSet: 2
Gerrit-Owner: Thiagollipe <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to