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

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. 

16 

17"""Stubouts, mocks and fixtures for the test suite.""" 

18 

19from manila import db 

20 

21 

22class FakeModel(object): 

23 """Stubs out for model.""" 

24 def __init__(self, values): 

25 self.values = values 

26 

27 def __getattr__(self, name): 

28 return self.values.get(name) 

29 

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() 

35 

36 def __repr__(self): 

37 return '<FakeModel: %s>' % self.values 

38 

39 def get(self, key, default=None): 

40 return self.__getattr__(key) or default 

41 

42 def __contains__(self, key): 

43 return self._getattr__(key) 

44 

45 def to_dict(self): 

46 return self.values 

47 

48 

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)