jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1226880?usp=email )
Change subject: tests: Fix ua format string tests for user names
......................................................................
tests: Fix ua format string tests for user names
user_agent_username() was changed to return a username set in
PYWIKIBOT_USERNAME or PWB_USERNAME environment variables
Change-Id: Iac3b748cb4c5ae5345e38fae08a3e3c9301a50af
---
M tests/dry_site_tests.py
M tests/http_tests.py
2 files changed, 14 insertions(+), 10 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/tests/dry_site_tests.py b/tests/dry_site_tests.py
index 589a221..f9f0652 100755
--- a/tests/dry_site_tests.py
+++ b/tests/dry_site_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""Tests against a fake Site object."""
#
-# (C) Pywikibot team, 2012-2022
+# (C) Pywikibot team, 2012-2026
#
# Distributed under the terms of the MIT license.
#
@@ -10,7 +10,7 @@
import unittest
import pywikibot
-from pywikibot.comms.http import user_agent
+from pywikibot.comms.http import user_agent, user_agent_username
from tests.aspects import DefaultDrySiteTestCase
@@ -68,9 +68,9 @@
self.assertEqual(x.family.name,
user_agent(x, format_string='{family}'))
self.assertEqual(x.code,
- user_agent(x, format_string='{lang}'))
+ user_agent(x, format_string='{code}'))
self.assertEqual(x.family.name + ' ' + x.code,
- user_agent(x, format_string='{family} {lang}'))
+ user_agent(x, format_string='{family} {code}'))
self.assertEqual(x.username(),
user_agent(x, format_string='{username}'))
@@ -102,10 +102,13 @@
x._userinfo = {'name': '127.0.0.1'}
x._username = None
- self.assertEqual('Foo', user_agent(x, format_string='Foo {username}'))
- self.assertEqual('Foo (' + x.family.name + ':' + x.code + ')',
- user_agent(x,
- format_string='Foo ({script_comments})'))
+ # user_agent_username() may set ua_username from environment variable
+ ua_username = user_agent_username()
+ self.assertEqual(f'Foo {ua_username}'.strip(),
+ user_agent(x, format_string='Foo {username}'))
+ self.assertEqual(f'Foo ({x})',
+ user_agent(
+ x, format_string='Foo ({script_comments})'))
if __name__ == '__main__':
diff --git a/tests/http_tests.py b/tests/http_tests.py
index 6cccab3..1a7e3bf 100755
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -188,8 +188,9 @@
self.assertEqual('', http.user_agent(format_string=' '))
self.assertEqual('a', http.user_agent(format_string=' a '))
- # if there is no site, these can't have a value
- self.assertEqual('', http.user_agent(format_string='{username}'))
+ # if there is no site, these can't have a value except for username
+ self.assertEqual(http.user_agent_username(),
+ http.user_agent(format_string='{username}'))
self.assertEqual('', http.user_agent(format_string='{family}'))
self.assertEqual('', http.user_agent(format_string='{lang}'))
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1226880?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: Iac3b748cb4c5ae5345e38fae08a3e3c9301a50af
Gerrit-Change-Number: 1226880
Gerrit-PatchSet: 4
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]