XZise has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/217433

Change subject: [FIX] logentry tests: Only work on actual block
......................................................................

[FIX] logentry tests: Only work on actual block

The unblock log entries aren't really special so these checks in the tests
don't apply for those. It'll also iterate over multiple (up to 5) entries to
find one block log entry.

Bug: T101976
Change-Id: I04c751e32130461aa950f92758a178947225a835
---
M pywikibot/logentries.py
M tests/logentry_tests.py
2 files changed, 20 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/33/217433/1

diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py
index a639628..bc99909 100644
--- a/pywikibot/logentries.py
+++ b/pywikibot/logentries.py
@@ -116,7 +116,12 @@
 
 class BlockEntry(LogEntry):
 
-    """Block log entry."""
+    """
+    Block or unblock log entry.
+
+    It might contain a block or unblock depending on the action. The duration,
+    expiry and flags are not available on unblock log entries.
+    """
 
     _expectedType = 'block'
 
diff --git a/tests/logentry_tests.py b/tests/logentry_tests.py
index 2326ebd..17bc02e 100644
--- a/tests/logentry_tests.py
+++ b/tests/logentry_tests.py
@@ -115,14 +115,20 @@
 
     def test_BlockEntry(self, key):
         """Test BlockEntry methods."""
-        logentry = self._get_logentry('block')
-        if logentry.action() == 'block':
-            self.assertIsInstance(logentry.flags(), list)
-            # Check that there are no empty strings
-            self.assertTrue(all(logentry.flags()))
-        if logentry.expiry() is not None:
-            self.assertIsInstance(logentry.expiry(), pywikibot.Timestamp)
-            self.assertIsInstance(logentry.duration(), datetime.timedelta)
+        # only 'block' entries can be tested
+        for logentry in self.site.logevents(logtype='block', total=5):
+            if logentry.action() == 'block':
+                self.assertIsInstance(logentry.flags(), list)
+                # Check that there are no empty strings
+                self.assertTrue(all(logentry.flags()))
+                if logentry.expiry() is not None:
+                    self.assertIsInstance(logentry.expiry(), 
pywikibot.Timestamp)
+                    self.assertIsInstance(logentry.duration(), 
datetime.timedelta)
+                    self.assertEqual(logentry.timestamp() + 
logentry.duration(),
+                                     logentry.expiry())
+                else:
+                    self.assertIsNone(logentry.duration())
+                break
 
     def test_RightsEntry(self, key):
         """Test RightsEntry methods."""

-- 
To view, visit https://gerrit.wikimedia.org/r/217433
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I04c751e32130461aa950f92758a178947225a835
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <commodorefabia...@gmx.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to