Fix to not run unnecessary tests
The methods "test_sample" and "test_sample_root" for obtaining the path of the sample file have been added to the TestCase class of base.py, but the above methods are judged to be test methods and executed in the UT. This patch renames and moves the relevant methods from {tosca-parser_root}/toscaparser/tests/base.py to {tosca-parser_root}/toscaparser/tests/utiles.py. Change-Id: If3a2e73d2e9d4a6052fef5db8db74c3da211bc5c
This commit is contained in:
parent
bfbe9b33f5
commit
6a95391f17
@ -20,6 +20,7 @@ import fixtures
|
||||
import testscenarios
|
||||
import testtools
|
||||
|
||||
from toscaparser.tests import utils
|
||||
from toscaparser.tosca_template import ToscaTemplate
|
||||
|
||||
_TRUE_VALUES = ('True', 'true', '1', 'yes')
|
||||
@ -61,21 +62,7 @@ class TestCase(testscenarios.TestWithScenarios, testtools.TestCase):
|
||||
:return: ToscaTemplate
|
||||
"""
|
||||
return ToscaTemplate(os.path.join(
|
||||
TestCase.test_sample('data'), filename))
|
||||
|
||||
@staticmethod
|
||||
def sample_root():
|
||||
return os.path.abspath(os.path.join(os.path.dirname(__file__),
|
||||
'../../samples'))
|
||||
|
||||
@staticmethod
|
||||
def test_sample_root():
|
||||
# {tosca-parser}/samples/tests
|
||||
return os.path.join(TestCase.sample_root(), 'tests')
|
||||
|
||||
@staticmethod
|
||||
def test_sample(*p):
|
||||
return os.path.join(TestCase.test_sample_root(), *p)
|
||||
utils.get_sample_test_path('data'), filename))
|
||||
|
||||
|
||||
class MockTestClass():
|
||||
|
@ -11,13 +11,14 @@
|
||||
# under the License.
|
||||
|
||||
from toscaparser.tests.base import TestCase
|
||||
from toscaparser.tests import utils
|
||||
from toscaparser.tosca_template import ToscaTemplate
|
||||
|
||||
|
||||
class CustomRelationshipTypesTest(TestCase):
|
||||
|
||||
'''TOSCA template.'''
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/relationship/test_custom_relationship.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
|
||||
|
@ -16,6 +16,7 @@ from toscaparser.dataentity import DataEntity
|
||||
from toscaparser.elements.datatype import DataType
|
||||
from toscaparser.parameters import Input
|
||||
from toscaparser.tests.base import TestCase
|
||||
from toscaparser.tests import utils
|
||||
from toscaparser.tosca_template import ToscaTemplate
|
||||
from toscaparser.utils.gettextutils import _
|
||||
from toscaparser.utils import yamlparser
|
||||
@ -341,17 +342,17 @@ class DataTypeTest(TestCase):
|
||||
error.__str__())
|
||||
|
||||
def test_datatype_in_current_template(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/datatypes/test_custom_datatypes_in_current_template.yaml")
|
||||
self.assertIsNotNone(ToscaTemplate(tpl_path))
|
||||
|
||||
def test_datatype_in_template_positive(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/datatypes/test_custom_datatypes_positive.yaml")
|
||||
self.assertIsNotNone(ToscaTemplate(tpl_path))
|
||||
|
||||
def test_datatype_in_template_invalid_value(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/datatypes/test_custom_datatypes_value_error.yaml")
|
||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path)
|
||||
exception.ExceptionCollector.assertExceptionMessage(
|
||||
@ -359,7 +360,7 @@ class DataTypeTest(TestCase):
|
||||
_('"[\'1 foo street\', \'9 bar avenue\']" is not a map.'))
|
||||
|
||||
def test_datatype_in_template_nested_datatype_error(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/datatypes/test_custom_datatypes_nested_datatype_error.yaml")
|
||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path)
|
||||
exception.ExceptionCollector.assertExceptionMessage(
|
||||
|
@ -15,13 +15,14 @@ import os
|
||||
from toscaparser.common import exception
|
||||
from toscaparser import functions
|
||||
from toscaparser.tests.base import TestCase
|
||||
from toscaparser.tests import utils
|
||||
from toscaparser.tosca_template import ToscaTemplate
|
||||
from toscaparser.utils.gettextutils import _
|
||||
|
||||
|
||||
class IntrinsicFunctionsTest(TestCase):
|
||||
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/tosca_single_instance_wordpress.yaml")
|
||||
params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user',
|
||||
'db_root_pwd': '12345678'}
|
||||
@ -119,7 +120,7 @@ class IntrinsicFunctionsTest(TestCase):
|
||||
self.assertEqual(dbms_root_password.result(), '12345678')
|
||||
|
||||
def test_get_property_with_host(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/functions/test_get_property_with_host.yaml")
|
||||
mysql_database = self._get_node('mysql_database',
|
||||
ToscaTemplate(tosca_tpl,
|
||||
@ -137,7 +138,7 @@ class IntrinsicFunctionsTest(TestCase):
|
||||
self.assertEqual(1, result)
|
||||
|
||||
def test_get_property_with_nested_params(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/functions/tosca_nested_property_names_indexes.yaml")
|
||||
webserver = self._get_node('wordpress',
|
||||
ToscaTemplate(tosca_tpl,
|
||||
@ -152,7 +153,7 @@ class IntrinsicFunctionsTest(TestCase):
|
||||
self.assertEqual(3, wp_list_prop.result())
|
||||
|
||||
def test_get_property_with_capabilties_inheritance(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/functions/test_capabilties_inheritance.yaml")
|
||||
some_node = self._get_node('some_node',
|
||||
ToscaTemplate(tosca_tpl,
|
||||
@ -164,7 +165,7 @@ class IntrinsicFunctionsTest(TestCase):
|
||||
self.assertEqual('someval', some_input.result())
|
||||
|
||||
def test_get_property_source_target_keywords(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/functions/test_get_property_source_target_keywords.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl,
|
||||
parsed_params={'db_root_pwd': '1234'})
|
||||
@ -184,7 +185,7 @@ class IntrinsicFunctionsTest(TestCase):
|
||||
self.assertEqual(3306, source_port.result())
|
||||
|
||||
def test_get_prop_cap_host(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/functions/test_get_prop_cap_host.yaml")
|
||||
some_node = self._get_node('some_node',
|
||||
ToscaTemplate(tosca_tpl))
|
||||
@ -193,7 +194,7 @@ class IntrinsicFunctionsTest(TestCase):
|
||||
self.assertEqual('someval', some_prop.value.result())
|
||||
|
||||
def test_get_prop_cap_bool(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/functions/test_get_prop_cap_bool.yaml")
|
||||
some_node = self._get_node('software',
|
||||
ToscaTemplate(tosca_tpl))
|
||||
@ -206,7 +207,7 @@ class GetAttributeTest(TestCase):
|
||||
|
||||
def _load_template(self, filename):
|
||||
return ToscaTemplate(os.path.join(
|
||||
TestCase.test_sample('data'), filename),
|
||||
utils.get_sample_test_path('data'), filename),
|
||||
parsed_params={'db_root_pwd': '1234'})
|
||||
|
||||
def _get_operation(self, interfaces, operation):
|
||||
@ -303,7 +304,7 @@ class GetAttributeTest(TestCase):
|
||||
'Unexpected attribute/index value "0"'))
|
||||
|
||||
def test_get_attribute_source_target_keywords(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/functions/test_get_attribute_source_target_keywords.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl,
|
||||
parsed_params={'db_root_pwd': '12345678'})
|
||||
@ -344,7 +345,7 @@ class GetAttributeTest(TestCase):
|
||||
class ConcatTest(TestCase):
|
||||
|
||||
def _load_template(self, filename):
|
||||
return ToscaTemplate(TestCase.test_sample(filename))
|
||||
return ToscaTemplate(utils.get_sample_test_path(filename))
|
||||
|
||||
def test_validate_concat(self):
|
||||
tosca = self._load_template("data/functions/test_concat.yaml")
|
||||
@ -365,7 +366,7 @@ class ConcatTest(TestCase):
|
||||
class TokenTest(TestCase):
|
||||
|
||||
def _load_template(self, filename):
|
||||
return ToscaTemplate(TestCase.test_sample(filename))
|
||||
return ToscaTemplate(utils.get_sample_test_path(filename))
|
||||
|
||||
def test_validate_token(self):
|
||||
tosca = self._load_template("data/functions/test_token.yaml")
|
||||
|
@ -23,6 +23,7 @@ from toscaparser.common.exception import ValidationError
|
||||
from toscaparser.prereq.csar import CSAR
|
||||
from toscaparser.tests.base import MockTestClass
|
||||
from toscaparser.tests.base import TestCase
|
||||
from toscaparser.tests import utils
|
||||
import toscaparser.utils
|
||||
from toscaparser.utils.gettextutils import _
|
||||
from toscaparser.utils.urlutils import UrlUtils
|
||||
@ -30,7 +31,7 @@ from toscaparser.utils.urlutils import UrlUtils
|
||||
|
||||
class CSARPrereqTest(TestCase):
|
||||
|
||||
base_path = TestCase.test_sample_root()
|
||||
base_path = utils.get_sample_test_dir()
|
||||
|
||||
def setUp(self):
|
||||
super(CSARPrereqTest, self).setUp()
|
||||
@ -59,7 +60,7 @@ class CSARPrereqTest(TestCase):
|
||||
content: bytes
|
||||
|
||||
response = TestResponse()
|
||||
file_path = TestCase.test_sample("data/CSAR/csar_not_zip.zip")
|
||||
file_path = utils.get_sample_test_path("data/CSAR/csar_not_zip.zip")
|
||||
|
||||
with open(file_path, 'br') as f:
|
||||
response.content = f.read()
|
||||
@ -192,7 +193,7 @@ class CSARPrereqTest(TestCase):
|
||||
mock_path = "https://example.com/wordpress.yaml"
|
||||
|
||||
mockclass = MockTestClass()
|
||||
mockclass.comp_urldict = {mock_path: TestCase.test_sample(
|
||||
mockclass.comp_urldict = {mock_path: utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")}
|
||||
mock_urlopen.side_effect = mockclass.mock_urlopen_method
|
||||
mock_url_accessible.return_value = True
|
||||
@ -234,7 +235,7 @@ class CSARPrereqTest(TestCase):
|
||||
def test_csar_main_template(self):
|
||||
path = os.path.join(self.base_path, "data/CSAR/csar_hello_world.zip")
|
||||
csar = CSAR(path)
|
||||
yaml_file = TestCase.test_sample("data/tosca_helloworld.yaml")
|
||||
yaml_file = utils.get_sample_test_path("data/tosca_helloworld.yaml")
|
||||
expected_yaml = toscaparser.utils.yamlparser.load_yaml(yaml_file)
|
||||
self.assertEqual(expected_yaml, csar.get_main_template_yaml())
|
||||
self.assertTrue(csar.temp_dir is None or
|
||||
@ -264,7 +265,8 @@ class CSARPrereqTest(TestCase):
|
||||
path = os.path.join(self.base_path,
|
||||
"data/CSAR/csar_root_level_yaml.zip")
|
||||
csar = CSAR(path)
|
||||
yaml_file = TestCase.test_sample("data/CSAR/root_level_file.yaml")
|
||||
yaml_file = utils.get_sample_test_path(
|
||||
"data/CSAR/root_level_file.yaml")
|
||||
expected_yaml = toscaparser.utils.yamlparser.load_yaml(yaml_file)
|
||||
self.assertEqual(expected_yaml, csar.get_main_template_yaml())
|
||||
self.assertTrue(csar.temp_dir is None or
|
||||
@ -285,7 +287,8 @@ class CSARPrereqTest(TestCase):
|
||||
"data/CSAR/csar_root_level_"
|
||||
"yaml_and_tosca_metadata.zip")
|
||||
csar = CSAR(path)
|
||||
yaml_file = TestCase.test_sample("data/CSAR/tosca_meta_file.yaml")
|
||||
yaml_file = utils.get_sample_test_path(
|
||||
"data/CSAR/tosca_meta_file.yaml")
|
||||
expected_yaml = toscaparser.utils.yamlparser.load_yaml(yaml_file)
|
||||
self.assertEqual(expected_yaml, csar.get_main_template_yaml())
|
||||
self.assertTrue(csar.temp_dir is None or
|
||||
@ -307,7 +310,7 @@ class CSARPrereqTest(TestCase):
|
||||
self.base_path,
|
||||
"data/CSAR/csar_valid_multilevel_imports_validation.zip")
|
||||
csar = CSAR(path)
|
||||
yaml_file = TestCase.test_sample(
|
||||
yaml_file = utils.get_sample_test_path(
|
||||
"data/CSAR/multi_level_imports_response.yaml")
|
||||
expected_yaml = toscaparser.utils.yamlparser.load_yaml(yaml_file)
|
||||
self.assertEqual(expected_yaml, csar.get_main_template_yaml())
|
||||
|
@ -13,14 +13,15 @@
|
||||
from toscaparser.common import exception
|
||||
import toscaparser.shell as shell
|
||||
from toscaparser.tests.base import TestCase
|
||||
from toscaparser.tests import utils
|
||||
from toscaparser.utils.gettextutils import _
|
||||
|
||||
|
||||
class ShellTest(TestCase):
|
||||
|
||||
tosca_helloworld = TestCase.test_sample("data/tosca_helloworld.yaml")
|
||||
tosca_helloworld = utils.get_sample_test_path("data/tosca_helloworld.yaml")
|
||||
|
||||
errornous_template = TestCase.test_sample(
|
||||
errornous_template = utils.get_sample_test_path(
|
||||
"data/test_multiple_validation_errors.yaml")
|
||||
|
||||
def test_missing_arg(self):
|
||||
|
@ -15,6 +15,7 @@ import os
|
||||
from toscaparser.common import exception
|
||||
from toscaparser.substitution_mappings import SubstitutionMappings
|
||||
from toscaparser.tests.base import TestCase
|
||||
from toscaparser.tests import utils
|
||||
from toscaparser.topology_template import TopologyTemplate
|
||||
from toscaparser.tosca_template import ToscaTemplate
|
||||
from toscaparser.utils.gettextutils import _
|
||||
@ -28,7 +29,7 @@ class TopologyTemplateTest(TestCase):
|
||||
def setUp(self):
|
||||
TestCase.setUp(self)
|
||||
'''TOSCA template.'''
|
||||
self.tosca_tpl_path = TestCase.test_sample(
|
||||
self.tosca_tpl_path = utils.get_sample_test_path(
|
||||
"data/topology_template/transactionsubsystem.yaml")
|
||||
self.tpl = YAML_LOADER(self.tosca_tpl_path)
|
||||
self.topo_tpl = self.tpl.get('topology_template')
|
||||
@ -56,7 +57,7 @@ class TopologyTemplateTest(TestCase):
|
||||
|
||||
def _get_custom_types(self):
|
||||
custom_types = {}
|
||||
def_file = TestCase.test_sample(
|
||||
def_file = utils.get_sample_test_path(
|
||||
"data/topology_template/definitions.yaml")
|
||||
custom_type = YAML_LOADER(def_file)
|
||||
node_types = custom_type['node_types']
|
||||
@ -167,7 +168,7 @@ class TopologyTemplateTest(TestCase):
|
||||
self.assertEqual(props['mem_size'].value, '4096 MB')
|
||||
|
||||
def test_system_template(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/topology_template/system.yaml")
|
||||
system_tosca_template = ToscaTemplate(tpl_path)
|
||||
self.assertIsNotNone(system_tosca_template)
|
||||
@ -237,9 +238,9 @@ class TopologyTemplateTest(TestCase):
|
||||
self.assertEqual(expected_message, err.__str__())
|
||||
|
||||
def test_system_with_input_validation(self):
|
||||
tpl_path0 = TestCase.test_sample(
|
||||
tpl_path0 = utils.get_sample_test_path(
|
||||
"data/topology_template/validate/system_invalid_input.yaml")
|
||||
tpl_path1 = TestCase.test_sample(
|
||||
tpl_path1 = utils.get_sample_test_path(
|
||||
"data/topology_template/validate/"
|
||||
"queuingsubsystem_invalid_input.yaml")
|
||||
errormsg = _('SubstitutionMappings with node_type '
|
||||
@ -259,13 +260,13 @@ class TopologyTemplateTest(TestCase):
|
||||
exception.MissingRequiredInputError, errormsg)
|
||||
|
||||
def test_substitution_mappings_valid_output(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/topology_template/validate/"
|
||||
"test_substitution_mappings_valid_output.yaml")
|
||||
self.assertIsNotNone(ToscaTemplate(tpl_path))
|
||||
|
||||
def test_system_with_unknown_output_validation(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/topology_template/validate/"
|
||||
"test_substitution_mappings_invalid_output.yaml")
|
||||
errormsg = _('\'Attribute "my_cpu_output" was not found in node '
|
||||
|
@ -11,13 +11,14 @@
|
||||
# under the License.
|
||||
|
||||
from toscaparser.tests.base import TestCase
|
||||
from toscaparser.tests import utils
|
||||
from toscaparser.tosca_template import ToscaTemplate
|
||||
|
||||
|
||||
class ToscaNFVTemplateTest(TestCase):
|
||||
|
||||
'''TOSCA NFV template.'''
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/extensions/tosca_helloworld_nfv.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
|
||||
|
@ -24,6 +24,7 @@ from toscaparser.functions import GetProperty
|
||||
from toscaparser.nodetemplate import NodeTemplate
|
||||
from toscaparser.tests.base import MockTestClass
|
||||
from toscaparser.tests.base import TestCase
|
||||
from toscaparser.tests import utils
|
||||
from toscaparser.tosca_template import ToscaTemplate
|
||||
from toscaparser.utils.gettextutils import _
|
||||
from toscaparser.utils.urlutils import UrlUtils
|
||||
@ -32,13 +33,13 @@ import toscaparser.utils.yamlparser
|
||||
|
||||
class ToscaTemplateTest(TestCase):
|
||||
'''TOSCA template.'''
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/tosca_single_instance_wordpress.yaml")
|
||||
params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user',
|
||||
'db_root_pwd': '12345678'}
|
||||
tosca = ToscaTemplate(tosca_tpl, parsed_params=params)
|
||||
tosca_elk_tpl = TestCase.test_sample("data/tosca_elk.yaml")
|
||||
tosca_repo_tpl = TestCase.test_sample(
|
||||
tosca_elk_tpl = utils.get_sample_test_path("data/tosca_elk.yaml")
|
||||
tosca_repo_tpl = utils.get_sample_test_path(
|
||||
"data/repositories/tosca_repositories_test_definition.yaml")
|
||||
|
||||
def test_version(self):
|
||||
@ -161,7 +162,7 @@ class ToscaTemplateTest(TestCase):
|
||||
"sample.SC",
|
||||
)
|
||||
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_nodetype_without_relationship.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
|
||||
@ -219,7 +220,7 @@ class ToscaTemplateTest(TestCase):
|
||||
|
||||
def test_normative_type_by_short_name(self):
|
||||
# test template with a short name Compute
|
||||
template = TestCase.test_sample(
|
||||
template = utils.get_sample_test_path(
|
||||
"data/test_tosca_normative_type_by_shortname.yaml")
|
||||
|
||||
tosca_tpl = ToscaTemplate(template)
|
||||
@ -319,7 +320,7 @@ class ToscaTemplateTest(TestCase):
|
||||
with explicit relationship.
|
||||
5. Requirement expressed via TOSCA types with a filter.
|
||||
"""
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/requirements/test_requirements.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
for node_tpl in tosca.nodetemplates:
|
||||
@ -490,7 +491,7 @@ class ToscaTemplateTest(TestCase):
|
||||
}
|
||||
}
|
||||
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_capability_without_properties.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
|
||||
@ -502,7 +503,7 @@ class ToscaTemplateTest(TestCase):
|
||||
)
|
||||
|
||||
def test_local_template_with_local_relpath_import(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/tosca_single_instance_wordpress.yaml")
|
||||
params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user',
|
||||
'db_root_pwd': '12345678'}
|
||||
@ -511,9 +512,9 @@ class ToscaTemplateTest(TestCase):
|
||||
|
||||
@mock.patch.object(ToscaTemplate, '_tpl_imports')
|
||||
def test_local_template_with_url_import(self, mock_tpl_imports):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/tosca_single_instance_wordpress_with_url_import.yaml")
|
||||
import_file_path = TestCase.test_sample(
|
||||
import_file_path = utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")
|
||||
mock_tpl_imports.return_value = [import_file_path]
|
||||
tosca = ToscaTemplate(tosca_tpl,
|
||||
@ -527,9 +528,9 @@ class ToscaTemplateTest(TestCase):
|
||||
mock_path = 'https://example.com/custom_types/wordpress.yaml'
|
||||
|
||||
mockclass = MockTestClass()
|
||||
mockclass.comp_urldict = {tosca_tpl: TestCase.test_sample(
|
||||
mockclass.comp_urldict = {tosca_tpl: utils.get_sample_test_path(
|
||||
"data/tosca_single_instance_wordpress.yaml"),
|
||||
mock_path: TestCase.test_sample(
|
||||
mock_path: utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")}
|
||||
mock_urlopen.side_effect = mockclass.mock_urlopen_method
|
||||
tosca = ToscaTemplate(tosca_tpl, a_file=False,
|
||||
@ -547,7 +548,7 @@ class ToscaTemplateTest(TestCase):
|
||||
'with_local_abspath_import.yaml')
|
||||
|
||||
mockclass = MockTestClass()
|
||||
mockclass.comp_urldict = {tosca_tpl: TestCase.test_sample(
|
||||
mockclass.comp_urldict = {tosca_tpl: utils.get_sample_test_path(
|
||||
"data/tosca_single_instance_wordpress_with_local_abspath_"
|
||||
"import.yaml")}
|
||||
mock_urlopen.side_effect = mockclass.mock_urlopen_method
|
||||
@ -570,11 +571,11 @@ class ToscaTemplateTest(TestCase):
|
||||
'with_url_import.yaml')
|
||||
|
||||
mockclass = MockTestClass()
|
||||
mockclass.comp_urldict = {tosca_tpl: TestCase.test_sample(
|
||||
mockclass.comp_urldict = {tosca_tpl: utils.get_sample_test_path(
|
||||
"data/tosca_single_instance_wordpress_with_url_import.yaml")}
|
||||
mock_urlopen.side_effect = mockclass.mock_urlopen_method
|
||||
|
||||
import_file_path = TestCase.test_sample(
|
||||
import_file_path = utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")
|
||||
mock_tpl_imports.return_value = [import_file_path]
|
||||
mock_isabs.return_value = False
|
||||
@ -585,7 +586,8 @@ class ToscaTemplateTest(TestCase):
|
||||
self.assertTrue(tosca.topology_template.custom_defs)
|
||||
|
||||
def test_csar_parsing_wordpress(self):
|
||||
csar_archive = TestCase.test_sample("data/CSAR/csar_wordpress.zip")
|
||||
csar_archive = utils.get_sample_test_path(
|
||||
"data/CSAR/csar_wordpress.zip")
|
||||
self.assertTrue(ToscaTemplate(csar_archive,
|
||||
parsed_params={"db_name": "mysql",
|
||||
"db_user": "mysql",
|
||||
@ -602,7 +604,7 @@ class ToscaTemplateTest(TestCase):
|
||||
content: bytes
|
||||
|
||||
response = TestResponse()
|
||||
file_path = TestCase.test_sample("data/CSAR/csar_elk.zip")
|
||||
file_path = utils.get_sample_test_path("data/CSAR/csar_elk.zip")
|
||||
|
||||
with open(file_path, 'br') as f:
|
||||
response.content = f.read()
|
||||
@ -613,7 +615,7 @@ class ToscaTemplateTest(TestCase):
|
||||
parsed_params={"my_cpus": 4}))
|
||||
|
||||
def test_nested_imports_in_templates(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_instance_nested_imports.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
expected_custom_types = ['tosca.nodes.SoftwareComponent.Kibana',
|
||||
@ -637,7 +639,7 @@ class ToscaTemplateTest(TestCase):
|
||||
expected_msg)
|
||||
|
||||
def test_multiple_validation_errors(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_multiple_validation_errors.yaml")
|
||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl,
|
||||
None)
|
||||
@ -692,7 +694,7 @@ class ToscaTemplateTest(TestCase):
|
||||
exception.InvalidTypeError, err10_msg)
|
||||
|
||||
def test_invalid_section_names(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_invalid_section_names.yaml")
|
||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl,
|
||||
None)
|
||||
@ -718,12 +720,13 @@ class ToscaTemplateTest(TestCase):
|
||||
exception.UnknownFieldError, err4_msg)
|
||||
|
||||
def test_csar_with_alternate_extenstion(self):
|
||||
tosca_tpl = TestCase.test_sample("data/CSAR/csar_elk.csar")
|
||||
tosca_tpl = utils.get_sample_test_path("data/CSAR/csar_elk.csar")
|
||||
tosca = ToscaTemplate(tosca_tpl, parsed_params={"my_cpus": 2})
|
||||
self.assertTrue(tosca.topology_template.custom_defs)
|
||||
|
||||
def test_available_rel_tpls(self):
|
||||
tosca_tpl = TestCase.test_sample("data/test_available_rel_tpls.yaml")
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_available_rel_tpls.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
for node in tosca.nodetemplates:
|
||||
for relationship, target in node.relationships.items():
|
||||
@ -741,7 +744,7 @@ class ToscaTemplateTest(TestCase):
|
||||
err_msg)
|
||||
|
||||
def test_path_and_yaml_dict_tpl_input(self):
|
||||
test_tpl = TestCase.test_sample("data/tosca_helloworld.yaml")
|
||||
test_tpl = utils.get_sample_test_path("data/tosca_helloworld.yaml")
|
||||
|
||||
yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl)
|
||||
|
||||
@ -750,7 +753,7 @@ class ToscaTemplateTest(TestCase):
|
||||
self.assertEqual(tosca.version, "tosca_simple_yaml_1_0")
|
||||
|
||||
def test_yaml_dict_tpl_input(self):
|
||||
test_tpl = TestCase.test_sample("data/tosca_helloworld.yaml")
|
||||
test_tpl = utils.get_sample_test_path("data/tosca_helloworld.yaml")
|
||||
|
||||
yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl)
|
||||
|
||||
@ -760,14 +763,14 @@ class ToscaTemplateTest(TestCase):
|
||||
|
||||
@mock.patch.object(ToscaTemplate, '_tpl_imports')
|
||||
def test_yaml_dict_tpl_with_params_and_url_import(self, mock_tpl_imports):
|
||||
test_tpl = TestCase.test_sample(
|
||||
test_tpl = utils.get_sample_test_path(
|
||||
"data/tosca_single_instance_wordpress_with_url_import.yaml")
|
||||
|
||||
yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl)
|
||||
|
||||
params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user',
|
||||
'db_root_pwd': 'mypasswd'}
|
||||
import_file_path = TestCase.test_sample(
|
||||
import_file_path = utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")
|
||||
mock_tpl_imports.return_value = [import_file_path]
|
||||
|
||||
@ -777,7 +780,7 @@ class ToscaTemplateTest(TestCase):
|
||||
self.assertEqual(tosca.version, "tosca_simple_yaml_1_0")
|
||||
|
||||
def test_yaml_dict_tpl_with_rel_import(self):
|
||||
test_tpl = TestCase.test_sample(
|
||||
test_tpl = utils.get_sample_test_path(
|
||||
"data/tosca_single_instance_wordpress.yaml")
|
||||
|
||||
yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl)
|
||||
@ -791,12 +794,12 @@ class ToscaTemplateTest(TestCase):
|
||||
err_msg)
|
||||
|
||||
def test_yaml_dict_tpl_with_fullpath_import(self):
|
||||
test_tpl = TestCase.test_sample(
|
||||
test_tpl = utils.get_sample_test_path(
|
||||
"data/tosca_single_instance_wordpress.yaml")
|
||||
|
||||
yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl)
|
||||
|
||||
yaml_dict_tpl['imports'] = [TestCase.test_sample(
|
||||
yaml_dict_tpl['imports'] = [utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")]
|
||||
|
||||
params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user',
|
||||
@ -808,7 +811,7 @@ class ToscaTemplateTest(TestCase):
|
||||
self.assertEqual(tosca.version, "tosca_simple_yaml_1_0")
|
||||
|
||||
def test_policies_for_node_templates(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/policies/tosca_policy_template.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
|
||||
@ -829,7 +832,7 @@ class ToscaTemplateTest(TestCase):
|
||||
'4096 MB')
|
||||
|
||||
def test_policies_for_groups(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/policies/tosca_policy_template.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
|
||||
@ -861,7 +864,7 @@ class ToscaTemplateTest(TestCase):
|
||||
|
||||
def test_policies_for_custom(self):
|
||||
host_prop = {}
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/policies/tosca_custom_policy_template.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
|
||||
@ -892,38 +895,39 @@ class ToscaTemplateTest(TestCase):
|
||||
'512 MB')
|
||||
|
||||
def test_node_filter(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/node_filter/test_node_filter.yaml")
|
||||
ToscaTemplate(tosca_tpl)
|
||||
|
||||
def test_attributes_inheritance(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_attributes_inheritance.yaml")
|
||||
ToscaTemplate(tosca_tpl)
|
||||
|
||||
@mock.patch.object(urllib.request, 'urlopen')
|
||||
def test_repositories_definition(self, mock_urlopen):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/repositories/test_repositories_definition.yaml")
|
||||
mock_path = "https://example.com/custom_types/compute_with_prop.yaml"
|
||||
|
||||
mockclass = MockTestClass()
|
||||
mockclass.comp_urldict = {mock_path: TestCase.test_sample(
|
||||
mockclass.comp_urldict = {mock_path: utils.get_sample_test_path(
|
||||
"data/custom_types/compute_with_prop.yaml")}
|
||||
mock_urlopen.side_effect = mockclass.mock_urlopen_method
|
||||
ToscaTemplate(tosca_tpl)
|
||||
|
||||
def test_custom_caps_def(self):
|
||||
tosca_tpl = TestCase.test_sample("data/test_custom_caps_def.yaml")
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_custom_caps_def.yaml")
|
||||
ToscaTemplate(tosca_tpl)
|
||||
|
||||
def test_custom_caps_with_custom_datatype(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_custom_caps_with_datatype.yaml")
|
||||
ToscaTemplate(tosca_tpl)
|
||||
|
||||
def test_custom_rel_with_script(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_tosca_custom_rel_with_script.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
rel = tosca.relationship_templates[0]
|
||||
@ -933,7 +937,7 @@ class ToscaTemplateTest(TestCase):
|
||||
self.assertEqual(rel.interfaces[0].type, "Configure")
|
||||
|
||||
def test_various_portspec_errors(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/datatypes/test_datatype_portspec_add_req.yaml")
|
||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl,
|
||||
None)
|
||||
@ -969,21 +973,22 @@ class ToscaTemplateTest(TestCase):
|
||||
exception.RangeValueError, msg)
|
||||
|
||||
def test_containers(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/containers/test_container_docker_mysql.yaml")
|
||||
ToscaTemplate(tosca_tpl, parsed_params={"mysql_root_pwd": "12345678"})
|
||||
|
||||
def test_endpoint_on_compute(self):
|
||||
tosca_tpl = TestCase.test_sample("data/test_endpoint_on_compute.yaml")
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_endpoint_on_compute.yaml")
|
||||
ToscaTemplate(tosca_tpl)
|
||||
|
||||
def test_nested_dsl_def(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/dsl_definitions/test_nested_dsl_def.yaml")
|
||||
self.assertIsNotNone(ToscaTemplate(tosca_tpl))
|
||||
|
||||
def test_multiple_policies(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/policies/test_tosca_nfv_multiple_policies.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
self.assertEqual(
|
||||
@ -991,16 +996,17 @@ class ToscaTemplateTest(TestCase):
|
||||
sorted([policy.name for policy in tosca.policies]))
|
||||
|
||||
def test_custom_capability(self):
|
||||
tosca_tpl = TestCase.test_sample("data/test_custom_capabilty.yaml")
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_custom_capabilty.yaml")
|
||||
ToscaTemplate(tosca_tpl)
|
||||
|
||||
def test_csar_multilevel_imports_relative_path(self):
|
||||
csar_archive = TestCase.test_sample(
|
||||
csar_archive = utils.get_sample_test_path(
|
||||
"data/CSAR/csar_relative_path_import_check.zip")
|
||||
self.assertTrue(ToscaTemplate(csar_archive))
|
||||
|
||||
def test_csar_multiple_deployment_flavours(self):
|
||||
csar_archive = TestCase.test_sample(
|
||||
csar_archive = utils.get_sample_test_path(
|
||||
"data/CSAR/csar_multiple_deployment_flavour.zip")
|
||||
tosca = ToscaTemplate(csar_archive)
|
||||
flavours = list()
|
||||
@ -1012,7 +1018,8 @@ class ToscaTemplateTest(TestCase):
|
||||
self.assertEqual(flavours[1]['flavour_id'], 'complex')
|
||||
|
||||
def test_custom_rel_get_type(self):
|
||||
tosca_tpl = TestCase.test_sample("data/test_tosca_custom_rel.yaml")
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_tosca_custom_rel.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
for src in tosca.nodetemplates:
|
||||
for rel, trgt in src.relationships.items():
|
||||
@ -1021,7 +1028,7 @@ class ToscaTemplateTest(TestCase):
|
||||
self.assertEqual(rel_tpls[0].type, "MyAttachesTo")
|
||||
|
||||
def test_policies_without_required_property(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/policies/test_policies_without_required_property.yaml")
|
||||
self.assertRaises(exception.ValidationError, ToscaTemplate,
|
||||
tosca_tpl, None)
|
||||
@ -1030,17 +1037,18 @@ class ToscaTemplateTest(TestCase):
|
||||
def test_local_custom_defs(self, mock_tpl_imports):
|
||||
"""Compare if custom defs on local and remote the same."""
|
||||
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/tosca_single_instance_wordpress_with_url_import.yaml")
|
||||
|
||||
local_def = TestCase.test_sample("data/custom_types/wordpress.yaml")
|
||||
local_def = utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")
|
||||
remote_def = (
|
||||
"https://example.com/custom_types/wordpress.yaml")
|
||||
|
||||
local_defs = {remote_def: local_def}
|
||||
params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user',
|
||||
'db_root_pwd': '12345678'}
|
||||
import_file_path = TestCase.test_sample(
|
||||
import_file_path = utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")
|
||||
mock_tpl_imports.return_value = [import_file_path]
|
||||
tosca = ToscaTemplate(tosca_tpl, parsed_params=params)
|
||||
|
@ -24,6 +24,7 @@ from toscaparser.repositories import Repository
|
||||
from toscaparser.reservation import Reservation
|
||||
from toscaparser.tests.base import MockTestClass
|
||||
from toscaparser.tests.base import TestCase
|
||||
from toscaparser.tests import utils
|
||||
from toscaparser.topology_template import TopologyTemplate
|
||||
from toscaparser.tosca_template import ToscaTemplate
|
||||
from toscaparser.triggers import Triggers
|
||||
@ -34,19 +35,19 @@ import toscaparser.utils.yamlparser
|
||||
class ToscaTemplateValidationTest(TestCase):
|
||||
|
||||
def test_well_defined_template(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/tosca_single_instance_wordpress.yaml")
|
||||
params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user',
|
||||
'db_root_pwd': '12345678'}
|
||||
self.assertIsNotNone(ToscaTemplate(tpl_path, params))
|
||||
|
||||
def test_custom_interface_allowed(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/interfaces/test_custom_interface_in_template.yaml")
|
||||
self.assertIsNotNone(ToscaTemplate(tpl_path))
|
||||
|
||||
def test_custom_interface_invalid_operation(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/interfaces/test_custom_interface_invalid_operation.yaml")
|
||||
self.assertRaises(exception.ValidationError,
|
||||
ToscaTemplate, tpl_path)
|
||||
@ -60,7 +61,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
# test whether operation_definitions defined
|
||||
# under 'operations' can be used.
|
||||
def test_custom_interface_operations(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/interfaces/test_custom_interface_operations.yaml")
|
||||
tosca = ToscaTemplate(tpl_path)
|
||||
op_names = tosca.tpl['interface_types'][
|
||||
@ -78,7 +79,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
# test whether notification_definitions defined
|
||||
# under 'notifications' can be used.
|
||||
def test_custom_interface_notifications(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/interfaces/test_custom_interface_notifications.yaml")
|
||||
tosca = ToscaTemplate(tpl_path)
|
||||
no_names = tosca.tpl['interface_types'][
|
||||
@ -93,7 +94,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
self.assertEqual('CustomNo', list(no_names)[0])
|
||||
|
||||
def test_first_level_sections(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/test_tosca_top_level_error1.yaml")
|
||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path)
|
||||
exception.ExceptionCollector.assertExceptionMessage(
|
||||
@ -101,7 +102,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
_('Template is missing required field '
|
||||
'"tosca_definitions_version".'))
|
||||
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/test_tosca_top_level_error2.yaml")
|
||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path)
|
||||
exception.ExceptionCollector.assertExceptionMessage(
|
||||
@ -110,7 +111,8 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
'definition to verify valid values.'))
|
||||
|
||||
def test_template_with_imports_validation(self):
|
||||
tpl_path = TestCase.test_sample("data/tosca_imports_validation.yaml")
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/tosca_imports_validation.yaml")
|
||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path)
|
||||
exception.ExceptionCollector.assertExceptionMessage(
|
||||
exception.UnknownFieldError,
|
||||
@ -349,7 +351,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
imports:
|
||||
# omitted here for brevity
|
||||
'''
|
||||
path = TestCase.test_sample("data/tosca_elk.yaml")
|
||||
path = utils.get_sample_test_path("data/tosca_elk.yaml")
|
||||
errormsg = _('"imports" keyname is defined without including '
|
||||
'templates.')
|
||||
err = self.assertRaises(exception.ValidationError,
|
||||
@ -364,7 +366,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
imports:
|
||||
- some_definitions:
|
||||
'''
|
||||
path = TestCase.test_sample("data/tosca_elk.yaml")
|
||||
path = utils.get_sample_test_path("data/tosca_elk.yaml")
|
||||
errormsg = _('A template file name is not provided with import '
|
||||
'definition "some_definitions".')
|
||||
err = self.assertRaises(exception.ValidationError,
|
||||
@ -382,10 +384,10 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
mock_path = "https://example.com/custom_types/wordpress.yaml"
|
||||
|
||||
mockclass = MockTestClass()
|
||||
mockclass.comp_urldict = {mock_path: TestCase.test_sample(
|
||||
mockclass.comp_urldict = {mock_path: utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")}
|
||||
mock_urlopen.side_effect = mockclass.mock_urlopen_method
|
||||
path = TestCase.test_sample("data/tosca_elk.yaml")
|
||||
path = utils.get_sample_test_path("data/tosca_elk.yaml")
|
||||
custom_defs = self._imports_content_test(tpl_snippet,
|
||||
path,
|
||||
"node_types")
|
||||
@ -403,10 +405,10 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
mock_path = "https://example.com/custom_types/wordpress.yaml"
|
||||
|
||||
mockclass = MockTestClass()
|
||||
mockclass.comp_urldict = {mock_path: TestCase.test_sample(
|
||||
mockclass.comp_urldict = {mock_path: utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")}
|
||||
mock_urlopen.side_effect = mockclass.mock_urlopen_method
|
||||
path = TestCase.test_sample("data/tosca_elk.yaml")
|
||||
path = utils.get_sample_test_path("data/tosca_elk.yaml")
|
||||
custom_defs = self._imports_content_test(tpl_snippet,
|
||||
path,
|
||||
"node_types")
|
||||
@ -420,7 +422,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
file: custom_types/nested_rsyslog.yaml
|
||||
namespace_prefix: testprefix
|
||||
'''
|
||||
path = TestCase.test_sample("data/tosca_elk.yaml")
|
||||
path = utils.get_sample_test_path("data/tosca_elk.yaml")
|
||||
custom_defs = self._imports_content_test(tpl_snippet,
|
||||
path,
|
||||
"node_types")
|
||||
@ -451,11 +453,11 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
mock_path = "https://example.com/custom_types/wordpress.yaml"
|
||||
|
||||
mockclass = MockTestClass()
|
||||
mockclass.comp_urldict = {mock_path: TestCase.test_sample(
|
||||
mockclass.comp_urldict = {mock_path: utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")}
|
||||
mock_urlopen.side_effect = mockclass.mock_urlopen_method
|
||||
errormsg = _('Duplicate import name "some_definitions" was found.')
|
||||
path = TestCase.test_sample("data/tosca_elk.yaml")
|
||||
path = utils.get_sample_test_path("data/tosca_elk.yaml")
|
||||
err = self.assertRaises(exception.ValidationError,
|
||||
self._imports_content_test,
|
||||
tpl_snippet, path, None)
|
||||
@ -472,7 +474,7 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
'''
|
||||
errormsg = _('Import of template "more_definitions" is missing '
|
||||
'required field "file".')
|
||||
path = TestCase.test_sample("data/tosca_elk.yaml")
|
||||
path = utils.get_sample_test_path("data/tosca_elk.yaml")
|
||||
err = self.assertRaises(exception.MissingRequiredFieldError,
|
||||
self._imports_content_test,
|
||||
tpl_snippet, path, None)
|
||||
@ -490,7 +492,7 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
'with_url_import.yaml')
|
||||
mock_path = "https://example.com/custom_types/wordpress.yaml"
|
||||
|
||||
import_file_path = TestCase.test_sample(
|
||||
import_file_path = utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")
|
||||
mockclass = MockTestClass()
|
||||
mockclass.comp_urldict = {mock_path: import_file_path}
|
||||
@ -514,10 +516,10 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
mock_path = "https://example.com/custom_types/wordpress.yaml"
|
||||
|
||||
mockclass = MockTestClass()
|
||||
mockclass.comp_urldict = {mock_path: TestCase.test_sample(
|
||||
mockclass.comp_urldict = {mock_path: utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")}
|
||||
mock_urlopen.side_effect = mockclass.mock_urlopen_method
|
||||
path = TestCase.test_sample("data/tosca_elk.yaml")
|
||||
path = utils.get_sample_test_path("data/tosca_elk.yaml")
|
||||
custom_defs = self._imports_content_test(tpl_snippet,
|
||||
path,
|
||||
"node_types")
|
||||
@ -534,7 +536,7 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
mock_path = "https://example.com/custom_types/wordpress.yaml"
|
||||
|
||||
mockclass = MockTestClass()
|
||||
mockclass.comp_urldict = {mock_path: TestCase.test_sample(
|
||||
mockclass.comp_urldict = {mock_path: utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")}
|
||||
mock_urlopen.side_effect = mockclass.mock_urlopen_method
|
||||
|
||||
@ -544,7 +546,7 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
'''.format(ctypes["remote"])
|
||||
local_defs = {ctypes["remote"]: ctypes["local"]}
|
||||
|
||||
path = TestCase.test_sample("data/tosca_elk.yaml")
|
||||
path = utils.get_sample_test_path("data/tosca_elk.yaml")
|
||||
imports = (toscaparser.utils.yamlparser.
|
||||
simple_parse(tpl_snippet)['imports'])
|
||||
ld1 = ImportsLoader(imports, path, "node_types")
|
||||
@ -556,7 +558,7 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
imports:
|
||||
- custom_types/wordpress.yml
|
||||
'''
|
||||
path = TestCase.test_sample("data/tosca_elk.yaml")
|
||||
path = utils.get_sample_test_path("data/tosca_elk.yaml")
|
||||
custom_defs = self._imports_content_test(tpl_snippet,
|
||||
path,
|
||||
"node_types")
|
||||
@ -572,7 +574,7 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
namespace_prefix: mycompany
|
||||
namespace_uri: http://docs.oasis-open.org/tosca/ns/simple/yaml/1.0
|
||||
'''
|
||||
path = TestCase.test_sample("data/tosca_elk.yaml")
|
||||
path = utils.get_sample_test_path("data/tosca_elk.yaml")
|
||||
self.assertRaises(ImportError,
|
||||
self._imports_content_test,
|
||||
tpl_snippet, path, None)
|
||||
@ -584,7 +586,7 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
'''
|
||||
errormsg = _('Import "abc.com/tests/data/tosca_elk.yaml" is not '
|
||||
'valid.')
|
||||
path = TestCase.test_sample("data/tosca_elk.yaml")
|
||||
path = utils.get_sample_test_path("data/tosca_elk.yaml")
|
||||
err = self.assertRaises(ImportError,
|
||||
self._imports_content_test,
|
||||
tpl_snippet, path, None)
|
||||
@ -867,7 +869,8 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
|
||||
def _custom_types(self):
|
||||
custom_types = {}
|
||||
def_file = TestCase.test_sample("data/custom_types/wordpress.yaml")
|
||||
def_file = utils.get_sample_test_path(
|
||||
"data/custom_types/wordpress.yaml")
|
||||
custom_type = toscaparser.utils.yamlparser.load_yaml(def_file)
|
||||
node_types = custom_type['node_types']
|
||||
for name in node_types:
|
||||
@ -877,7 +880,8 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
|
||||
def _custom_types_policy(self):
|
||||
custom_types = {}
|
||||
def_file = TestCase.test_sample("data/custom_types/custom_policy.yaml")
|
||||
def_file = utils.get_sample_test_path(
|
||||
"data/custom_types/custom_policy.yaml")
|
||||
custom_type = toscaparser.utils.yamlparser.load_yaml(def_file)
|
||||
policy_types = custom_type['policy_types']
|
||||
for name in policy_types:
|
||||
@ -1543,7 +1547,7 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
self.assertEqual(expectedmessage, str(err))
|
||||
|
||||
def test_relationship_template_properties_key_schema(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/relationship/test_custom_relationship_key_schema.yaml")
|
||||
tosca = ToscaTemplate(tpl_path)
|
||||
p_key_schema_type = tosca.tpl['relationship_types'][
|
||||
@ -1560,17 +1564,17 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
self.assertEqual('test_value', property_value)
|
||||
|
||||
def test_tosca_version_1_3(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/test_tosca_version_1_3.yaml")
|
||||
self.assertIsNotNone(ToscaTemplate(tpl_path))
|
||||
|
||||
def test_import_tosca_version_1_3(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/test_import_tosca_version_1_3.yaml")
|
||||
self.assertIsNotNone(ToscaTemplate(tpl_path))
|
||||
|
||||
def test_invalid_template_version(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_invalid_template_version.yaml")
|
||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl)
|
||||
valid_versions = '", "'.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS)
|
||||
@ -1580,7 +1584,7 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
'are "%s".') % valid_versions))
|
||||
|
||||
def test_import_invalid_template_version(self):
|
||||
tosca_tpl = TestCase.test_sample(
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_import_invalid_template_version.yaml")
|
||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl)
|
||||
valid_versions = '", "'.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS)
|
||||
@ -1591,7 +1595,7 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
' is invalid. Valid versions are "%s".') % valid_versions))
|
||||
|
||||
def test_import_template_metadata(self):
|
||||
tosca_tpl = TestCase.test_sample("data/test_import_metadata.yml")
|
||||
tosca_tpl = utils.get_sample_test_path("data/test_import_metadata.yml")
|
||||
ToscaTemplate(tosca_tpl)
|
||||
|
||||
def test_node_template_capabilities_properties(self):
|
||||
@ -1934,11 +1938,12 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
self.assertEqual(expectedmessage, err.__str__())
|
||||
|
||||
def test_credential_datatype(self):
|
||||
tosca_tpl = TestCase.test_sample("data/test_credential_datatype.yaml")
|
||||
tosca_tpl = utils.get_sample_test_path(
|
||||
"data/test_credential_datatype.yaml")
|
||||
self.assertIsNotNone(ToscaTemplate(tosca_tpl))
|
||||
|
||||
def test_invalid_default_value(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/test_invalid_input_defaults.yaml")
|
||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path)
|
||||
exception.ExceptionCollector.assertExceptionMessage(
|
||||
@ -2045,12 +2050,12 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
self._single_node_template_content_test(tpl_snippet3))
|
||||
|
||||
def test_properties_override_with_flavor_and_image(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/test_normative_type_properties_override.yaml")
|
||||
self.assertIsNotNone(ToscaTemplate(tpl_path))
|
||||
|
||||
def test_long_rel(self):
|
||||
tpl_path = TestCase.test_sample("data/test_long_rel.yaml")
|
||||
tpl_path = utils.get_sample_test_path("data/test_long_rel.yaml")
|
||||
self.assertIsNotNone(ToscaTemplate(tpl_path))
|
||||
|
||||
def test_policy_reservation_valid_keyname_heat_resources(self):
|
||||
@ -2104,7 +2109,7 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||
self.assertEqual(expectedmessage, err.__str__())
|
||||
|
||||
def test_scalar_unit_without_unit(self):
|
||||
tpl_path = TestCase.test_sample(
|
||||
tpl_path = utils.get_sample_test_path(
|
||||
"data/test_scalar_unit_without_unit.yaml")
|
||||
self.assertRaises(exception.ValidationError,
|
||||
lambda: ToscaTemplate(tpl_path))
|
||||
|
29
toscaparser/tests/utils.py
Normal file
29
toscaparser/tests/utils.py
Normal file
@ -0,0 +1,29 @@
|
||||
# Copyright (C) 2024 Fujitsu
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
import os
|
||||
|
||||
|
||||
def get_sample_dir():
|
||||
return os.path.abspath(os.path.join(os.path.dirname(__file__),
|
||||
'../../samples'))
|
||||
|
||||
|
||||
def get_sample_test_dir():
|
||||
# {tosca-parser}/samples/tests
|
||||
return os.path.join(get_sample_dir(), 'tests')
|
||||
|
||||
|
||||
def get_sample_test_path(*p):
|
||||
return os.path.join(get_sample_test_dir(), *p)
|
Loading…
x
Reference in New Issue
Block a user