Files
freeipa/ipatests/test_custodia/test_plugins.py
T
Miro Hrončok ac791f7372 Stop using deprecated pkg_resources
Use packaging.version and importlib.metadata instead.

Note that packaging.version only parses versions compatible with Python packaging
(originally defined in PEP 440).
https://packaging.python.org/en/latest/specifications/version-specifiers/

Fixes https://pagure.io/freeipa/issue/9676

Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
2025-05-06 13:48:35 +02:00

42 lines
1.3 KiB
Python

# Copyright (C) 2016 Custodia Project Contributors - see LICENSE file
import importlib.metadata
import pytest
from ipaserver.custodia.plugin import (
CSStore, HTTPAuthenticator, HTTPAuthorizer
)
class TestCustodiaPlugins:
project_name = 'ipaserver.custodia'
def get_entry_points(self, group):
eps = []
for e in importlib.metadata.entry_points(group=group):
if e.dist.name != self.project_name:
# only interested in our own entry points
continue
eps.append(e)
return eps
def assert_ep(self, ep, basecls):
try:
cls = ep.load(require=False)
except Exception as e: # pylint: disable=broad-except
pytest.fail("Failed to load %r: %r" % (ep, e))
if not issubclass(cls, basecls):
pytest.fail("%r is not a subclass of %r" % (cls, basecls))
def test_authenticators(self):
for ep in self.get_entry_points('custodia.authenticators'):
self.assert_ep(ep, HTTPAuthenticator)
def test_authorizers(self):
for ep in self.get_entry_points('custodia.authorizers'):
self.assert_ep(ep, HTTPAuthorizer)
def test_stores(self):
for ep in self.get_entry_points('custodia.stores'):
self.assert_ep(ep, CSStore)