[CORD-2022] Adding inherited fields to TOSCA definition
Change-Id: I76140526fe9c40980a614213b25b9fe424118bd7
diff --git a/test/out/.gitignore b/test/out/.gitignore
new file mode 100644
index 0000000..c96a04f
--- /dev/null
+++ b/test/out/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
\ No newline at end of file
diff --git a/test/test_tosca_generator.py b/test/test_tosca_generator.py
new file mode 100644
index 0000000..4e3ecda
--- /dev/null
+++ b/test/test_tosca_generator.py
@@ -0,0 +1,85 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import unittest
+import os
+from xosgenx.generator import XOSGenerator
+
+current_dir = os.path.dirname(os.path.realpath(__file__))
+OUTPUT_DIR = os.path.join(current_dir, 'out');
+print OUTPUT_DIR
+
+class FakeArgs:
+ pass
+
+class TOSCA_Generator_Test(unittest.TestCase):
+
+ def test_generate_basic_tosca(self):
+ """
+ [TOSCA_xtarget] Should generate a basic TOSCA recipe
+ """
+ xproto = \
+ """
+ option app_label = "core";
+
+ message XOSGuiExtension (XOSBase) {
+ option verbose_name="XOS GUI Extension";
+ option description="This model holds the instruction to load an extension in the GUI";
+ required string name = 1 [max_length = 200, content_type = "stripped", blank = False, help_text = "Name of the GUI Extensions", null = False, db_index = False];
+ 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];
+ }
+ """
+ args = FakeArgs()
+ args.inputs = xproto
+ args.target = os.path.join(current_dir, '../src/tosca/xtarget/tosca.xtarget')
+ args.output = OUTPUT_DIR
+ args.write_to_file = "single"
+ args.dest_file = "basic.yaml"
+ args.quiet = False
+ output = XOSGenerator.generate(args)
+ self.assertIn("name:", output)
+ self.assertIn("files:", output)
+
+ def test_generate_inherithed_tosca(self):
+ """
+ [TOSCA_xtarget] Should generate a TOSCA recipe for a models that inherits from another model
+ """
+ xproto = \
+ """
+ option app_label = "core";
+
+ message Service (XosBase) {
+ option verbose_name="Basic Service";
+ required string name = 1 [max_length = 200, content_type = "stripped", blank = False, null = False, db_index = False];
+ }
+
+ message MyService (Service) {
+ option verbose_name="Extending service";
+ required string prop = 1 [max_length = 200, content_type = "stripped", blank = False, null = False, db_index = False];
+ }
+ """
+ args = FakeArgs()
+ args.inputs = xproto
+ args.target = os.path.join(current_dir, '../src/tosca/xtarget/tosca.xtarget')
+ args.output = OUTPUT_DIR
+ args.write_to_file = 'target'
+ args.quiet = False
+ output = XOSGenerator.generate(args)
+ self.assertEqual(output.count("name:"), 2)
+ self.assertIn("prop:", output)
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/test/test_tosca_parser_e2e.py b/test/test_tosca_parser_e2e.py
index 4b6d05d..5e1f916 100644
--- a/test/test_tosca_parser_e2e.py
+++ b/test/test_tosca_parser_e2e.py
@@ -202,7 +202,6 @@
description: Create a new site with one user
imports:
- - custom_types/user.yaml
- custom_types/site.yaml
topology_template: