Unicodesnowman has uploaded a new change for review.

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

Change subject: Add unit tests for Site.protect() and Page.protect()
......................................................................

Add unit tests for Site.protect() and Page.protect()

This patch adds unit tests for protecting / unprotecting a page.
A bug, T78522 ( https://phabricator.wikimedia.org/T78522 ) was
encountered, causing the tests to fail right now. The tests pass
successfully if the bug is worked around by only protecting
a page once per execution.

I've (hopefully) marked the tests as disabled by default due to
that bug.

You'll need sysop rights on test.wikipedia.org in order to run
the tests.

Bug: T59602
Change-Id: I8c0c91651b1c0083161d0e7c1d4cbf6ad144c669
---
M tests/page_tests.py
M tests/site_tests.py
2 files changed, 66 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/78/179878/1

diff --git a/tests/page_tests.py b/tests/page_tests.py
index 84338e2..b354596 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -593,6 +593,44 @@
         self.assertIsInstance(rv, bool)
         self.assertTrue(rv)
 
+class TestPageProtect(TestCase):
+
+    """Test page protect / unprotect actions."""
+
+    family = 'test'
+    code = 'test'
+
+    user = True
+    sysop = True
+
+    def test_applicable_protections(self):
+        """Test Page.applicable_protections."""
+        site = self.get_site()
+        p1 = pywikibot.Page(site, u'User:Unicodesnowman/NonexistentPage')
+        p2 = pywikibot.Page(site, u'User:Unicodesnowman/ProtectTest')
+        p3 = pywikibot.Page(site, u'File:Wiki.png')
+
+        self.assertEqual(p1.applicable_protections(), set(['create']))
+        self.assertIn('edit', p2.applicable_protections())
+        self.assertNotIn('create', p2.applicable_protections())
+        self.assertNotIn('upload', p2.applicable_protections())
+        self.assertIn('upload', p3.applicable_protections())
+
+    @unittest.expectedFailure
+    def test_protect(self):
+        """Test Page.protect."""
+        site = self.get_site()
+        p1 = pywikibot.Page(site, u'User:Unicodesnowman/ProtectTest')
+
+        p1.protect(protections=dict(edit='sysop', move='autoconfirmed'),
+                  reason=u'Pywikibot unit test')
+        self.assertEqual(p1.protection(),
+                         dict([(u'edit', (u'sysop', u'infinity')),
+                               (u'move', (u'autoconfirmed', u'infinity'))]))
+
+        p1.protect(protections=dict(edit='', move=''),
+                  reason=u'Pywikibot unit test')
+        self.assertEqual(p1.protection(), dict())
 
 if __name__ == '__main__':
     try:
diff --git a/tests/site_tests.py b/tests/site_tests.py
index e7438e6..867e012 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -1137,6 +1137,34 @@
                           end="2008-09-03T00:00:01Z", reverse=True,
                           total=5)
 
+    @unittest.expectedFailure
+    def test_protect(self):
+        """Test the site.protect() method."""
+        site = self.get_site()
+        p1 = pywikibot.Page(site, u'User:Unicodesnowman/ProtectTest')
+
+        site.protect(protections=dict(edit='sysop', move='autoconfirmed'),
+                     page=p1,
+                     reason='Pywikibot unit test')
+        self.assertEqual(site.page_restrictions(page=p1),
+                         dict([(u'edit', (u'sysop', u'infinity')),
+                               (u'move', (u'autoconfirmed', u'infinity'))]))
+
+        expiry = pywikibot.Timestamp.fromISOformat('2050-01-01T00:00:00Z')
+        site.protect(protections=dict(edit='sysop', move='autoconfirmed'),
+                     page=p1,
+                     expiry=expiry,
+                     reason='Pywikibot unit test')
+
+        self.assertEqual(site.page_restrictions(page=p1),
+                         dict([(u'edit', (u'sysop', u'2050-01-01T00:00:00Z')),
+                               (u'move', (u'autoconfirmed', 
u'2050-01-01T00:00:00Z'))]))
+
+        site.protect(protections=dict(edit='', move=''),
+                     page=p1,
+                     reason='Pywikibot unit test')
+        self.assertEqual(site.page_restrictions(page=p1), dict())
+
 
 class SiteUserTestCase2(DefaultSiteTestCase):
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8c0c91651b1c0083161d0e7c1d4cbf6ad144c669
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Unicodesnowman <ad...@glados.cc>

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

Reply via email to