Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -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 | |
Matteo Scandolo | 5a07a2c | 2018-06-05 18:04:00 -0700 | [diff] [blame] | 16 | from helpers import * |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 17 | import unittest |
| 18 | import os |
Sapan Bhatia | 4d711e7 | 2018-02-09 19:08:32 -0800 | [diff] [blame] | 19 | from xosgenx.generator import XOSProcessor |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 20 | |
| 21 | current_dir = os.path.dirname(os.path.realpath(__file__)) |
| 22 | OUTPUT_DIR = os.path.join(current_dir, 'out'); |
| 23 | print OUTPUT_DIR |
| 24 | |
| 25 | class FakeArgs: |
| 26 | pass |
| 27 | |
| 28 | class TOSCA_Generator_Test(unittest.TestCase): |
| 29 | |
| 30 | def test_generate_basic_tosca(self): |
| 31 | """ |
| 32 | [TOSCA_xtarget] Should generate a basic TOSCA recipe |
| 33 | """ |
| 34 | xproto = \ |
| 35 | """ |
| 36 | option app_label = "core"; |
| 37 | |
| 38 | message XOSGuiExtension (XOSBase) { |
| 39 | option verbose_name="XOS GUI Extension"; |
| 40 | option description="This model holds the instruction to load an extension in the GUI"; |
| 41 | required string name = 1 [max_length = 200, content_type = "stripped", blank = False, help_text = "Name of the GUI Extensions", null = False, db_index = False]; |
| 42 | required string files = 2 [max_length = 1024, content_type = "stripped", blank = False, help_text = "List of comma separated file composing the view", null = False, db_index = False]; |
| 43 | } |
| 44 | """ |
| 45 | args = FakeArgs() |
| 46 | args.inputs = xproto |
| 47 | args.target = os.path.join(current_dir, '../src/tosca/xtarget/tosca.xtarget') |
| 48 | args.output = OUTPUT_DIR |
| 49 | args.write_to_file = "single" |
| 50 | args.dest_file = "basic.yaml" |
| 51 | args.quiet = False |
Sapan Bhatia | 4d711e7 | 2018-02-09 19:08:32 -0800 | [diff] [blame] | 52 | output = XOSProcessor.process(args) |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 53 | self.assertIn("name:", output) |
| 54 | self.assertIn("files:", output) |
| 55 | |
| 56 | def test_generate_inherithed_tosca(self): |
| 57 | """ |
| 58 | [TOSCA_xtarget] Should generate a TOSCA recipe for a models that inherits from another model |
| 59 | """ |
| 60 | xproto = \ |
| 61 | """ |
| 62 | option app_label = "core"; |
| 63 | |
| 64 | message Service (XosBase) { |
| 65 | option verbose_name="Basic Service"; |
| 66 | required string name = 1 [max_length = 200, content_type = "stripped", blank = False, null = False, db_index = False]; |
| 67 | } |
| 68 | |
| 69 | message MyService (Service) { |
| 70 | option verbose_name="Extending service"; |
| 71 | required string prop = 1 [max_length = 200, content_type = "stripped", blank = False, null = False, db_index = False]; |
| 72 | } |
| 73 | """ |
| 74 | args = FakeArgs() |
| 75 | args.inputs = xproto |
| 76 | args.target = os.path.join(current_dir, '../src/tosca/xtarget/tosca.xtarget') |
| 77 | args.output = OUTPUT_DIR |
| 78 | args.write_to_file = 'target' |
| 79 | args.quiet = False |
Sapan Bhatia | 4d711e7 | 2018-02-09 19:08:32 -0800 | [diff] [blame] | 80 | output = XOSProcessor.process(args) |
Matteo Scandolo | 1fedfae | 2017-10-09 13:57:00 -0700 | [diff] [blame] | 81 | self.assertEqual(output.count("name:"), 4) |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 82 | self.assertIn("prop:", output) |
| 83 | |
| 84 | if __name__ == '__main__': |
Sapan Bhatia | 4d711e7 | 2018-02-09 19:08:32 -0800 | [diff] [blame] | 85 | unittest.main() |