Xqt created this task.
Xqt added projects: Pywikibot, Pywikibot-tests.
Restricted Application added subscribers: pywikibot-bugs-list, Aklapper.

TASK DESCRIPTION
    ______ 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

TASK DETAIL
  https://phabricator.wikimedia.org/T367296

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Xqt
Cc: Aklapper, pywikibot-bugs-list, Xqt, mevo, PotsdamLamb, Jyoo1011, 
JohnsonLee01, SHEKH, Dijkstra, Khutuck, Zkhalido, Aram, Viztor, Wenyi, Tbscho, 
MayS, Mdupont, JJMC89, Dvorapa, Altostratus, binbot, Avicennasis, mys_721tx, 
jayvdb, Masti, Alchimista
_______________________________________________
pywikibot-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to