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