jenkins-bot has submitted this change and it was merged.
Change subject: Implement OAuthEditTest ......................................................................
Implement OAuthEditTest
OAuthEditTest will login, edit a userpage and confirm the edit was done using OAuth.
Bug: T109061 Change-Id: I1344b4496af9a9ebfb698ebb7e864c61e4833750 --- M tests/aspects.py M tests/edit_tests.py M tests/oauth_tests.py 3 files changed, 51 insertions(+), 4 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/aspects.py b/tests/aspects.py index f4016d7..994a3de 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -685,7 +685,7 @@ # Inherit superclass attributes for base in bases: for key in ('pwb', 'net', 'site', 'user', 'sysop', 'write', - 'sites', 'family', 'code', 'dry', 'hostname', + 'sites', 'family', 'code', 'dry', 'hostname', 'oauth', 'hostnames', 'cached', 'cacheinfo', 'wikibase'): if hasattr(base, key) and key not in dct: # print('%s has %s; copying to %s' @@ -783,7 +783,7 @@ bases = tuple([CheckHostnameMixin] + list(bases))
if 'write' in dct and dct['write']: - if 'user' not in dct: + if 'user' not in dct and 'oauth' not in dct: dct['user'] = True bases = tuple([SiteWriteMixin] + list(bases))
diff --git a/tests/edit_tests.py b/tests/edit_tests.py index db5cfee..0e9ce7e 100644 --- a/tests/edit_tests.py +++ b/tests/edit_tests.py @@ -15,8 +15,10 @@ import pywikibot
from pywikibot import page_put_queue +from pywikibot import config
from tests.aspects import unittest, TestCase +from tests.oauth_tests import OAuthSiteTestCase
called_back = False
@@ -71,6 +73,43 @@ self.assertTrue(p.text.endswith(ts)) self.assertTrue(p.text != ts)
+ +class OAuthEditTest(OAuthSiteTestCase): + + """Run edit test with OAuth enabled.""" + + family = 'wikipedia' + code = 'test' + + write = True + oauth = True + + def setUp(self): + """Set up test by checking site and initialization.""" + super(OAuthEditTest, self).setUp() + self._authenticate = config.authenticate + oauth_tokens = self.consumer_token + self.access_token + config.authenticate[self.site.hostname()] = oauth_tokens + + def tearDown(self): + """Tear down test by resetting config.authenticate.""" + config.authenticate = self._authenticate + + def test_edit(self): + """Test editing to a page.""" + self.site.login() + self.assertTrue(self.site.logged_in()) + ts = str(time.time()) + p = pywikibot.Page(self.site, + 'User:%s/edit test' % self.site.username()) + p.site.editpage(p, appendtext=ts) + revision_id = p.latest_revision_id + p = pywikibot.Page(self.site, + 'User:%s/edit test' % self.site.username()) + self.assertEqual(revision_id, p.latest_revision_id) + self.assertTrue(p.text.endswith(ts)) + + if __name__ == '__main__': try: unittest.main() diff --git a/tests/oauth_tests.py b/tests/oauth_tests.py index 111c0d8..8a7955e 100644 --- a/tests/oauth_tests.py +++ b/tests/oauth_tests.py @@ -19,11 +19,12 @@ from pywikibot.login import OauthLoginManager from tests.aspects import ( unittest, + TestCase, DefaultSiteTestCase, )
-class OAuthSiteTestCase(DefaultSiteTestCase): +class OAuthSiteTestCase(TestCase):
"""Run tests related to OAuth authentication."""
@@ -55,7 +56,14 @@ self.access_token = tokens[2:]
-class TestOauthLoginManger(OAuthSiteTestCase): +class DefaultOAuthSiteTestCase(DefaultSiteTestCase, OAuthSiteTestCase): + + """Default OAuth site test.""" + + pass + + +class TestOauthLoginManger(DefaultOAuthSiteTestCase):
"""Test OAuth login manager."""
pywikibot-commits@lists.wikimedia.org