jenkins-bot has submitted this change and it was merged.
Change subject: Require login for two site methods ......................................................................
Require login for two site methods
Also purgepages was recently added as a API 'write' action which asserts it must be performed by a logged in user.
is_uploaddisabled added recently for bug 69090 only works if the user is logged in, otherwise the assert module returns an error before the upload module can respond. Re-raise any API error that is_uploaddisabled is not expecting.
Use test projects to test is_uploaddisabled, as the travis config already has username's for those sites.
Change-Id: I009260c9476852cc8ee818aa791fd15f1dc05ec1 --- M pywikibot/site.py M tests/site_tests.py 2 files changed, 11 insertions(+), 3 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py index 6825a26..bcead58 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -3885,6 +3885,7 @@ return ((unwatch and "unwatched" in watched) or (not unwatch and "watched" in result))
+ @must_be(group='user') def purgepages(self, pages, **kwargs): """Purge the server's cache for one or multiple pages.
@@ -3936,6 +3937,7 @@ def getImagesFromAnHash(self, hash_found=None): return self.getFilesFromAnHash(hash_found)
+ @must_be(group='user') def is_uploaddisabled(self): """Return True if upload is disabled on site.
@@ -3959,8 +3961,14 @@ except api.APIError as error: if error.code == u'uploaddisabled': self._uploaddisabled = True - else: + elif error.code == u'missingparam': + # If the upload module is enabled, the above dummy request + # does not have sufficient parameters and will cause a + # 'missingparam' error. self._uploaddisabled = False + else: + # Unexpected error + raise return self._uploaddisabled
@deprecate_arg('imagepage', 'filepage') diff --git a/tests/site_tests.py b/tests/site_tests.py index 5f72381..f3d8899 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -1184,10 +1184,10 @@ class TestUploadEnabledSite(SiteTestCase):
def test_is_uploaddisabled(self): - site = pywikibot.Site('commons', 'commons') + site = pywikibot.Site('test', 'wikipedia') self.assertFalse(site.is_uploaddisabled())
- site = pywikibot.Site('wikidata', 'wikidata') + site = pywikibot.Site('test', 'wikidata') self.assertTrue(site.is_uploaddisabled())
pywikibot-commits@lists.wikimedia.org