[tests/results] implement more specific '#auth' checks

This commit is contained in:
Mike Fährmann
2025-12-23 22:17:33 +01:00
parent 9c50c10f1a
commit 57c2327ae3

View File

@@ -56,14 +56,14 @@ AUTH_REQUIRED = {
"poipiku", "poipiku",
} }
AUTH_KEYS = ( AUTH_KEYS = {
"username", "username",
"cookies", "cookies",
"api-key", "api-key",
"client-id", "client-id",
"access-token", "access-token",
"refresh-token", "refresh-token",
) }
class TestExtractorResults(unittest.TestCase): class TestExtractorResults(unittest.TestCase):
@@ -145,7 +145,7 @@ class TestExtractorResults(unittest.TestCase):
for key in AUTH_KEYS: for key in AUTH_KEYS:
config.set((), key, None) config.set((), key, None)
if auth and not any(extr.config(key) for key in AUTH_KEYS): if auth and not self._has_auth(extr, auth):
self._skipped.append((result["#url"], "no auth")) self._skipped.append((result["#url"], "no auth"))
self.skipTest("no auth") self.skipTest("no auth")
@@ -271,6 +271,19 @@ class TestExtractorResults(unittest.TestCase):
for kwdict in kwdicts: for kwdict in kwdicts:
self._test_kwdict(kwdict, metadata) self._test_kwdict(kwdict, metadata)
def _has_auth(self, extr, auth):
if auth is True:
auth = AUTH_KEYS
if isinstance(auth, str):
return extr.config(auth)
if isinstance(auth, set):
return any(self._has_auth(extr, a) for a in auth)
if isinstance(auth, (tuple, list)):
return all(self._has_auth(extr, k) for k in auth)
self.fail(f"Invalid '#auth' value: {auth!r}")
def _test_kwdict(self, kwdict, tests, parent=None): def _test_kwdict(self, kwdict, tests, parent=None):
for key, test in tests.items(): for key, test in tests.items():