Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 17 | import unittest |
| 18 | import os |
| 19 | from xosgenx.generator import XOSGenerator |
| 20 | from helpers import FakeArgs |
| 21 | |
| 22 | VROUTER_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 |
| 25 | class 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 | |
| 40 | if __name__ == '__main__': |
| 41 | unittest.main() |
| 42 | |
| 43 | |