blob: 4e3ecdacc88052a774b01006e81ea7f8c2d1334b [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
16
17import unittest
18import os
19from xosgenx.generator import XOSGenerator
20
21current_dir = os.path.dirname(os.path.realpath(__file__))
22OUTPUT_DIR = os.path.join(current_dir, 'out');
23print OUTPUT_DIR
24
25class FakeArgs:
26 pass
27
28class 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
52 output = XOSGenerator.generate(args)
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
80 output = XOSGenerator.generate(args)
81 self.assertEqual(output.count("name:"), 2)
82 self.assertIn("prop:", output)
83
84if __name__ == '__main__':
85 unittest.main()