Files
heat-translator/translator/toscalib/tests/test_toscadef.py
Sahdev Zala 0c1591bf15 TOSCA definition types for TOSCA library.
Create a TOSCA metamodel covering various TOSCA types including node type,
relationship type, capabilities type, interfaces and properties.

Also, a small change, renamed heat-translator subdir to 'translator' as tox
doesn't like dash in the name.

Change-Id: I59e496063f8f1d7fd8557278a690b65d2a400a43
Partially implements blueprint heat-translator-tosca
2014-05-05 16:49:32 -05:00

65 lines
2.5 KiB
Python

# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# 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.
from translator.toscalib.elements.nodetype import NodeType
from translator.toscalib.tests.base import TestCase
compute_type = NodeType('tosca.nodes.Compute')
component_type = NodeType('tosca.nodes.SoftwareComponent')
class ToscaDefTest(TestCase):
def test_type(self):
self.assertEqual(compute_type.type, "tosca.nodes.Compute")
self.assertRaises(ValueError, NodeType, 'tosca.nodes.Invalid')
def test_parent_type(self):
self.assertEqual(compute_type.parent_type.type, "tosca.nodes.Root")
def test_capabilities(self):
self.assertEqual(
['tosca.capabilities.Container'],
[c.type for c in compute_type.capabilities])
def test_properties_def(self):
self.assertEqual(
['disk_size', 'ip_address', 'mem_size',
'num_cpus', 'os_arch', 'os_distribution',
'os_type', 'os_version'],
sorted([p.name for p in compute_type.properties_def]))
self.assertTrue([p.required for p in compute_type.properties_def
if p.name == 'os_type'])
def test_requirements(self):
self.assertEqual(compute_type.requirements, None)
self.assertEqual(
[{'host': 'tosca.nodes.Compute'}],
[r for r in component_type.requirements])
def test_relationship(self):
self.assertEqual(
[('tosca.relationships.HostedOn', 'tosca.nodes.Compute')],
[(relation.type, node.type) for
relation, node in component_type.relationship.items()])
self.assertIn(
('tosca.relationships.HostedOn', ['tosca.capabilities.Container']),
[(relation.type, relation.valid_targets) for
relation in list(component_type.relationship.keys())])
def test_interfaces(self):
self.assertEqual(compute_type.interfaces, None)
root_node = NodeType('tosca.nodes.Root')
self.assertIn('tosca.interfaces.node.Lifecycle', root_node.interfaces)