Debian Codegraph @

neutronclient/tests/unit/osc/v2/logging/fakes.py

raw
1 # Copyright 2017 FUJITSU LIMITED
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 #
16
17 import collections
18 import copy
19 from unittest import mock
20 import uuid
21
22
23 class FakeLogging(object):
24
25 def create(self, attrs={}):
26 """Create a fake network logs
27
28 :param Dictionary attrs:
29 A dictionary with all attributes
30 :return:
31 A OrderedDict faking the network log
32 """
33 self.ordered.update(attrs)
34 return copy.deepcopy(self.ordered)
35
36 def bulk_create(self, attrs=None, count=2):
37 """Create multiple fake network logs
38
39 :param Dictionary attrs:
40 A dictionary with all attributes
41 :param int count:
42 The number of network logs to fake
43 :return:
44 A list of dictionaries faking the network logs
45 """
46 return [self.create(attrs=attrs) for i in range(0, count)]
47
48 def get(self, attrs=None, count=2):
49 """Create multiple fake network logs
50
51 :param Dictionary attrs:
52 A dictionary with all attributes
53 :param int count:
54 The number of network logs to fake
55 :return:
56 A list of dictionaries faking the network log
57 """
58 if attrs is None:
59 self.attrs = self.bulk_create(count=count)
60 return mock.Mock(side_effect=attrs)
61
62
63 class NetworkLog(FakeLogging):
64 """Fake one or more network log"""
65
66 def __init__(self):
67 super(NetworkLog, self).__init__()
68 self.ordered = collections.OrderedDict((
69 ('id', 'log-id-' + uuid.uuid4().hex),
70 ('description', 'my-desc-' + uuid.uuid4().hex),
71 ('enabled', False),
72 ('name', 'my-log-' + uuid.uuid4().hex),
73 ('target_id', None),
74 ('project_id', 'project-id-' + uuid.uuid4().hex),
75 ('resource_id', None),
76 ('resource_type', 'security_group'),
77 ('event', 'all'),
78 ))