Coverage for manila/tests/db/test_api.py: 100%
16 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright (c) Goutham Pacha Ravi.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15"""Unit Tests for the interface methods in the manila/db/api.py."""
17import re
19from manila.db import api as db_interface
20from manila.db.sqlalchemy import api as db_api
21from manila import test
24class DBInterfaceTestCase(test.TestCase):
25 """Test cases for the DB Interface methods."""
27 def test_interface_methods(self):
28 """Ensure that implementation methods match interfaces.
30 manila/db/api module is merely shim layer between the database
31 implementation and the other methods using these implementations.
32 Bugs are introduced when the shims go out of sync with the actual
33 implementation. So this test ensures that method names and
34 signatures match between the interface and the implementation.
35 """
36 members = dir(db_interface)
37 # Ignore private methods for the file and any other members that
38 # need not match.
39 ignore_members = re.compile(r'^_|CONF|IMPL')
40 interfaces = [i for i in members if not ignore_members.match(i)]
41 for interface in interfaces:
42 method = getattr(db_interface, interface)
43 if callable(method):
44 mock_method_call = self.mock_object(db_api, interface)
45 # kwargs always specify defaults, ignore them in the signature.
46 args = filter(
47 lambda x: x != 'kwargs', method.__code__.co_varnames)
49 method(*args)
51 self.assertTrue(mock_method_call.called)