jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1305725?usp=email )
Change subject: tests: Fix http_tests
......................................................................
tests: Fix http_tests
- use hostname instead of sites in HttpbinTestCase
- use net attibute instead of sites in HttpTestCase
- remove sites in TestHttpStatus and use the default hostname
Remark: hostname/hostnames and sites with hostnames entries lead to
TestCase inherits from CheckHostnameMixin which checks
whether the hostname is available; otherwise the tests is skipped.
wikia currently blocks requests and returns a 403 status code.
In this case the tests were skipped.
Bug: T430027
Change-Id: Ief5dedceb17f9c3a03b9917bde9a0db7883d5f8b
---
M tests/aspects.py
M tests/http_tests.py
2 files changed, 12 insertions(+), 25 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/tests/aspects.py b/tests/aspects.py
index 234172c..3c23365 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -1731,11 +1731,7 @@
Test cases, which use httpbin, need to inherit this class.
"""
- sites = {
- 'httpbin': {
- 'hostname': 'httpbin.org',
- },
- }
+ hostname = 'httpbin.org'
def get_httpbin_url(self, path=''):
"""Return url of httpbin."""
diff --git a/tests/http_tests.py b/tests/http_tests.py
index f018cce..860e183 100755
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -35,11 +35,7 @@
"""Tests for http module."""
- sites = {
- 'www-wp': {
- 'hostname': 'www.wikipedia.org',
- },
- }
+ net = True
def test_fetch(self) -> None:
"""Test http.fetch using http://www.wikipedia.org/."""
@@ -130,18 +126,6 @@
"""Test HTTP status code handling and errors."""
- sites = {
- 'httpbin': {
- 'hostname': 'httpbin.org',
- },
- 'enwp': {
- 'hostname': 'en.wikipedia.org',
- },
- 'wikia': {
- 'hostname': 'en.wikia.com',
- },
- }
-
def test_http_504(self) -> None:
"""Test that a HTTP 504 raises the correct exception."""
with self.assertRaisesRegex(
@@ -171,13 +155,20 @@
# The following will redirect from ' ' -> '_', and maybe to https://
r = http.fetch('http://en.wikipedia.org/wiki/Main%20Page')
self.assertEqual(r.status_code, HTTPStatus.OK.value)
- self.assertIsNotNone(r.history)
+ self.assertIsNotEmpty(r.history)
+ self.assertEqual(r.history[0].status_code,
+ HTTPStatus.MOVED_PERMANENTLY.value)
self.assertIn('//en.wikipedia.org/wiki/Main_Page', r.url)
- r = http.fetch('http://en.wikia.com')
+ r = http.fetch(
+ self.get_httpbin_url('/redirect-to?url=https://www.wikidata.org'))
+ self.assertIsNotEmpty(r.history)
+ self.assertEqual(r.history[0].status_code, HTTPStatus.FOUND.value)
+ self.assertEqual(r.history[-1].status_code,
+ HTTPStatus.MOVED_PERMANENTLY.value)
self.assertEqual(r.status_code, HTTPStatus.OK.value)
self.assertEqual(r.url,
- 'https://community.fandom.com/wiki/Community_Central')
+ 'https://www.wikidata.org/wiki/Wikidata:Main_Page')
class UserAgentTestCase(DeprecationTestCase):
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1305725?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ief5dedceb17f9c3a03b9917bde9a0db7883d5f8b
Gerrit-Change-Number: 1305725
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]