[CORD-1525] Populating relational fields and saving models
Change-Id: Ied02e7e48efed353ae4be8ebb277aef3b6af4cab
diff --git a/test/test_tosca_parser.py b/test/test_tosca_parser.py
index 9a369fe..6c0a14c 100644
--- a/test/test_tosca_parser.py
+++ b/test/test_tosca_parser.py
@@ -21,4 +21,32 @@
res = TOSCA_Parser.get_tosca_models_by_name(FakeTemplate)
self.assertIsInstance(res['model1'], FakeNode)
- self.assertIsInstance(res['model2'], FakeNode)
\ No newline at end of file
+ self.assertIsInstance(res['model2'], FakeNode)
+
+ def test_populate_dependencies(self):
+ """
+ [TOSCA_Parser] populate_dependencies: if a recipe has dependencies, it should find the ID of the requirements and add it to the model
+ """
+ class FakeRecipe:
+ requirements = [
+ {
+ 'site': {
+ 'node': 'site_onlab',
+ 'relationship': 'tosca.relationship.BelongsToOne'
+ }
+ }
+ ]
+
+ class FakeSite:
+ id = 1
+ name = 'onlab'
+
+ class FakeModel:
+ name = 'test@opencord.org'
+
+ saved_models = {
+ 'site_onlab': FakeSite
+ }
+
+ model = TOSCA_Parser.populate_dependencies(FakeModel, FakeRecipe.requirements, saved_models)
+ self.assertEqual(model.site_id, 1)
\ No newline at end of file
diff --git a/test/tosca/test.yaml b/test/tosca/test.yaml
index e5b9fbd..9fc2246 100644
--- a/test/tosca/test.yaml
+++ b/test/tosca/test.yaml
@@ -18,7 +18,7 @@
files: /spa/extensions/test/vendor.js, /spa/extensions/test/app.js
# Site
- onlab:
+ site_onlab:
type: tosca.nodes.Site
properties:
name: Open Networking Lab
@@ -26,14 +26,16 @@
hosts_nodes: True
# User
- test@opencord.org:
+ user_test:
type: tosca.nodes.User
properties:
+ username: test@opencord.org
+ email: test@opencord.org
password: mypwd
firstname: User
lastname: Test
is_admin: True
requirements:
- site:
- node: onlab
+ node: site_onlab
relationship: tosca.relationships.BelongsToOne
\ No newline at end of file