blob: e40a2dee3307952f42cf8cc3c4f744e1ab29d90c [file] [log] [blame]
Matteo Scandolo8ef264f2019-05-01 15:26:39 -07001# 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 __future__ import absolute_import
16import unittest
17from xosgenx.generator import XOSProcessor, XOSProcessorArgs
18from xosgenx.jinja2_extensions import xproto_validators
19from helpers import XProtoTestHelpers
20
21
22class 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
49if __name__ == "__main__":
50 unittest.main()