XZise has uploaded a new change for review.

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

Change subject: [IMPROV] http_tests: assert a deprecation
......................................................................

[IMPROV] http_tests: assert a deprecation

The calls to `http.request` without a Site and a URI instead issue a
deprecation warning which we should check for.

Change-Id: I405dac88ba8994791edbec8509d1b6edea78a30c
---
M pywikibot/comms/http.py
M tests/http_tests.py
2 files changed, 23 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/21/230921/1

diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 4b8fcfc..d597446 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -27,7 +27,6 @@
 
 from distutils.version import StrictVersion
 from string import Formatter
-from warnings import warn
 
 import requests
 
@@ -43,7 +42,7 @@
     FatalServerError, Server504Error, Server414Error
 )
 from pywikibot.comms import threadedhttp
-from pywikibot.tools import deprecate_arg, PY2
+from pywikibot.tools import deprecate_arg, issue_deprecation_warning, PY2
 import pywikibot.version
 
 # The error message for failed SSL certificate verification
@@ -219,8 +218,9 @@
     """
     assert(site or uri)
     if not site:
-        warn('Invoking http.request without argument site is deprecated. '
-             'Use http.fetch.', DeprecationWarning, 2)
+        # +1 because of @deprecate_arg
+        issue_deprecation_warning(
+            'Invoking http.request without argument site', 'http.fetch()', 3)
         r = fetch(uri, method, body, headers, **kwargs)
         return r.content
 
diff --git a/tests/http_tests.py b/tests/http_tests.py
index 8804345..550eab1 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -20,7 +20,7 @@
 from pywikibot.comms import http, threadedhttp
 
 from tests import _images_dir
-from tests.aspects import unittest, TestCase
+from tests.aspects import unittest, TestCase, DeprecationTestCase
 from tests.utils import expected_failure_if
 
 if sys.version_info[0] > 2:
@@ -34,9 +34,6 @@
     sites = {
         'www-wp': {
             'hostname': 'www.wikipedia.org',
-        },
-        'www-wq': {
-            'hostname': 'www.wikiquote.org',
         },
     }
 
@@ -58,17 +55,35 @@
         self.assertIsInstance(r.content, unicode)
         self.assertIsInstance(r.raw, bytes)
 
+
+class HttpRequestURI(DeprecationTestCase):
+
+    """Tests using http.request without a site."""
+
+    sites = {
+        'www-wp': {
+            'hostname': 'www.wikipedia.org',
+        },
+        'www-wq': {
+            'hostname': 'www.wikiquote.org',
+        },
+    }
+
     def test_http(self):
         """Test http.request using http://www.wikipedia.org/.""";
         r = http.request(site=None, uri='http://www.wikipedia.org/')
         self.assertIsInstance(r, unicode)
         self.assertIn('<html lang="mul"', r)
+        self.assertOneDeprecationParts(
+            'Invoking http.request without argument site', 'http.fetch()')
 
     def test_https(self):
         """Test http.request using https://www.wikiquote.org/.""";
         r = http.request(site=None, uri='https://www.wikiquote.org/')
         self.assertIsInstance(r, unicode)
         self.assertIn('<html lang="mul"', r)
+        self.assertOneDeprecationParts(
+            'Invoking http.request without argument site', 'http.fetch()')
 
 
 class HttpsCertificateTestCase(TestCase):

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I405dac88ba8994791edbec8509d1b6edea78a30c
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to