blob: 871ca188a13eaadc32075d9c2065f46566d9885a [file] [log] [blame]
Matteo Scandolocb92e162017-10-03 13:12:30 -07001# 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 Williams6bb2cfe2019-03-27 15:01:45 -070015from __future__ import absolute_import
16from __future__ import print_function
17from . import helpers # noqa: F401
Matteo Scandolocb92e162017-10-03 13:12:30 -070018import unittest
19import os
Scott Baker190df2b2018-10-08 10:54:56 -070020from xosgenx.generator import XOSProcessor, XOSProcessorArgs
Matteo Scandolocb92e162017-10-03 13:12:30 -070021
22current_dir = os.path.dirname(os.path.realpath(__file__))
Zack Williams6bb2cfe2019-03-27 15:01:45 -070023OUTPUT_DIR = os.path.join(current_dir, "out")
24print(OUTPUT_DIR)
25
Matteo Scandolocb92e162017-10-03 13:12:30 -070026
Matteo Scandolocb92e162017-10-03 13:12:30 -070027class TOSCA_Generator_Test(unittest.TestCase):
Matteo Scandolocb92e162017-10-03 13:12:30 -070028 def test_generate_basic_tosca(self):
29 """
30 [TOSCA_xtarget] Should generate a basic TOSCA recipe
31 """
Zack Williams6bb2cfe2019-03-27 15:01:45 -070032 xproto = """
Matteo Scandolocb92e162017-10-03 13:12:30 -070033 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 Williams6bb2cfe2019-03-27 15:01:45 -070038 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 Scandolocb92e162017-10-03 13:12:30 -070054 }
55 """
Zack Williams6bb2cfe2019-03-27 15:01:45 -070056 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 Bhatia4d711e72018-02-09 19:08:32 -080064 output = XOSProcessor.process(args)
Matteo Scandolocb92e162017-10-03 13:12:30 -070065 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 Williams6bb2cfe2019-03-27 15:01:45 -070072 xproto = """
Matteo Scandolocb92e162017-10-03 13:12:30 -070073 option app_label = "core";
74
75 message Service (XosBase) {
76 option verbose_name="Basic Service";
Zack Williams6bb2cfe2019-03-27 15:01:45 -070077 required string name = 1 [
78 max_length = 200,
79 content_type = "stripped",
80 blank = False,
81 null = False,
82 db_index = False
83 ];
Matteo Scandolocb92e162017-10-03 13:12:30 -070084 }
Zack Williams6bb2cfe2019-03-27 15:01:45 -070085
Matteo Scandolocb92e162017-10-03 13:12:30 -070086 message MyService (Service) {
87 option verbose_name="Extending service";
Zack Williams6bb2cfe2019-03-27 15:01:45 -070088 required string prop = 1 [
89 max_length = 200,
90 content_type = "stripped",
91 blank = False,
92 null = False,
93 db_index = False
94 ];
Matteo Scandolocb92e162017-10-03 13:12:30 -070095 }
96 """
Zack Williams6bb2cfe2019-03-27 15:01:45 -070097 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 Bhatia4d711e72018-02-09 19:08:32 -0800104 output = XOSProcessor.process(args)
Matteo Scandolo1fedfae2017-10-09 13:57:00 -0700105 self.assertEqual(output.count("name:"), 4)
Matteo Scandolocb92e162017-10-03 13:12:30 -0700106 self.assertIn("prop:", output)
107
Zack Williams6bb2cfe2019-03-27 15:01:45 -0700108
109if __name__ == "__main__":
110 unittest.main()