Coverage for manila/tests/message/test_message_field.py: 100%

31 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# Licensed under the Apache License, Version 2.0 (the "License"); you may 

2# not use this file except in compliance with the License. You may obtain 

3# a copy of the License at 

4# 

5# http://www.apache.org/licenses/LICENSE-2.0 

6# 

7# Unless required by applicable law or agreed to in writing, software 

8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

10# License for the specific language governing permissions and limitations 

11# under the License. 

12import ddt 

13from oslo_config import cfg 

14 

15from manila import exception 

16from manila.message import message_field 

17from manila import test 

18 

19CONF = cfg.CONF 

20 

21 

22@ddt.ddt 

23class MessageFieldTest(test.TestCase): 

24 

25 @ddt.data(message_field.Action, message_field.Detail) 

26 def test_unique_ids(self, cls): 

27 """Assert that no action or detail id is duplicated.""" 

28 ids = [name[0] for name in cls.ALL] 

29 self.assertEqual(len(ids), len(set(ids))) 

30 

31 @ddt.data({'id': '001', 'content': 'allocate host'}, 

32 {'id': 'invalid', 'content': None}) 

33 @ddt.unpack 

34 def test_translate_action(self, id, content): 

35 result = message_field.translate_action(id) 

36 if content is None: 

37 content = 'unknown action' 

38 self.assertEqual(content, result) 

39 

40 @ddt.data({'id': '001', 

41 'content': 'An unknown error occurred.'}, 

42 {'id': '002', 

43 'content': 'No storage could be allocated for this share ' 

44 'request. Trying again with a different size or ' 

45 'share type may succeed.'}, 

46 {'id': 'invalid', 'content': None}) 

47 @ddt.unpack 

48 def test_translate_detail(self, id, content): 

49 result = message_field.translate_detail(id) 

50 if content is None: 

51 content = 'An unknown error occurred.' 

52 self.assertEqual(content, result) 

53 

54 @ddt.data({'exception': exception.NoValidHost(reason='fake reason'), 

55 'detail': '', 'expected': '002'}, 

56 {'exception': exception.NoValidHost( 

57 detail_data={'last_filter': 'CapacityFilter'}, 

58 reason='fake reason'), 

59 'detail': '', 'expected': '009'}, 

60 {'exception': exception.NoValidHost( 

61 detail_data={'last_filter': 'FakeFilter'}, 

62 reason='fake reason'), 

63 'detail': '', 'expected': '002'}, 

64 {'exception': None, 'detail': message_field.Detail.NO_VALID_HOST, 

65 'expected': '002'}) 

66 @ddt.unpack 

67 def test_translate_detail_id(self, exception, detail, expected): 

68 result = message_field.translate_detail_id(exception, detail) 

69 self.assertEqual(expected, result)