blob: 914c4a381b3f01dcae8ce9cd94ffda38239b021d [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain 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,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Matteo Scandolo67654fa2017-06-09 09:33:17 -070017import unittest
18import os
19from xosgenx.generator import XOSGenerator
20from helpers import FakeArgs
21
22VROUTER_XPROTO = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/xproto/vrouterport.xproto")
23
24# Generate Protobuf from Xproto and then parse the resulting Protobuf
25class XProtoProtobufGeneratorTest(unittest.TestCase):
26 def test_proto_generator(self):
27 """
28 [XOS-GenX] Generate DJANGO models, verify Fields and Foreign Keys
29 """
30 args = FakeArgs()
31 args.files = [VROUTER_XPROTO]
32 args.target = 'django.xtarget'
33 output = XOSGenerator.generate(args)
34
35 fields = filter(lambda s:'Field(' in s, output.splitlines())
36 self.assertEqual(len(fields), 2)
37 links = filter(lambda s:'Key(' in s, output.splitlines())
38 self.assertEqual(len(links), 2)
39
40if __name__ == '__main__':
41 unittest.main()
42
43