Coverage for manila/tests/db/fakes.py: 65%
22 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) 2011 X.commerce, a business unit of eBay Inc.
2# Copyright 2010 OpenStack, LLC
3# All Rights Reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
17"""Stubouts, mocks and fixtures for the test suite."""
19from manila import db
22class FakeModel(object):
23 """Stubs out for model."""
24 def __init__(self, values):
25 self.values = values
27 def __getattr__(self, name):
28 return self.values.get(name)
30 def __getitem__(self, key):
31 if key in self.values: 31 ↛ 34line 31 didn't jump to line 34 because the condition on line 31 was always true
32 return self.values[key]
33 else:
34 raise NotImplementedError()
36 def __repr__(self):
37 return '<FakeModel: %s>' % self.values
39 def get(self, key, default=None):
40 return self.__getattr__(key) or default
42 def __contains__(self, key):
43 return self._getattr__(key)
45 def to_dict(self):
46 return self.values
49def stub_out(stubs, funcs):
50 """Set the stubs in mapping in the db api."""
51 for func in funcs:
52 func_name = '_'.join(func.__name__.split('_')[1:])
53 stubs.Set(db, func_name, func)