blob: 6c0a14c47457f481fad4b1a1eecbf75b2183ff2d [file] [log] [blame]
Matteo Scandolo9ce18252017-06-22 10:48:25 -07001import unittest
Matteo Scandolo9ce18252017-06-22 10:48:25 -07002from tosca.parser import TOSCA_Parser
3
Matteo Scandolo485b7132017-06-30 11:46:47 -07004class TOSCA_Parser_Test(unittest.TestCase):
Matteo Scandolo9ce18252017-06-22 10:48:25 -07005
Matteo Scandolo485b7132017-06-30 11:46:47 -07006 def test_get_tosca_models_by_name(self):
Matteo Scandolo9ce18252017-06-22 10:48:25 -07007 """
Matteo Scandolo485b7132017-06-30 11:46:47 -07008 [TOSCA_Parser] get_tosca_models_by_name: should extract models from the TOSCA recipe and store them in a dict
Matteo Scandolo9ce18252017-06-22 10:48:25 -07009 """
Matteo Scandolo485b7132017-06-30 11:46:47 -070010 class FakeNode:
11 def __init__(self, name):
12 self.name = name
Matteo Scandolo9ce18252017-06-22 10:48:25 -070013
Matteo Scandolo485b7132017-06-30 11:46:47 -070014 class FakeTemplate:
15 nodetemplates = [
16 FakeNode('model1'),
17 FakeNode('model2')
18 ]
19 pass
Matteo Scandolo9ce18252017-06-22 10:48:25 -070020
Matteo Scandolo9ce18252017-06-22 10:48:25 -070021
Matteo Scandolo485b7132017-06-30 11:46:47 -070022 res = TOSCA_Parser.get_tosca_models_by_name(FakeTemplate)
23 self.assertIsInstance(res['model1'], FakeNode)
Matteo Scandolo8bbb03a2017-07-05 14:03:33 -070024 self.assertIsInstance(res['model2'], FakeNode)
25
26 def test_populate_dependencies(self):
27 """
28 [TOSCA_Parser] populate_dependencies: if a recipe has dependencies, it should find the ID of the requirements and add it to the model
29 """
30 class FakeRecipe:
31 requirements = [
32 {
33 'site': {
34 'node': 'site_onlab',
35 'relationship': 'tosca.relationship.BelongsToOne'
36 }
37 }
38 ]
39
40 class FakeSite:
41 id = 1
42 name = 'onlab'
43
44 class FakeModel:
45 name = 'test@opencord.org'
46
47 saved_models = {
48 'site_onlab': FakeSite
49 }
50
51 model = TOSCA_Parser.populate_dependencies(FakeModel, FakeRecipe.requirements, saved_models)
52 self.assertEqual(model.site_id, 1)