summaryrefslogtreecommitdiffstats
path: root/tosca2heat/tosca-parser/toscaparser/tests
diff options
context:
space:
mode:
authorshangxdy <shang.xiaodong@zte.com.cn>2016-09-09 17:41:48 +0800
committershangxdy <shang.xiaodong@zte.com.cn>2016-09-09 17:54:30 +0800
commit44540b6c2b16637659099c65e31309fc7573ba7d (patch)
tree053fde2c7387644bb2841fe7ae59ed5d008b1949 /tosca2heat/tosca-parser/toscaparser/tests
parent23f466831a8284433609e9f770737830d0b448bf (diff)
Add keys validation testcase in substitution_mapping class
Add keys validation in class of substitution_mapping according to specification of http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.0/TOSCA-Simple-Profile-YAML-v1.0.html: 1) Substitution mapping only supports keys of node_type, capabilities and requirements; 2) The key of node_type is required, the others are optional. JIRA:PARSER-80 Change-Id: Icd3284349175429e5ba5e52814819a6790f0e831 Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
Diffstat (limited to 'tosca2heat/tosca-parser/toscaparser/tests')
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py b/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py
index 6e3eb62..edb834b 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py
@@ -12,9 +12,12 @@
import os
+from toscaparser.common import exception
+from toscaparser.substitution_mappings import SubstitutionMappings
from toscaparser.tests.base import TestCase
from toscaparser.topology_template import TopologyTemplate
from toscaparser.tosca_template import ToscaTemplate
+from toscaparser.utils.gettextutils import _
import toscaparser.utils.yamlparser
YAML_LOADER = toscaparser.utils.yamlparser.load_yaml
@@ -162,3 +165,43 @@ class TopologyTemplateTest(TestCase):
self.assertEqual(
len(system_tosca_template.
nested_tosca_templates_with_topology), 4)
+
+ def test_invalid_keyname(self):
+ tpl_snippet = '''
+ substitution_mappings:
+ node_type: example.DatabaseSubsystem
+ capabilities:
+ database_endpoint: [ db_app, database_endpoint ]
+ requirements:
+ receiver1: [ tran_app, receiver1 ]
+ invalid_key: 123
+ '''
+ sub_mappings = (toscaparser.utils.yamlparser.
+ simple_parse(tpl_snippet))['substitution_mappings']
+ expected_message = _(
+ 'SubstitutionMappings contains unknown field '
+ '"invalid_key". Refer to the definition '
+ 'to verify valid values.')
+ err = self.assertRaises(
+ exception.UnknownFieldError,
+ lambda: SubstitutionMappings(sub_mappings, None, None,
+ None, None, None))
+ self.assertEqual(expected_message, err.__str__())
+
+ def test_missing_required_keyname(self):
+ tpl_snippet = '''
+ substitution_mappings:
+ capabilities:
+ database_endpoint: [ db_app, database_endpoint ]
+ requirements:
+ receiver1: [ tran_app, receiver1 ]
+ '''
+ sub_mappings = (toscaparser.utils.yamlparser.
+ simple_parse(tpl_snippet))['substitution_mappings']
+ expected_message = _('SubstitutionMappings used in topology_template '
+ 'is missing required field "node_type".')
+ err = self.assertRaises(
+ exception.MissingRequiredFieldError,
+ lambda: SubstitutionMappings(sub_mappings, None, None,
+ None, None, None))
+ self.assertEqual(expected_message, err.__str__())