File: test_plugins.py

package info (click to toggle)
custodia 0.6.0-5.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 880 kB
  • sloc: python: 6,074; makefile: 317; sh: 62
file content (61 lines) | stat: -rw-r--r-- 1,996 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Copyright (C) 2016  Custodia Project Contributors - see LICENSE file
from __future__ import absolute_import

import unittest

import pkg_resources

from custodia.client import CustodiaHTTPClient
from custodia.plugin import CSStore, HTTPAuthenticator, HTTPAuthorizer

try:
    # pylint: disable=unused-import
    import ipaclient  # noqa: F401
except ImportError:
    HAS_IPA = False
else:
    HAS_IPA = True


class TestCustodiaPlugins(unittest.TestCase):
    project_name = 'custodia'

    def get_entry_points(self, group):
        eps = []
        for e in pkg_resources.iter_entry_points(group):
            if e.dist.project_name != self.project_name:
                # only interested in our own entry points
                continue
            if not HAS_IPA and e.module_name.startswith('custodia.ipa'):
                # skip IPA plugins when ipaclient isn't installed
                continue
            eps.append(e)
        return eps

    def assert_ep(self, ep, basecls):
        try:
            # backwards compatibility with old setuptools
            if hasattr(ep, "resolve"):
                cls = ep.resolve()
            else:
                cls = ep.load(require=False)
        except Exception as e:  # pylint: disable=broad-except
            self.fail("Failed to load %r: %r" % (ep, e))
        if not issubclass(cls, basecls):
            self.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_clients(self):
        for ep in self.get_entry_points('custodia.clients'):
            self.assert_ep(ep, CustodiaHTTPClient)

    def test_stores(self):
        for ep in self.get_entry_points('custodia.stores'):
            self.assert_ep(ep, CSStore)