summaryrefslogtreecommitdiffstats
path: root/tosca2heat/tosca-parser/toscaparser/tests/test_functions.py
diff options
context:
space:
mode:
authorshangxdy <shang.xiaodong@zte.com.cn>2016-07-08 15:15:00 +0800
committershangxdy <shang.xiaodong@zte.com.cn>2016-07-10 00:38:59 +0800
commit0997552722dc4845a854e0e6f8d7f18058e26380 (patch)
treeb90d1e808bb326612211ba56b3b941516493398d /tosca2heat/tosca-parser/toscaparser/tests/test_functions.py
parent7fe3011a67a239f7dc04153c54eaff78ef967eaf (diff)
Synchronise the openstack bugs
When run unittests through tox, some test cases are always error, the errors are already done in openstack community, so it's necessary to synchronise the fixes. Change-Id: Ib29078e6cc138a474e89c6a2cc90ad7a1db1bb46 JIRA: PARSER-63 Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
Diffstat (limited to 'tosca2heat/tosca-parser/toscaparser/tests/test_functions.py')
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_functions.py46
1 files changed, 39 insertions, 7 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_functions.py b/tosca2heat/tosca-parser/toscaparser/tests/test_functions.py
index 2a6225d..4d063e5 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_functions.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_functions.py
@@ -201,8 +201,9 @@ class GetAttributeTest(TestCase):
website_url_output.value.attribute_name)
def test_get_attribute_invalid_args(self):
- expected_msg = _('Expected arguments: "node-template-name", '
- '"attribute-name"')
+ expected_msg = _('Illegal arguments for function "get_attribute".'
+ ' Expected arguments: "node-template-name", '
+ '"req-or-cap"(optional), "property name"')
err = self.assertRaises(ValueError,
functions.get_function, None, None,
{'get_attribute': []})
@@ -211,10 +212,6 @@ class GetAttributeTest(TestCase):
functions.get_function, None, None,
{'get_attribute': ['x']})
self.assertIn(expected_msg, six.text_type(err))
- err = self.assertRaises(ValueError,
- functions.get_function, None, None,
- {'get_attribute': ['x', 'y', 'z', 'k']})
- self.assertIn(expected_msg, six.text_type(err))
def test_get_attribute_unknown_node_template_name(self):
self.assertRaises(
@@ -280,7 +277,7 @@ class GetAttributeTest(TestCase):
exception.ExceptionCollector.assertExceptionMessage(
ValueError,
_('Illegal arguments for function "get_attribute". '
- 'Expected arguments: "node-template-name", "attribute-name"'))
+ 'Unexpected attribute/index value "0"'))
def test_get_attribute_source_target_keywords(self):
tosca_tpl = os.path.join(
@@ -300,6 +297,10 @@ class GetAttributeTest(TestCase):
source_port = operation.inputs['source_port']
self.assertTrue(isinstance(source_port, functions.GetAttribute))
+ def test_get_attribute_with_nested_params(self):
+ self._load_template(
+ 'functions/test_get_attribute_with_nested_params.yaml')
+
class ConcatTest(TestCase):
@@ -322,3 +323,34 @@ class ConcatTest(TestCase):
ValueError,
_('Invalid arguments for function "concat". Expected at least '
'one arguments.'))
+
+
+class TokenTest(TestCase):
+
+ def _load_template(self, filename):
+ return ToscaTemplate(os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ filename))
+
+ def test_validate_token(self):
+ tosca = self._load_template("data/functions/test_token.yaml")
+ server_url_output = [
+ output for output in tosca.outputs if output.name == 'url'][0]
+ func = functions.get_function(self, tosca.outputs,
+ server_url_output.value)
+ self.assertIsInstance(func, functions.Token)
+
+ self.assertRaises(exception.ValidationError, self._load_template,
+ 'data/functions/test_token_invalid.yaml')
+ exception.ExceptionCollector.assertExceptionMessage(
+ ValueError,
+ _('Invalid arguments for function "token". Expected at least '
+ 'three arguments.'))
+ exception.ExceptionCollector.assertExceptionMessage(
+ ValueError,
+ _('Invalid arguments for function "token". Expected '
+ 'integer value as third argument.'))
+ exception.ExceptionCollector.assertExceptionMessage(
+ ValueError,
+ _('Invalid arguments for function "token". Expected '
+ 'single char value as second argument.'))