Coverage for manila/tests/api/v2/stubs.py: 100%

15 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. 

12 

13import datetime 

14 

15from manila.message import message_field 

16from manila.message import message_levels 

17from manila.tests.api import fakes 

18 

19 

20FAKE_UUID = fakes.FAKE_UUID 

21 

22 

23def stub_message(id, **kwargs): 

24 message = { 

25 'id': id, 

26 'project_id': 'fake_project', 

27 'action_id': message_field.Action.ALLOCATE_HOST[0], 

28 'message_level': message_levels.ERROR, 

29 'request_id': FAKE_UUID, 

30 'resource_type': message_field.Resource.SHARE, 

31 'resource_id': FAKE_UUID, 

32 'updated_at': datetime.datetime(1900, 1, 1, 1, 1, 1, 

33 tzinfo=datetime.timezone.utc), 

34 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1, 

35 tzinfo=datetime.timezone.utc), 

36 'expires_at': datetime.datetime(1900, 1, 1, 1, 1, 1, 

37 tzinfo=datetime.timezone.utc), 

38 'detail_id': message_field.Detail.NO_VALID_HOST[0], 

39 } 

40 

41 message.update(kwargs) 

42 return message 

43 

44 

45def stub_message_get(self, context, message_id): 

46 return stub_message(message_id) 

47 

48 

49def stub_lock(id, **kwargs): 

50 lock = { 

51 'id': id, 

52 'project_id': 'f63f7a159f404cfc8604b7065c609691', 

53 'user_id': 'e78f4294e3534e00ae176bd989d6a682', 

54 'resource_id': 'c474badd-f06e-4ff9-ae26-daa00e19867b', 

55 'resource_action': 'delete', 

56 'resource_type': 'share', 

57 'lock_context': 'user', 

58 'lock_reason': 'for the tests', 

59 'updated_at': datetime.datetime(2023, 8, 10, 20, 4, 39, 

60 tzinfo=datetime.timezone.utc), 

61 'created_at': datetime.datetime(2023, 1, 10, 15, 3, 1, 

62 tzinfo=datetime.timezone.utc), 

63 } 

64 

65 lock.update(kwargs) 

66 return lock