Allow methods to be empty and error when not dict

Change-Id: Ic2e37de78263f46054e0e95272afd6d1a77c9ff1
This commit is contained in:
Krzysztof Szukiełojć 2016-09-30 14:53:34 +02:00 committed by Kirill Zaitsev
parent 80a6886e81
commit b12e6c9ae1
2 changed files with 15 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import mock
from muranopkgcheck.tests import test_validator_helpers as helpers
from muranopkgcheck.validators import muranopl
from muranopkgcheck import yaml_loader
MURANOPL_BASE = {
'Name': 'Instance',
@ -119,6 +120,14 @@ class MuranoPlTests(helpers.BaseValidatorTestClass):
self.assertIn('Wrong Scope "Wrong"',
next(self.g).message)
def test_methods_list(self):
self.g = self.mpl_validator._valid_methods([])
self.assertIn('Methods are not a dict',
next(self.g).message)
def test_methods_null(self):
self.g = self.mpl_validator._valid_methods(yaml_loader.YamlNull())
def test_dict_in_body(self):
m_dict = deepcopy(MURANOPL_BASE['Methods'])
m_dict['foo']['Body'] = {'$a': 'b'}

View File

@ -21,6 +21,7 @@ from muranopkgcheck.checkers import yaql_checker
from muranopkgcheck import error
from muranopkgcheck.i18n import _
from muranopkgcheck.validators import base
from muranopkgcheck import yaml_loader
SUPPORTED_FORMATS = frozenset(['1.0', '1.1', '1.2', '1.3', '1.4'])
@ -188,6 +189,11 @@ class MuranoPLValidator(base.YamlValidator):
'"{}"').format(fqn), fqn)
def _valid_methods(self, value):
if not isinstance(value, dict):
if not isinstance(value, yaml_loader.YamlNull):
yield error.report.E046(_('Methods are not a dict'),
value)
return
for method_name, method_data in six.iteritems(value):
if not isinstance(method_data, dict):
if method_data: