jenkins-bot has submitted this change and it was merged.
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(+), 7 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py index 4b8fcfc..8e34670 100644 --- a/pywikibot/comms/http.py +++ b/pywikibot/comms/http.py @@ -43,7 +43,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 +219,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):
pywikibot-commits@lists.wikimedia.org