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

Change subject: [bugfix] use IntEnum for _loginstatus instead of int value
......................................................................

[bugfix] use IntEnum for _loginstatus instead of int value

Also update dry_api_tests.py

Bug: T263010
Change-Id: I5b8cec2ed5a1dea96998c641b422e538b1aa31b8
---
M pywikibot/data/api.py
M tests/dry_api_tests.py
2 files changed, 18 insertions(+), 16 deletions(-)

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



diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 9bd5791..798ebd2 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -2011,7 +2011,10 @@
                 continue

             # If readapidenied is returned try to login
-            if code == 'readapidenied' and self.site._loginstatus in (-3, -1):
+            if code == 'readapidenied' \
+               and self.site._loginstatus in (
+                   pywikibot.site.LoginStatus.NOT_ATTEMPTED,
+                   pywikibot.site.LoginStatus.NOT_LOGGED_IN):
                 self.site.login()
                 continue

@@ -3032,7 +3035,7 @@
         return self.mapping[key][index]

     @remove_last_args(arg_names=['remember, captchaId, captchaAnswer'])
-    def getCookie(self):
+    def getCookie(self) -> str:
         """Login to the site.

         Note, this doesn't actually return or do anything with cookies.
@@ -3080,7 +3083,7 @@
         if self.site.family.ldapDomain:
             login_request[self.keyword('ldap')] = self.site.family.ldapDomain

-        self.site._loginstatus = -2  # IN_PROGRESS
+        self.site._loginstatus = pywikibot.site.LoginStatus.IN_PROGRESS
         while True:
             # get token using meta=tokens if supported
             if not below_mw_1_27:
diff --git a/tests/dry_api_tests.py b/tests/dry_api_tests.py
index 9e61e60..0aaeba5 100644
--- a/tests/dry_api_tests.py
+++ b/tests/dry_api_tests.py
@@ -5,8 +5,6 @@
 #
 # Distributed under the terms of the MIT license.
 #
-from __future__ import absolute_import, division, unicode_literals
-
 import datetime

 import pywikibot
@@ -17,6 +15,7 @@
     QueryGenerator,
 )
 from pywikibot.family import Family
+from pywikibot.site import LoginStatus
 from pywikibot.tools import suppress_warnings

 from tests import join_images_path, patch
@@ -45,7 +44,7 @@

     def setUp(self):
         """Initialize the fake requests."""
-        super(DryCachedRequestTests, self).setUp()
+        super().setUp()
         self.parms = {'action': 'query',
                       'meta': 'userinfo'}
         self.req = CachedRequest(expiry=1, site=self.basesite,
@@ -147,7 +146,7 @@

         class MockSite(pywikibot.site.APISite):

-            _loginstatus = pywikibot.site.LoginStatus.NOT_ATTEMPTED
+            _loginstatus = LoginStatus.NOT_ATTEMPTED

             _namespaces = {2: ['User']}

@@ -185,7 +184,7 @@
                 raise Exception('Attribute {!r} not defined'.format(attr))

         self.mocksite = MockSite()
-        super(MockCachedRequestKeyTests, self).setUp()
+        super().setUp()

     def test_cachefile_path_different_users(self):
         """Test and compare file paths when different usernames are used."""
@@ -194,26 +193,26 @@
         anonpath = req._cachefile_path()

         self.mocksite._userinfo = {'name': 'MyUser'}
-        self.mocksite._loginstatus = 0
+        self.mocksite._loginstatus = LoginStatus.AS_USER
         req = CachedRequest(expiry=1, site=self.mocksite,
                             parameters={'action': 'query', 'meta': 'siteinfo'})
         userpath = req._cachefile_path()

         self.assertNotEqual(anonpath, userpath)
 
-        self.mocksite._userinfo = {'name': 'MySysop'}
-        self.mocksite._loginstatus = 1
+        self.mocksite._userinfo = {'name': 'MyOtherUser'}
+        self.mocksite._loginstatus = LoginStatus.AS_USER
         req = CachedRequest(expiry=1, site=self.mocksite,
                             parameters={'action': 'query', 'meta': 'siteinfo'})
-        sysoppath = req._cachefile_path()
+        otherpath = req._cachefile_path()

-        self.assertNotEqual(anonpath, sysoppath)
-        self.assertNotEqual(userpath, sysoppath)
+        self.assertNotEqual(anonpath, otherpath)
+        self.assertNotEqual(userpath, otherpath)

     def test_unicode(self):
         """Test caching with Unicode content."""
         self.mocksite._userinfo = {'name': 'محمد الفلسطيني'}
-        self.mocksite._loginstatus = 0
+        self.mocksite._loginstatus = LoginStatus.AS_USER

         req = CachedRequest(expiry=1, site=self.mocksite,
                             parameters={'action': 'query', 'meta': 'siteinfo'})
@@ -385,7 +384,7 @@

     def setUp(self):
         """Add a real ParamInfo to the DrySite."""
-        super(ParamInfoDictTests, self).setUp()
+        super().setUp()
         site = self.get_site()
         site._paraminfo = ParamInfo(site)
         # Pretend that paraminfo has been loaded

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/627779
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: I5b8cec2ed5a1dea96998c641b422e538b1aa31b8
Gerrit-Change-Number: 627779
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: JJMC89 <[email protected]>
Gerrit-Reviewer: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Multichill <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Mpaa <[email protected]>
Gerrit-CC: Russell Blau <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to