blob: 3973568cd6c752d6225a4e99ee1a62f4453060e8 [file] [log] [blame]
Sapan Bhatiabcbe8ce2017-11-14 13:02:30 -05001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from mock import Mock
16import random
17
18def mock_enumerator(items):
19 e = lambda:None
20 e.all = lambda:items
21 return e
22
23class Object:
24 objects = Mock()
25 def __init__(self, **kwargs):
26 setattr(self, 'save', Mock())
27 setattr(self, 'delete', Mock())
28 setattr(self, 'backend_code', 0)
29 setattr(self, 'id', 98052)
30 setattr(self, 'pk', random.randint(0, 1<<30))
31
32 for (k,v) in kwargs.items():
33 setattr(self,k,v)
34
35
36 def tologdict(self):
37 return {}
38
39class ONOSService(Object):
40 leaf_model_name = 'ONOSService'
41
42class ONOSApp(Object):
43 leaf_model_name = 'ONOSApp'
44
45class ModelAccessor:
46 def check_db_connection_ok(self):
47 return True
48
49 def fetch_pending(self, model, deleted = False):
50 num = random.randint(1, 5)
51 object_list = []
52
53 for i in range(num):
54 if isinstance(model, list):
55 model = model[0]
56
57 try:
58 obj = model()
59 except:
60 import pdb
61 pdb.set_trace()
62
63 obj.name = "Opinionated Berry %d"%i
64 object_list.append(obj)
65
66 return object_list
67
68model_accessor = ModelAccessor()
69
70class ObjectSet(object):
71 def __init__(self, objects):
72 self.objects = objects
73
74 def all(self):
75 return self.objects
76
77#####
78# DO NOT MODIFY THE CLASSES BELOW. THEY ARE AUTOGENERATED.
79#
80
81{% for m in proto.messages -%}
82class {{ m.name }}(Object):
83 {% for f in xproto_base_fields(m, proto.message_table) + m.fields -%}
84 {{ f.name }} = {{ xproto_first_non_empty([f.options.default, "None"]) }}
85 {% endfor %}
86 leaf_model_name = "{{ m.name }}"
87{% endfor %}