summaryrefslogtreecommitdiffstats
path: root/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py
diff options
context:
space:
mode:
Diffstat (limited to 'tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py')
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py145
1 files changed, 143 insertions, 2 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py
index 81a1a6c..986d9e4 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py
@@ -20,12 +20,12 @@ from toscaparser.parameters import Input
from toscaparser.parameters import Output
from toscaparser.policy import Policy
from toscaparser.relationship_template import RelationshipTemplate
+from toscaparser.repositories import Repository
from toscaparser.tests.base import TestCase
from toscaparser.topology_template import TopologyTemplate
from toscaparser.tosca_template import ToscaTemplate
from toscaparser.triggers import Triggers
from toscaparser.utils.gettextutils import _
-
import toscaparser.utils.yamlparser
@@ -105,7 +105,9 @@ class ToscaTemplateValidationTest(TestCase):
type: integer
description: Number of CPUs for the server.
constraint:
- - valid_values: [ 1, 2, 4, 8 ]
+ - valid_values: [ 1, 2, 4 ]
+ required: yes
+ status: supported
'''
inputs = (toscaparser.utils.yamlparser.
simple_parse(tpl_snippet)['inputs'])
@@ -335,6 +337,113 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml
'to verify valid values.'),
err.__str__())
+ def _repo_content(self, path):
+ repositories = path['repositories']
+ reposit = []
+ for name, val in repositories.items():
+ reposits = Repository(name, val)
+ reposit.append(reposits)
+ return reposit
+
+ def test_repositories(self):
+ tpl_snippet = '''
+ repositories:
+ repo_code0: https://raw.githubusercontent.com/nandinivemula/intern
+ repo_code1:
+ description: My project's code Repository in github usercontent.
+ url: https://github.com/nandinivemula/intern
+ credential:
+ user: nandini
+ password: tcs@12345
+ repo_code2:
+ description: My Project's code Repository in github.
+ url: https://github.com/nandinivemula/intern
+ credential:
+ user: xyzw
+ password: xyz@123
+ '''
+ tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
+ repoobject = self._repo_content(tpl)
+ actualrepo_names = []
+ for repo in repoobject:
+ repos = repo.name
+ actualrepo_names.append(repos)
+ reposname = list(tpl.values())
+ reposnames = reposname[0]
+ expected_reponames = list(reposnames.keys())
+ self.assertEqual(expected_reponames, actualrepo_names)
+
+ def test_repositories_with_missing_required_field(self):
+ tpl_snippet = '''
+ repositories:
+ repo_code0: https://raw.githubusercontent.com/nandinivemula/intern
+ repo_code1:
+ description: My project's code Repository in github usercontent.
+ credential:
+ user: nandini
+ password: tcs@12345
+ repo_code2:
+ description: My Project's code Repository in github.
+ url: https://github.com/nandinivemula/intern
+ credential:
+ user: xyzw
+ password: xyz@123
+ '''
+ tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
+ err = self.assertRaises(exception.MissingRequiredFieldError,
+ self._repo_content, tpl)
+ expectedmessage = _('Repository "repo_code1" is missing '
+ 'required field "url".')
+ self.assertEqual(expectedmessage, err.__str__())
+
+ def test_repositories_with_unknown_field(self):
+ tpl_snippet = '''
+ repositories:
+ repo_code0: https://raw.githubusercontent.com/nandinivemula/intern
+ repo_code1:
+ description: My project's code Repository in github usercontent.
+ url: https://github.com/nandinivemula/intern
+ credential:
+ user: nandini
+ password: tcs@12345
+ repo_code2:
+ descripton: My Project's code Repository in github.
+ url: https://github.com/nandinivemula/intern
+ credential:
+ user: xyzw
+ password: xyz@123
+ '''
+ tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
+ err = self.assertRaises(exception.UnknownFieldError,
+ self._repo_content, tpl)
+ expectedmessage = _('repositories "repo_code2" contains unknown field'
+ ' "descripton". Refer to the definition to verify'
+ ' valid values.')
+ self.assertEqual(expectedmessage, err.__str__())
+
+ def test_repositories_with_invalid_url(self):
+ tpl_snippet = '''
+ repositories:
+ repo_code0: https://raw.githubusercontent.com/nandinivemula/intern
+ repo_code1:
+ description: My project's code Repository in github usercontent.
+ url: h
+ credential:
+ user: nandini
+ password: tcs@12345
+ repo_code2:
+ description: My Project's code Repository in github.
+ url: https://github.com/nandinivemula/intern
+ credential:
+ user: xyzw
+ password: xyz@123
+ '''
+ tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
+ err = self.assertRaises(exception.URLException,
+ self._repo_content, tpl)
+ expectedmessage = _('repsositories "repo_code1" Invalid Url')
+ self.assertEqual(expectedmessage, err.__str__())
+
def test_groups(self):
tpl_snippet = '''
node_templates:
@@ -1379,3 +1488,35 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml
exception.MissingRequiredFieldError,
lambda: Policy(name, policies[name], None, None))
self.assertEqual(expectedmessage, err.__str__())
+
+ def test_credential_datatype(self):
+ tosca_tpl = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "data/test_credential_datatype.yaml")
+ self.assertIsNotNone(ToscaTemplate(tosca_tpl))
+
+ def test_invalid_default_value(self):
+ tpl_path = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "data/test_invalid_input_defaults.yaml")
+ self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path)
+ exception.ExceptionCollector.assertExceptionMessage(
+ ValueError, _('"two" is not an integer.'))
+
+ def test_invalid_capability(self):
+ tpl_snippet = '''
+ node_templates:
+ server:
+ type: tosca.nodes.Compute
+ capabilities:
+ oss:
+ properties:
+ architecture: x86_64
+ '''
+ tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
+ err = self.assertRaises(exception.UnknownFieldError,
+ TopologyTemplate, tpl, None)
+ expectedmessage = _('"capabilities" of template "server" contains '
+ 'unknown field "oss". Refer to the definition '
+ 'to verify valid values.')
+ self.assertEqual(expectedmessage, err.__str__())