Sapan Bhatia | bcbe8ce | 2017-11-14 13:02:30 -0500 | [diff] [blame] | 1 | # 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 | |
| 15 | from mock import Mock |
| 16 | import random |
| 17 | |
| 18 | def mock_enumerator(items): |
| 19 | e = lambda:None |
| 20 | e.all = lambda:items |
| 21 | return e |
| 22 | |
| 23 | class 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 | |
| 39 | class ONOSService(Object): |
| 40 | leaf_model_name = 'ONOSService' |
| 41 | |
| 42 | class ONOSApp(Object): |
| 43 | leaf_model_name = 'ONOSApp' |
| 44 | |
| 45 | class 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 | |
| 68 | model_accessor = ModelAccessor() |
| 69 | |
| 70 | class 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 -%} |
| 82 | class {{ 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 %} |