-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #352 from maykinmedia/feature/json-merge-patch
✨ Use JSON Merge Patch when doing a partial update on records
- Loading branch information
Showing
10 changed files
with
98 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from unittest import TestCase | ||
|
||
from objects.api.utils import merge_patch | ||
|
||
|
||
class MergePatchTests(TestCase): | ||
def test_merge_patch(self): | ||
|
||
test_data = [ | ||
({"a": "b"}, {"a": "c"}, {"a": "c"}), | ||
({"a": "b"}, {"b": "c"}, {"a": "b", "b": "c"}), | ||
({"a": "b"}, {"a": None}, {"a": None}), | ||
({"a": "b", "b": "c"}, {"a": None}, {"a": None, "b": "c"}), | ||
({"a": ["b"]}, {"a": "c"}, {"a": "c"}), | ||
({"a": "c"}, {"a": ["b"]}, {"a": ["b"]}), | ||
( | ||
{"a": {"b": "c"}}, | ||
{"a": {"b": "d", "c": None}}, | ||
{"a": {"b": "d", "c": None}}, | ||
), | ||
({"a": [{"b": "c"}]}, {"a": [1]}, {"a": [1]}), | ||
(["a", "b"], ["c", "d"], ["c", "d"]), | ||
({"a": "b"}, ["c"], ["c"]), | ||
({"a": "foo"}, None, None), | ||
({"a": "foo"}, "bar", "bar"), | ||
({"e": None}, {"a": 1}, {"e": None, "a": 1}), | ||
([1, 2], {"a": "b", "c": None}, {"a": "b", "c": None}), | ||
({}, {"a": {"bb": {"ccc": None}}}, {"a": {"bb": {"ccc": None}}}), | ||
({"a": "b"}, {"a": "b"}, {"a": "b"}), | ||
] | ||
|
||
for target, patch, expected in test_data: | ||
with self.subTest(): | ||
self.assertEqual(merge_patch(target, patch), expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from typing import Dict, List, Union | ||
|
||
JSONPrimitive = Union[str, int, None, float, bool] | ||
|
||
JSONValue = Union[JSONPrimitive, "JSONObject", List["JSONValue"]] | ||
|
||
JSONObject = Dict[str, JSONValue] |