[CORD-2022] Adding inherited fields to TOSCA definition

Change-Id: I76140526fe9c40980a614213b25b9fe424118bd7
diff --git a/Makefile b/Makefile
index 41b3f2e..a6493e6 100644
--- a/Makefile
+++ b/Makefile
@@ -27,4 +27,4 @@
 	curl -H "xos-username: xosadmin@opencord.org" -H "xos-password: rk1UYDHZXbu6KVCMkhmV" -X POST --data-binary @test/tosca/test.yaml 127.0.0.1:9102/delete
 
 tosca:
-	xosgenx --target=src/tosca/xtarget/tosca.xtarget --output=src/tosca/custom_types --write-to-file=model --dest-extension=yaml ../xos/xos/core/models/core.xproto
\ No newline at end of file
+	xosgenx --target=src/tosca/xtarget/tosca.xtarget --output=src/tosca/custom_types --write-to-file=target ../xos/xos/core/models/core.xproto
\ No newline at end of file
diff --git a/docs/devel.md b/docs/devel.md
index 33c5f93..4a7f752 100644
--- a/docs/devel.md
+++ b/docs/devel.md
@@ -3,7 +3,7 @@
 To run a development environment locally, you'll need to have:
 - an XOS configuration running in the frontend vm
 - source the xos virtual env (from `xos` root: `source scripts/setup_venv.sh`)
-- install `xos-tosca` specific dependencies: `pip install -r requirements`
+- install `xos-tosca` specific dependencies: `pip install -r pip_requirements.txt`
 - an entry in the `/etc/hosts` file that point `xos-core.opencord.org` to you local environment
 
 ### Run the xos-tosca process
diff --git a/src/tosca/generator.py b/src/tosca/generator.py
index 065170c..12e2442 100644
--- a/src/tosca/generator.py
+++ b/src/tosca/generator.py
@@ -43,8 +43,7 @@
             args.output = TOSCA_DEFS_DIR
             args.inputs = str(xproto.xproto)
             args.target = os.path.join(current_dir, 'xtarget/tosca.xtarget')
-            args.write_to_file = 'model'
-            args.dest_extension = 'yaml'
+            args.write_to_file = 'target'
             XOSGenerator.generate(args)
             print "[XOS-TOSCA] Recipes generated in %s" % args.output
         except Exception as e:
diff --git a/src/tosca/xtarget/tosca.xtarget b/src/tosca/xtarget/tosca.xtarget
index d162d30..5faafee 100644
--- a/src/tosca/xtarget/tosca.xtarget
+++ b/src/tosca/xtarget/tosca.xtarget
@@ -1,7 +1,10 @@
+
+{% for m in proto.messages %}
+
 tosca_definitions_version: tosca_simple_yaml_1_0
 
 node_types:
-{% for m in proto.messages %}
+
     tosca.nodes.{{ m.name }}:
         derived_from: tosca.nodes.Root
         description: {% if m.options.description -%}{{ m.options.description}}{% else%}"An XOS {{ m.name }}"{%- endif %}
@@ -13,7 +16,7 @@
                 type: boolean
                 default: false
                 description: Allow to reference existing models in TOSCA recipes
-            {% for f in m.fields %}
+            {% for f in (m.fields + xproto_base_fields(m, proto.message_table)) | sort(attribute='name') %}
             {%- if not f.link -%}
             {{ f.name }}:
                 type: {{ xproto_tosca_field_type(f.type) }}
@@ -38,4 +41,8 @@
     tosca.capabilities.xos.{{ m.name }}:
         derived_from: tosca.capabilities.Root
         description: {{ m.name }}
-{%- endfor %}
\ No newline at end of file
+
++++ {{ m.name }}.yaml
+
+{%- endfor %}
+
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: