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

Change subject: [bugfix] ensure bot is logged in for 
api_tests.TestAPIMWException test
......................................................................

[bugfix] ensure bot is logged in for api_tests.TestAPIMWException test

- tests fails if test account is not logged in. Force to be logged in
  with user attribute
- use a separate test method for all TestAPIMWException tests

Bug: T264096
Change-Id: If5f845382fc7793f37e5ca30e0120b81e9520825
---
M tests/api_tests.py
1 file changed, 13 insertions(+), 18 deletions(-)

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



diff --git a/tests/api_tests.py b/tests/api_tests.py
index 02be034..98684d3 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -35,6 +35,8 @@

     """Test raising an APIMWException."""

+    user = True
+
     data = {'error': {'code': 'internal_api_error_fake',
                       'info': 'Fake error message'},
             'servedby': 'unittest',
@@ -88,17 +90,20 @@
         self.error_patcher.stop()
         super(TestAPIMWException, self).tearDown()

+    def _test_assert_called_with(self, req):
+        self.assertRaises(api.APIMWException, req.submit)
+        pywikibot.warning.assert_called_with(
+            'API error internal_api_error_fake: Fake error message')
+        pywikibot.error.assert_called_with(
+            'Detected MediaWiki API exception internal_api_error_fake: '
+            'Fake error message\n[servedby: unittest]; raising')
+
     def test_API_error(self):
         """Test a static request."""
         req = api.Request(site=self.site, parameters={'action': 'query',
                                                       'fake': True})
         with PatchedHttp(api, self.data):
-            self.assertRaises(api.APIMWException, req.submit)
-            pywikibot.warning.assert_called_with(
-                'API error internal_api_error_fake: Fake error message')
-            pywikibot.error.assert_called_with(
-                'You have no API read permissions. '
-                'Seems you are not logged in.')
+            self._test_assert_called_with(req)

     def test_API_error_encoding_ASCII(self):
         """Test a Page instance as parameter using ASCII chars."""
@@ -108,12 +113,7 @@
                                                       'titles': page})
         self.assert_parameters = {'fake': ''}
         with PatchedHttp(api, self._dummy_request):
-            self.assertRaises(api.APIMWException, req.submit)
-            pywikibot.warning.assert_called_with(
-                'API error internal_api_error_fake: Fake error message')
-            pywikibot.error.assert_called_with(
-                'Detected MediaWiki API exception internal_api_error_fake: '
-                'Fake error message\n[servedby: unittest]; raising')
+            self._test_assert_called_with(req)
 
     def test_API_error_encoding_Unicode(self):
         """Test a Page instance as parameter using non-ASCII chars."""
@@ -123,12 +123,7 @@
                                                       'titles': page})
         self.assert_parameters = {'fake': ''}
         with PatchedHttp(api, self._dummy_request):
-            self.assertRaises(api.APIMWException, req.submit)
-            pywikibot.warning.assert_called_with(
-                'API error internal_api_error_fake: Fake error message')
-            pywikibot.error.assert_called_with(
-                'Detected MediaWiki API exception internal_api_error_fake: '
-                'Fake error message\n[servedby: unittest]; raising')
+            self._test_assert_called_with(req)


 class TestApiFunctions(DefaultSiteTestCase):

-- 
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/631957
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: If5f845382fc7793f37e5ca30e0120b81e9520825
Gerrit-Change-Number: 631957
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to