diff --git a/tests/helpers.py b/tests/helpers.py index c57ee171..64a747d6 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -56,3 +56,15 @@ def trigger( if post_event: post_event(mgr.charm) return state_out + + +def sort_patch(patch: List[Dict], key=lambda obj: obj["path"] + obj["op"]): + return sorted(patch, key=key) + + +def jsonpatch_delta(self, other: "State"): + patch = jsonpatch.make_patch( + dataclasses.asdict(other), + dataclasses.asdict(self), + ).patch + return sort_patch(patch)