summaryrefslogtreecommitdiffstats
path: root/keystone/tests/test_drivers.py
blob: c83c1a8904427c9269c7bdb001918de7d186d99a (plain)
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
import inspect
import unittest2 as unittest

from keystone import assignment
from keystone import catalog
from keystone import exception
from keystone import identity
from keystone import policy
from keystone import token


class TestDrivers(unittest.TestCase):
    """Asserts that drivers are written as expected.

    Public methods on drivers should raise keystone.exception.NotImplemented,
    which renders to the API as a HTTP 501 Not Implemented.

    """

    def assertMethodNotImplemented(self, f):
        """Asserts that a given method raises 501 Not Implemented.

        Provides each argument with a value of None, ignoring optional
        arguments.
        """
        args = inspect.getargspec(f).args
        args.remove('self')
        kwargs = dict(zip(args, [None] * len(args)))
        with self.assertRaises(exception.NotImplemented):
            f(**kwargs)

    def assertInterfaceNotImplemented(self, interface):
        """Public methods on an interface class should not be implemented."""
        for name in dir(interface):
            method = getattr(interface, name)
            if name[0] != '_' and callable(method):
                self.assertMethodNotImplemented(method)

    def test_assignment_driver_unimplemented(self):
        interface = assignment.Driver()
        self.assertInterfaceNotImplemented(interface)

    def test_catalog_driver_unimplemented(self):
        interface = catalog.Driver()
        self.assertInterfaceNotImplemented(interface)

    def test_identity_driver_unimplemented(self):
        interface = identity.Driver()
        self.assertInterfaceNotImplemented(interface)

    def test_policy_driver_unimplemented(self):
        interface = policy.Driver()
        self.assertInterfaceNotImplemented(interface)

    def test_token_driver_unimplemented(self):
        interface = token.Driver()
        self.assertInterfaceNotImplemented(interface)