______ TestSiteSysopWrite.test_protect_exception (test='anInvalidLevel') _______ self = <tests.site_tests.TestSiteSysopWrite testMethod=test_protect_exception> def test_protect_exception(self): """Test that site.protect() throws an exception for invalid args.""" site = self.get_site() page = pywikibot.Page(site, 'User:Unicodesnowman/ProtectTest') with self.subTest(test='anInvalidType'), \ self.assertRaisesRegex(APIError, 'Invalid protection type "anInvalidType"'): site.protect(protections={'anInvalidType': 'sysop'}, page=page, reason='Pywikibot unit test') with self.subTest(test='anInvalidLevel'), \ self.assertRaises(AssertionError): site.protect(protections={'edit': 'anInvalidLevel'}, > page=page, reason='Pywikibot unit test') tests/site_tests.py:635: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ pywikibot/site/_decorators.py:93: in callee return fn(self, *args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @need_right('protect') def protect( self, page: BasePage, protections: dict[str, str | None], reason: str, expiry: datetime.datetime | str | None = None, **kwargs: Any ) -> None: """(Un)protect a wiki page. Requires *protect* right. .. seealso:: - :meth:`page.BasePage.protect` - :meth:`protection_types` - :meth:`protection_levels` - :api:`Protect` :param protections: A dict mapping type of protection to protection level of that type. Refer :meth:`protection_types` for valid restriction types and :meth:`protection_levels` for valid restriction levels. If None is given, however, that protection will be skipped. :param reason: Reason for the action :param expiry: When the block should expire. This expiry will be applied to all protections. If ``None``, ``'infinite'``, ``'indefinite'``, ``'never'``, or ``''`` is given, there is no expiry. """ token = self.tokens['csrf'] self.lock_page(page) protections_list = [ptype + '=' + level for ptype, level in protections.items() if level is not None] parameters = merge_unique_dicts( kwargs, action='protect', title=page, token=token, protections=protections_list, reason=reason, expiry=expiry or None, # pass None instead of empty str ) req = self.simple_request(**parameters) try: result = req.submit() except APIError as err: errdata = { 'site': self, 'user': self.user(), } if err.code in self._protect_errors: raise Error( self._protect_errors[err.code].format_map(errdata) > ) from None E pywikibot.exceptions.Error: Invalid protection level pywikibot/site/_apisite.py:2806: Error
Description
Description
Details
Details
Subject | Repo | Branch | Lines +/- | |
---|---|---|---|---|
[tests] fix invalid level test in TestSiteSysopWrite.test_protect_exception() | pywikibot/core | master | +2 -1 |
Status | Subtype | Assigned | Task | ||
---|---|---|---|---|---|
Open | None | T152961 Improve tests suite | |||
Open | None | T129368 Usages of unittest.expectedFailure or unittest.skip should be solved (goal) | |||
Open | None | T367260 Write test CI github action has ~ 22 failing tests or errors | |||
Resolved | Xqt | T367296 TestSiteSysopWrite.test_protect_exception() of site_tests fails with Error |
Event Timeline
Comment Actions
Change #1042246 had a related patch set uploaded (by Xqt; author: Xqt):
[pywikibot/core@master] [tests] fix invalid level test in TestSiteSysopWrite.test_protect_exception()
Comment Actions
Change #1042246 merged by jenkins-bot:
[pywikibot/core@master] [tests] fix invalid level test in TestSiteSysopWrite.test_protect_exception()