jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] site_detect_tests: Don't test Gutenberg wiki
......................................................................
[FIX] site_detect_tests: Don't test Gutenberg wiki
The Gutenberg wiki returns 403 errors via Travis as their IP address is
blocked on the wiki. Thus the test won't reliably work.
Bug: T108671
Change-Id: I26141d6a73b594d798892a4ffd2552549b67b089
---
M tests/site_detect_tests.py
1 file changed, 1 insertion(+), 2 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/site_detect_tests.py b/tests/site_detect_tests.py
index 2df7b2e..da18788 100644
--- a/tests/site_detect_tests.py
+++ b/tests/site_detect_tests.py
@@ -112,7 +112,6 @@
self.assertSite('http://wiki.rennkuckuck.de/index.php/$1')
self.assertSite('http://www.proofwiki.org/wiki/$1')
self.assertSite('http://wiki.rennkuckuck.de/index.php/$1')
- self.assertSite('http://www.gutenberg.org/wiki/$1')
self.assertSite(
'http://www.ck-wissen.de/ckwiki/index.php?title=$1')
self.assertSite('http://en.citizendium.org/wiki/$1')
@@ -121,7 +120,7 @@
self.assertSite('http://www.EcoReality.org/wiki/$1')
self.assertSite('http://www.wikichristian.org/index.php?title=$1')
self.assertSite('http://wikitree.org/index.php?title=$1')
- self.assertEqual(self.pass_no, 15)
+ self.assertEqual(self.pass_no, 14)
self.assertEqual(len(self.failures), 0)
self.assertEqual(len(self.errors), 0)
--
To view, visit https://gerrit.wikimedia.org/r/231013
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I26141d6a73b594d798892a4ffd2552549b67b089
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Support wildcard character for config.authenticate
......................................................................
Support wildcard character for config.authenticate
Wildcard character '*' could be used as the prefix of urls in
config.authenticate.
Bug: T108334
Change-Id: Ib426ca834839912c3707c66d41b814ece58be5a1
---
M pywikibot/comms/http.py
M pywikibot/config2.py
M tests/http_tests.py
3 files changed, 63 insertions(+), 2 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..e39aae0 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -241,6 +241,29 @@
return r.content
+def get_authentication(uri):
+ """
+ Retrieve authentication token.
+
+ @param uri: the URI to access
+ @type uri: str
+ @return: authentication token
+ @rtype: None or tuple of two str
+ """
+ parsed_uri = requests.utils.urlparse(uri)
+ netloc_parts = parsed_uri.netloc.split('.')
+ netlocs = [parsed_uri.netloc] + ['.'.join(['*'] + netloc_parts[i + 1:])
+ for i in range(len(netloc_parts))]
+ for path in netlocs:
+ if path in config.authenticate:
+ if len(config.authenticate[path]) == 2:
+ return config.authenticate[path]
+ else:
+ warn('Invalid authentication tokens for %s '
+ 'set in `config.authenticate`' % path)
+ return None
+
+
def _http_process(session, http_request):
method = http_request.method
uri = http_request.uri
@@ -248,7 +271,7 @@
headers = http_request.headers
if PY2 and headers:
headers = dict((key, str(value)) for key, value in headers.items())
- auth = config.authenticate.get(requests.utils.urlparse(uri).netloc, None)
+ auth = get_authentication(uri)
timeout = config.socket_timeout
try:
response = session.request(method, uri, data=body, headers=headers,
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 40a5031..0ef584b 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -151,13 +151,17 @@
# the following form:
#
# authenticate['en.wikipedia.org'] = ('John','XXXXX')
+# authenticate['*.wikipedia.org'] = ('John','XXXXX')
#
# where John is your login name, and XXXXX your password.
# Note:
# 1. This is only for sites that use authentication in the form that gives
# you a popup for name and password when you try to access any data, NOT
# for, for example, wiki usernames
-# 2. You must use the hostname of the site, not its family/language pair
+# 2. You must use the hostname of the site, not its family/language pair.
+# Pywikibot supports wildcard (*) in the prefix of hostname and select the
+# best match authentication. So you can specify authentication not only for
+# one site
authenticate = {}
#
diff --git a/tests/http_tests.py b/tests/http_tests.py
index 8804345..d3d6027 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -71,6 +71,40 @@
self.assertIn('<html lang="mul"', r)
+class TestGetAuthenticationConfig(TestCase):
+
+ """Test http.get_authentication."""
+
+ net = False
+
+ def setUp(self):
+ """Set up test by configuring config.authenticate."""
+ self._authenticate = config.authenticate
+ config.authenticate = {
+ 'zh.wikipedia.beta.wmflabs.org': ('1', '2'),
+ '*.wikipedia.beta.wmflabs.org': ('3', '4'),
+ '*.beta.wmflabs.org': ('5', '6'),
+ '*.wmflabs.org': ('7', '8'),
+ }
+
+ def tearDown(self):
+ """Tear down test by resetting config.authenticate."""
+ config.authenticate = self._authenticate
+
+ def test_url_based_authentication(self):
+ """Test url-based authentication info."""
+ pairs = {
+ 'https://zh.wikipedia.beta.wmflabs.org': ('1', '2'),
+ 'https://en.wikipedia.beta.wmflabs.org': ('3', '4'),
+ 'https://wiki.beta.wmflabs.org': ('5', '6'),
+ 'https://beta.wmflabs.org': ('7', '8'),
+ 'https://wmflabs.org': None,
+ 'https://www.wikiquote.org/': None,
+ }
+ for url, auth in pairs.items():
+ self.assertEqual(http.get_authentication(url), auth)
+
+
class HttpsCertificateTestCase(TestCase):
"""HTTPS certificate test."""
--
To view, visit https://gerrit.wikimedia.org/r/230159
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib426ca834839912c3707c66d41b814ece58be5a1
Gerrit-PatchSet: 7
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: VcamX <vcamx3(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: VcamX <vcamx3(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] tests: add support for hostname check
......................................................................
[IMPROV] tests: add support for hostname check
If no sites are needed but only hostname must be checked it is now possible to
either define one hostname or multiple hostnames and it'll automatically
creates sites from it.
There are already two instances which used a hostname without a site parameter,
which wasn't recognized. And thus they need the net=True explicitly defined.
Change-Id: I4f956c6db6fc4adf62973873759500ec88533423
---
M tests/api_tests.py
M tests/aspects.py
M tests/http_tests.py
3 files changed, 18 insertions(+), 5 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 6119baf..213cf3b 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -835,7 +835,6 @@
it impossible to test two scenarios with the same APISite object.
"""
- net = True
hostname = 'steward.wikimedia.org'
@classmethod
diff --git a/tests/aspects.py b/tests/aspects.py
index 5710e8d..f4016d7 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -685,12 +685,21 @@
# Inherit superclass attributes
for base in bases:
for key in ('pwb', 'net', 'site', 'user', 'sysop', 'write',
- 'sites', 'family', 'code', 'dry',
- 'cached', 'cacheinfo', 'wikibase'):
+ 'sites', 'family', 'code', 'dry', 'hostname',
+ 'hostnames', 'cached', 'cacheinfo', 'wikibase'):
if hasattr(base, key) and key not in dct:
# print('%s has %s; copying to %s'
# % (base.__name__, key, name))
dct[key] = getattr(base, key)
+
+ # Will be inserted into dct[sites] later
+ if 'hostname' in dct:
+ hostnames = [dct['hostname']]
+ del dct['hostname']
+ elif 'hostnames' in dct:
+ hostnames = dct['hostnames']
+ else:
+ hostnames = []
if 'net' in dct and dct['net'] is False:
dct['site'] = False
@@ -713,6 +722,13 @@
}
}
+ if hostnames:
+ if 'sites' not in dct:
+ dct['sites'] = {}
+ for hostname in hostnames:
+ assert hostname not in dct['sites']
+ dct['sites'][hostname] = {'hostname': hostname}
+
if 'dry' in dct and dct['dry'] is True:
dct['net'] = False
diff --git a/tests/http_tests.py b/tests/http_tests.py
index 8804345..cf8e4b4 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -344,8 +344,6 @@
"""Get binary file using requests and pywikibot."""
- net = True
-
hostname = 'upload.wikimedia.org'
url = 'https://upload.wikimedia.org/wikipedia/commons/f/fc/MP_sounds.png'
--
To view, visit https://gerrit.wikimedia.org/r/230925
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4f956c6db6fc4adf62973873759500ec88533423
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] site_detect_tests: Remove duplicate URL
......................................................................
[FIX] site_detect_tests: Remove duplicate URL
The URL `http://www.gutenberg.org/wiki/$1` is tested twice, which is fine for
the tests. But as soon an error or failure occurs it only logs that once which
is confusing as it'll tell that of 16 tests 14 were successful but lists only
one error.
Change-Id: I0de1686255a196816c324307eebe7d216c1eccd1
---
M tests/site_detect_tests.py
1 file changed, 1 insertion(+), 2 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/site_detect_tests.py b/tests/site_detect_tests.py
index a914a3b..2df7b2e 100644
--- a/tests/site_detect_tests.py
+++ b/tests/site_detect_tests.py
@@ -108,7 +108,6 @@
self.assertSite('http://glossary.reuters.com/index.php?title=$1')
self.assertSite('http://www.livepedia.gr/index.php?title=$1')
self.assertSite('http://guildwars.wikia.com/wiki/$1')
- self.assertSite('http://www.gutenberg.org/wiki/$1')
self.assertSite('http://www.hrwiki.org/index.php/$1')
self.assertSite('http://wiki.rennkuckuck.de/index.php/$1')
self.assertSite('http://www.proofwiki.org/wiki/$1')
@@ -122,7 +121,7 @@
self.assertSite('http://www.EcoReality.org/wiki/$1')
self.assertSite('http://www.wikichristian.org/index.php?title=$1')
self.assertSite('http://wikitree.org/index.php?title=$1')
- self.assertEqual(self.pass_no, 16)
+ self.assertEqual(self.pass_no, 15)
self.assertEqual(len(self.failures), 0)
self.assertEqual(len(self.errors), 0)
--
To view, visit https://gerrit.wikimedia.org/r/230748
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0de1686255a196816c324307eebe7d216c1eccd1
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>