1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
13 from toscaparser.common.exception import InvalidPropertyValueError
14 from toscaparser.nodetemplate import NodeTemplate
15 from toscaparser.tests.base import TestCase
16 from toscaparser.utils.gettextutils import _
17 import toscaparser.utils.yamlparser
18 from translator.hot.tosca.tosca_block_storage import ToscaBlockStorage
21 class ToscaBlockStoreTest(TestCase):
23 def _tosca_blockstore_test(self, tpl_snippet, expectedprops):
24 nodetemplates = (toscaparser.utils.yamlparser.
25 simple_parse(tpl_snippet)['node_templates'])
26 name = list(nodetemplates.keys())[0]
28 nodetemplate = NodeTemplate(name, nodetemplates)
29 tosca_block_store = ToscaBlockStorage(nodetemplate)
30 tosca_block_store.handle_properties()
31 if not self._compare_properties(tosca_block_store.properties,
33 raise Exception(_("Hot Properties are not"
34 " same as expected properties"))
36 # for time being rethrowing. Will be handled future based
40 def _compare_properties(self, hotprops, expectedprops):
41 return all(item in hotprops.items() for item in expectedprops.items())
43 def test_node_blockstorage_with_properties(self):
47 type: tosca.nodes.BlockStorage
52 expectedprops = {'snapshot_id': 'abc',
54 self._tosca_blockstore_test(
61 type: tosca.nodes.BlockStorage
66 expectedprops = {'snapshot_id': 'abc',
68 self._tosca_blockstore_test(
72 def test_node_blockstorage_with_invalid_size_property(self):
76 type: tosca.nodes.BlockStorage
82 self.assertRaises(InvalidPropertyValueError,
83 lambda: self._tosca_blockstore_test(tpl_snippet,