Add schema tests for base artifact types
Add tests for json-schema generation for: images, murano_packages, heat_templates, heat_environments and tosca_templates. DictDiffer supporting class was moved in common utilities. Change-Id: I14acd7ee023b4ba7402a6c33398cc9ade63cd2fa
This commit is contained in:
parent
e66673a583
commit
67aa2433b8
|
@ -544,3 +544,42 @@ class error_handler(object):
|
|||
else:
|
||||
raise
|
||||
return new_function
|
||||
|
||||
|
||||
class DictDiffer(object):
|
||||
"""
|
||||
Calculate the difference between two dictionaries as:
|
||||
(1) items added
|
||||
(2) items removed
|
||||
(3) keys same in both but changed values
|
||||
(4) keys same in both and unchanged values
|
||||
"""
|
||||
|
||||
def __init__(self, current_dict, past_dict):
|
||||
self.current_dict, self.past_dict = current_dict, past_dict
|
||||
self.current_keys, self.past_keys = [
|
||||
set(d.keys()) for d in (current_dict, past_dict)]
|
||||
self.intersect = self.current_keys.intersection(
|
||||
self.past_keys)
|
||||
|
||||
def added(self):
|
||||
return self.current_keys - self.intersect
|
||||
|
||||
def removed(self):
|
||||
return self.past_keys - self.intersect
|
||||
|
||||
def changed(self):
|
||||
return set(o for o in self.intersect
|
||||
if self.past_dict[o] != self.current_dict[o])
|
||||
|
||||
def unchanged(self):
|
||||
return set(o for o in self.intersect
|
||||
if self.past_dict[o] == self.current_dict[o])
|
||||
|
||||
def __str__(self):
|
||||
msg = "\nResult output:\n"
|
||||
msg += "\tAdded keys: %s\n" % ', '.join(self.added())
|
||||
msg += "\tRemoved keys: %s\n" % ', '.join(self.removed())
|
||||
msg += "\tChanged keys: %s\n" % ', '.join(self.changed())
|
||||
msg += "\tUnchanged keys: %s\n" % ', '.join(self.unchanged())
|
||||
return msg
|
||||
|
|
|
@ -20,6 +20,7 @@ from oslo_log import log as logging
|
|||
|
||||
from glare.common import exception
|
||||
from glare.common import policy
|
||||
from glare.common import utils
|
||||
from glare.db import artifact_api
|
||||
from glare.i18n import _
|
||||
from glare import locking
|
||||
|
@ -156,39 +157,9 @@ class Engine(object):
|
|||
:return: dict of updated attributes and their values
|
||||
"""
|
||||
|
||||
class DictDiffer(object):
|
||||
"""
|
||||
Calculate the difference between two dictionaries as:
|
||||
(1) items added
|
||||
(2) items removed
|
||||
(3) keys same in both but changed values
|
||||
(4) keys same in both and unchanged values
|
||||
"""
|
||||
def __init__(self, current_dict, past_dict):
|
||||
self.current_dict, self.past_dict = current_dict, past_dict
|
||||
self.current_keys, self.past_keys = [
|
||||
set(d.keys()) for d in (current_dict, past_dict)
|
||||
]
|
||||
self.intersect = self.current_keys.intersection(
|
||||
self.past_keys)
|
||||
|
||||
def added(self):
|
||||
return self.current_keys - self.intersect
|
||||
|
||||
def removed(self):
|
||||
return self.past_keys - self.intersect
|
||||
|
||||
def changed(self):
|
||||
return set(o for o in self.intersect
|
||||
if self.past_dict[o] != self.current_dict[o])
|
||||
|
||||
def unchanged(self):
|
||||
return set(o for o in self.intersect
|
||||
if self.past_dict[o] == self.current_dict[o])
|
||||
|
||||
try:
|
||||
af_dict_patched = patch_with_upd.apply(af_dict)
|
||||
diff = DictDiffer(af_dict_patched, af_dict)
|
||||
diff = utils.DictDiffer(af_dict_patched, af_dict)
|
||||
|
||||
# we mustn't add or remove attributes from artifact
|
||||
if diff.added() or diff.removed():
|
||||
|
|
|
@ -54,7 +54,7 @@ class Image(base.BaseArtifact):
|
|||
description="URL where image is available "
|
||||
"for users by accepting EULA "
|
||||
"or some other form. It is "
|
||||
"used when it is not possible"
|
||||
"used when it is not possible "
|
||||
"to upload image directly to "
|
||||
"Glare. F.e. some Windows "
|
||||
"cloud images requires EULA "
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue