Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 1 | import unittest |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 2 | from tosca.parser import TOSCA_Parser |
| 3 | |
Matteo Scandolo | 485b713 | 2017-06-30 11:46:47 -0700 | [diff] [blame] | 4 | class TOSCA_Parser_Test(unittest.TestCase): |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 5 | |
Matteo Scandolo | 485b713 | 2017-06-30 11:46:47 -0700 | [diff] [blame] | 6 | def test_get_tosca_models_by_name(self): |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 7 | """ |
Matteo Scandolo | 485b713 | 2017-06-30 11:46:47 -0700 | [diff] [blame] | 8 | [TOSCA_Parser] get_tosca_models_by_name: should extract models from the TOSCA recipe and store them in a dict |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 9 | """ |
Matteo Scandolo | 485b713 | 2017-06-30 11:46:47 -0700 | [diff] [blame] | 10 | class FakeNode: |
| 11 | def __init__(self, name): |
| 12 | self.name = name |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 13 | |
Matteo Scandolo | 485b713 | 2017-06-30 11:46:47 -0700 | [diff] [blame] | 14 | class FakeTemplate: |
| 15 | nodetemplates = [ |
| 16 | FakeNode('model1'), |
| 17 | FakeNode('model2') |
| 18 | ] |
| 19 | pass |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 20 | |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 21 | |
Matteo Scandolo | 485b713 | 2017-06-30 11:46:47 -0700 | [diff] [blame] | 22 | res = TOSCA_Parser.get_tosca_models_by_name(FakeTemplate) |
| 23 | self.assertIsInstance(res['model1'], FakeNode) |
Matteo Scandolo | 8bbb03a | 2017-07-05 14:03:33 -0700 | [diff] [blame^] | 24 | 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) |