From 9a682de2f1735c276903eb39c980abfe033cf9c0 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Tue, 5 Mar 2013 22:17:12 +1100 Subject: [PATCH] Fail validation when an unknown property is supplied in a template. bug #1101098 Change-Id: I9430ad859e9a93d6c0d2a417877e02c151e98a05 --- heat/engine/properties.py | 5 +++++ heat/tests/test_properties.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/heat/engine/properties.py b/heat/engine/properties.py index 00a657cc..465f02de 100644 --- a/heat/engine/properties.py +++ b/heat/engine/properties.py @@ -167,6 +167,11 @@ class Properties(collections.Mapping): return (self.error_prefix + '%s Property not implemented yet' % key) + for key in self.data: + if key not in self.props: + return (self.error_prefix + + 'Unknown Property "%s"' % key) + def __getitem__(self, key): if key not in self: raise KeyError(self.error_prefix + 'Invalid Property %s' % key) diff --git a/heat/tests/test_properties.py b/heat/tests/test_properties.py index ac7dd6d9..dc60a8a7 100644 --- a/heat/tests/test_properties.py +++ b/heat/tests/test_properties.py @@ -337,3 +337,8 @@ class PropertiesValidationTest(unittest.TestCase): schema = {'foo': {'Type': 'String'}} props = properties.Properties(schema, {'foo': 42}) self.assertEqual(props.validate(), 'foo Value must be a string') + + def test_unknown_typo(self): + schema = {'foo': {'Type': 'String'}} + props = properties.Properties(schema, {'food': 42}) + self.assertNotEqual(props.validate(), None) -- 2.45.2