Matteo Scandolo | 8ef264f | 2019-05-01 15:26:39 -0700 | [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 __future__ import absolute_import |
| 16 | import unittest |
| 17 | from xosgenx.generator import XOSProcessor, XOSProcessorArgs |
| 18 | from xosgenx.jinja2_extensions import xproto_validators |
| 19 | from helpers import XProtoTestHelpers |
| 20 | |
| 21 | |
| 22 | class XProtoGuiTest(unittest.TestCase): |
| 23 | def setUp(self): |
| 24 | self.target = XProtoTestHelpers.write_tmp_target( |
| 25 | """ |
| 26 | {%- for m in proto.messages %} |
| 27 | {% for f in m.fields %} |
| 28 | {{ xproto_validators(f) }} |
| 29 | {% endfor -%} |
| 30 | {% endfor -%} |
| 31 | """ |
| 32 | ) |
| 33 | |
| 34 | def test_validators(self): |
| 35 | field = { |
| 36 | 'modifier': 'required', |
| 37 | 'type': 'string', |
| 38 | 'options': { |
| 39 | 'max_length': '200', |
| 40 | 'modifier': 'required' |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | res = xproto_validators(field) |
| 45 | |
| 46 | self.assertDictEqual(res[0], {'int_value': 200, 'name': 'maxlength'}) |
| 47 | self.assertDictEqual(res[1], {'bool_value': True, 'name': 'required'}) |
| 48 | |
| 49 | if __name__ == "__main__": |
| 50 | unittest.main() |