blob: 5e7421475ae6142e45939975012dfaeb7920eb34 [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
Sapan Bhatia4d711e72018-02-09 19:08:32 -080019from xosgenx.generator import XOSProcessor
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
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
Sapan Bhatia4d711e72018-02-09 19:08:32 -080052 output = XOSProcessor.process(args)
Matteo Scandolocb92e162017-10-03 13:12:30 -070053 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 Bhatia4d711e72018-02-09 19:08:32 -080080 output = XOSProcessor.process(args)
Matteo Scandolo1fedfae2017-10-09 13:57:00 -070081 self.assertEqual(output.count("name:"), 4)
Matteo Scandolocb92e162017-10-03 13:12:30 -070082 self.assertIn("prop:", output)
83
84if __name__ == '__main__':
Sapan Bhatia4d711e72018-02-09 19:08:32 -080085 unittest.main()