Page MenuHomePhabricator

Skip tests when the user does not have necessary tokens on the wiki being tested
Closed, ResolvedPublic

Description

The following tests depend on the user having certain token

site_tests.TestSiteTokens.*
site_tests.TestSiteObjectDeprecatedFunctions.test_token
site_tests.SiteUserTestCase2.testPatrol

If the test depends on having a token, the test is non-functional if the test user doesnt have that token, and the test should be marked as skipped.

Event Timeline

jayvdb assigned this task to Omegat.
jayvdb raised the priority of this task from to High.
jayvdb updated the task description. (Show Details)
jayvdb added subscribers: Unknown Object (MLST), jayvdb, XZise, Omegat.

Change 181883 had a related patch set uploaded (by Maverick):
Skip Token tests if user doesn't have rights

https://gerrit.wikimedia.org/r/181883

Patch-For-Review

Change 181883 merged by jenkins-bot:
Skip Token tests if user doesn't have rights

https://gerrit.wikimedia.org/r/181883

This changeset was reverted by xzise in
https://gerrit.wikimedia.org/r/#/c/182168/

As pointed out by xzise, test_token passed for a particular case before merging the change 181883.
https://travis-ci.org/wikimedia/pywikibot-core/jobs/45416313#L801

While test_token was skipped when it was run on the change 181883.
https://travis-ci.org/wikimedia/pywikibot-core/jobs/45420743#L800

This happened so because TokenWallet.__contains__ only returns token value of a cached token. While TokenWallet.__getitem__ requests for the required token (if the token is not available in cache).

More analysis has shown that the patrol token problem on Wikia is that the patrol token doesnt exist on Wikia - i.e. it isnt user-specific; the site havent enabled patrol functionality. That issue is now tracked in T85725.

As patrol is a separate problem, the change for this task should focus only on the edit tokens.

Change 182575 had a related patch set uploaded (by Maverick):
Detect if user doesn't have rights

https://gerrit.wikimedia.org/r/182575

Patch-For-Review

Change 182575 merged by jenkins-bot:
Detect if user doesn't have rights

https://gerrit.wikimedia.org/r/182575

Well you're the author but as I see it this has been resolved.

Still three more
https://travis-ci.org/jayvdb/pywikibot-core/jobs/72051895#L3500

ERROR: testPatrol (tests.site_tests.SiteUserTestCase2)
Test the site.patrol() method.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/jayvdb/pywikibot-core/tests/site_tests.py", line 1551, in testPatrol
    result = list(mysite.patrol(rcid=rc['rcid']))
  File "/home/travis/build/jayvdb/pywikibot-core/pywikibot/site.py", line 4944, in patrol
    token = self.tokens['patrol']
  File "/home/travis/build/jayvdb/pywikibot-core/pywikibot/site.py", line 1590, in __getitem__
    .format(key, self.site.user(), self.site))
Error: Action 'patrol' is not allowed for user JVbot-test on wikia:wikia wiki.

======================================================================
ERROR: test_deprecated_token (tests.site_tests.TestSiteTokens)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/jayvdb/pywikibot-core/tests/site_tests.py", line 1707, in test_deprecated_token
    self.assertEqual(self.mysite.getToken(), self.mysite.tokens['edit'])
  File "/home/travis/build/jayvdb/pywikibot-core/pywikibot/tools/__init__.py", line 1136, in wrapper
    return obj(*args, **kwargs)
  File "/home/travis/build/jayvdb/pywikibot-core/pywikibot/site.py", line 3035, in getToken
    return self.tokens[token]
  File "/home/travis/build/jayvdb/pywikibot-core/pywikibot/site.py", line 1590, in __getitem__
    .format(key, self.site.user(), self.site))
Error: Action 'edit' is not allowed for user JVbot-test on wikia:wikia wiki.

======================================================================
ERROR: test_patrol_tokens_in_mw_116 (tests.site_tests.TestSiteTokens)
Test ability to get patrol token on MW 1.16 wiki.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/jayvdb/pywikibot-core/tests/site_tests.py", line 1681, in test_patrol_tokens_in_mw_116
    self._test_tokens('1.14', '1.16', 'patrol')
  File "/home/travis/build/jayvdb/pywikibot-core/tests/site_tests.py", line 1661, in _test_tokens
    token = self.mysite.tokens[ttype]
  File "/home/travis/build/jayvdb/pywikibot-core/pywikibot/site.py", line 1580, in __getitem__
    self.load_tokens([key], all=False if user_tokens else None)
  File "/home/travis/build/jayvdb/pywikibot-core/pywikibot/site.py", line 1552, in load_tokens
    self.site.get_tokens(types, all=all))
  File "/home/travis/build/jayvdb/pywikibot-core/pywikibot/site.py", line 2964, in get_tokens
    user_tokens['patrol'] = user_tokens['edit']
KeyError: u'edit'

Change 233098 had a related patch set uploaded (by John Vandenberg):
Skip tests when token not available

https://gerrit.wikimedia.org/r/233098

Change 233098 merged by jenkins-bot:
Skip tests when token not available

https://gerrit.wikimedia.org/r/233098