Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 1 | # 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 | |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 15 | from __future__ import absolute_import |
| 16 | from __future__ import print_function |
| 17 | from . import helpers # noqa: F401 |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 18 | import unittest |
| 19 | import os |
Scott Baker | 190df2b | 2018-10-08 10:54:56 -0700 | [diff] [blame] | 20 | from xosgenx.generator import XOSProcessor, XOSProcessorArgs |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 21 | |
| 22 | current_dir = os.path.dirname(os.path.realpath(__file__)) |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 23 | OUTPUT_DIR = os.path.join(current_dir, "out") |
| 24 | print(OUTPUT_DIR) |
| 25 | |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 26 | |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 27 | class TOSCA_Generator_Test(unittest.TestCase): |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 28 | def test_generate_basic_tosca(self): |
| 29 | """ |
| 30 | [TOSCA_xtarget] Should generate a basic TOSCA recipe |
| 31 | """ |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 32 | xproto = """ |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 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"; |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 38 | required string name = 1 [ |
| 39 | max_length = 200, |
| 40 | content_type = "stripped", |
| 41 | blank = False, |
| 42 | help_text = "Name of the GUI Extensions", |
| 43 | null = False, |
| 44 | db_index = False |
| 45 | ]; |
| 46 | required string files = 2 [ |
| 47 | max_length = 1024, |
| 48 | content_type = "stripped", |
| 49 | blank = False, |
| 50 | help_text = "List of comma separated file composing the view", |
| 51 | null = False, |
| 52 | db_index = False |
| 53 | ]; |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 54 | } |
| 55 | """ |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 56 | args = XOSProcessorArgs( |
| 57 | inputs=xproto, |
| 58 | target=os.path.join(current_dir, "../src/tosca/xtarget/tosca.xtarget"), |
| 59 | output=OUTPUT_DIR, |
| 60 | write_to_file="single", |
| 61 | dest_file="basic.yaml", |
| 62 | quiet=False, |
| 63 | ) |
Sapan Bhatia | 4d711e7 | 2018-02-09 19:08:32 -0800 | [diff] [blame] | 64 | output = XOSProcessor.process(args) |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 65 | self.assertIn("name:", output) |
| 66 | self.assertIn("files:", output) |
| 67 | |
| 68 | def test_generate_inherithed_tosca(self): |
| 69 | """ |
| 70 | [TOSCA_xtarget] Should generate a TOSCA recipe for a models that inherits from another model |
| 71 | """ |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 72 | xproto = """ |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 73 | option app_label = "core"; |
| 74 | |
| 75 | message Service (XosBase) { |
| 76 | option verbose_name="Basic Service"; |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 77 | required string name = 1 [ |
| 78 | max_length = 200, |
| 79 | content_type = "stripped", |
| 80 | blank = False, |
| 81 | null = False, |
| 82 | db_index = False |
| 83 | ]; |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 84 | } |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 85 | |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 86 | message MyService (Service) { |
| 87 | option verbose_name="Extending service"; |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 88 | required string prop = 1 [ |
| 89 | max_length = 200, |
| 90 | content_type = "stripped", |
| 91 | blank = False, |
| 92 | null = False, |
| 93 | db_index = False |
| 94 | ]; |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 95 | } |
| 96 | """ |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 97 | args = XOSProcessorArgs( |
| 98 | inputs=xproto, |
| 99 | target=os.path.join(current_dir, "../src/tosca/xtarget/tosca.xtarget"), |
| 100 | output=OUTPUT_DIR, |
| 101 | write_to_file="target", |
| 102 | quiet=False, |
| 103 | ) |
Sapan Bhatia | 4d711e7 | 2018-02-09 19:08:32 -0800 | [diff] [blame] | 104 | output = XOSProcessor.process(args) |
Matteo Scandolo | 1fedfae | 2017-10-09 13:57:00 -0700 | [diff] [blame] | 105 | self.assertEqual(output.count("name:"), 4) |
Matteo Scandolo | cb92e16 | 2017-10-03 13:12:30 -0700 | [diff] [blame] | 106 | self.assertIn("prop:", output) |
| 107 | |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 108 | |
| 109 | if __name__ == "__main__": |
| 110 | unittest.main() |