Page MenuHomePhabricator

file_tests.TestMediaInfoReadonlyEditing: fails on NoUsernameError
Closed, ResolvedPublicBUG REPORT

Description

class TestMediaInfoReadonlyEditing(TestCase):
    """Test writing structured data of FilePage."""

    # Create valid API requests which will fail to missing permission.

    # commons.wikimedia.beta.wmflabs.org
    family = 'commons'
    code = 'beta'

fails with:

Traceback (most recent call last):
  File "/src/pywikibot/login.py", line 102, in __init__
    user = code_to_usr.get(site.code) or code_to_usr['*']
KeyError: '*'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/src/tests/file_tests.py", line 533, in test_edit_claims
    item.addClaim(new_claim)
  File "/src/pywikibot/page/_wikibase.py", line 533, in addClaim
    self.repo.addClaim(self, claim, bot=bot, **kwargs)
  File "/src/pywikibot/site/_decorators.py", line 86, in callee
    return fn(self, *args, **kwargs)
  File "/src/pywikibot/site/_datasite.py", line 344, in addClaim
    'token': self.tokens['csrf'],
  File "/src/pywikibot/site/_tokenwallet.py", line 39, in __getitem__
    self.site.login()
  File "/src/pywikibot/site/_apisite.py", line 432, in login
    user=self.username())
  File "/src/pywikibot/login.py", line 110, in __init__
    "'myUsername'".format(site=site))
pywikibot.exceptions.NoUsernameError: ERROR: username for commons:beta is undefined.
If you have a username for that site, please add a line to user config file (user_config.py) as follows:
usernames['commons']['beta'] = 'myUsername'

We should put that usernames['commons']['beta'] = 'myUsername' somewhere.
It's weird it suddenly stopped working. It could be some upstream change in login management.

Event Timeline

Two methods ar failing: test_edit_claims and test_edit_label.

Tests were introduced with rPWBC2715217e with 8.5.0 but 8.5.0 also fails.

Xqt renamed this task from Experimental build fails on NoUsernameError to file_tests.TestMediaInfoReadonlyEditing: fails on NoUsernameError.Jan 27 2024, 3:38 PM
Xqt added a subscriber: Zache.

The problem is that anonymous users got edit rights on beta:commons and the tests as no longer raises UserRightsError.

@Zache: can we change the tests somehow?

Change 993230 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [tests] expect TestMediaInfoReadonlyEditing to fail

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

Xqt removed Xqt as the assignee of this task.Jan 27 2024, 5:09 PM

I've added the unittest.expectedFailure decorator until the tests was updated due to the new rights for anonymous users.

Change 993230 merged by jenkins-bot:

[pywikibot/core@master] [tests] expect TestMediaInfoReadonlyEditing to fail

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

Xqt lowered the priority of this task from High to Medium.Jan 27 2024, 6:00 PM

My test was just to test that everything in client side code works without need to setting up accounts etc.

One solution could be just to protect the file https://commons.wikimedia.beta.wmflabs.org/wiki/File:123_4.jpg so the server would again return permission denied error and add to the image description that image is protected because it is used by pywikibot tests. (link to the phab ticket)

Another solution could be to extend the test so that it would actually do the writing and test if it works correctly.

Change 1004301 had a related patch set uploaded (by Zache-tool; author: Zache-tool):

[pywikibot/core@master] Update MediaInfo editing tests

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

Note, i do not know how this should be done.

We should put that usernames['commons']['beta'] = 'myUsername' somewhere.
It's weird it suddenly stopped working. It could be some upstream change in login management.

Change 1004301 merged by jenkins-bot:

[pywikibot/core@master] Update MediaInfo editing tests

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