blob: f76dce522071179308a021c2e413d3705d4cf069 [file] [log] [blame]
Matteo Scandolocb92e162017-10-03 13:12:30 -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
Matteo Scandolo5a07a2c2018-06-05 18:04:00 -070016from helpers import *
Matteo Scandolocb92e162017-10-03 13:12:30 -070017import unittest
18import os
Scott Baker190df2b2018-10-08 10:54:56 -070019from xosgenx.generator import XOSProcessor, XOSProcessorArgs
Matteo Scandolocb92e162017-10-03 13:12:30 -070020
21current_dir = os.path.dirname(os.path.realpath(__file__))
22OUTPUT_DIR = os.path.join(current_dir, 'out');
23print OUTPUT_DIR
24
Matteo Scandolocb92e162017-10-03 13:12:30 -070025class 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 Baker190df2b2018-10-08 10:54:56 -070042 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 Bhatia4d711e72018-02-09 19:08:32 -080048 output = XOSProcessor.process(args)
Matteo Scandolocb92e162017-10-03 13:12:30 -070049 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 Baker190df2b2018-10-08 10:54:56 -070070 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 Bhatia4d711e72018-02-09 19:08:32 -080075 output = XOSProcessor.process(args)
Matteo Scandolo1fedfae2017-10-09 13:57:00 -070076 self.assertEqual(output.count("name:"), 4)
Matteo Scandolocb92e162017-10-03 13:12:30 -070077 self.assertIn("prop:", output)
78
79if __name__ == '__main__':
Sapan Bhatia4d711e72018-02-09 19:08:32 -080080 unittest.main()