Merge "Python 3: Fix JsonPatch-related issues"
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from jsonpatch import JsonPatch
|
||||||
import testtools
|
import testtools
|
||||||
import warlock
|
import warlock
|
||||||
|
|
||||||
@@ -53,6 +54,11 @@ _SCHEMA = schemas.Schema({
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def compare_json_patches(a, b):
|
||||||
|
"""Return 0 if a and b describe the same JSON patch."""
|
||||||
|
return JsonPatch.from_string(a) == JsonPatch.from_string(b)
|
||||||
|
|
||||||
|
|
||||||
class TestSchemaProperty(testtools.TestCase):
|
class TestSchemaProperty(testtools.TestCase):
|
||||||
def test_property_minimum(self):
|
def test_property_minimum(self):
|
||||||
prop = schemas.SchemaProperty('size')
|
prop = schemas.SchemaProperty('size')
|
||||||
@@ -111,7 +117,7 @@ class TestSchemaBasedModel(testtools.TestCase):
|
|||||||
|
|
||||||
patch = original.patch
|
patch = original.patch
|
||||||
expected = '[{"path": "/color", "value": "red", "op": "replace"}]'
|
expected = '[{"path": "/color", "value": "red", "op": "replace"}]'
|
||||||
self.assertEqual(patch, expected)
|
self.assertTrue(compare_json_patches(patch, expected))
|
||||||
|
|
||||||
def test_patch_should_add_extra_properties(self):
|
def test_patch_should_add_extra_properties(self):
|
||||||
obj = {
|
obj = {
|
||||||
@@ -123,7 +129,7 @@ class TestSchemaBasedModel(testtools.TestCase):
|
|||||||
|
|
||||||
patch = original.patch
|
patch = original.patch
|
||||||
expected = '[{"path": "/weight", "value": "10", "op": "add"}]'
|
expected = '[{"path": "/weight", "value": "10", "op": "add"}]'
|
||||||
self.assertEqual(patch, expected)
|
self.assertTrue(compare_json_patches(patch, expected))
|
||||||
|
|
||||||
def test_patch_should_replace_extra_properties(self):
|
def test_patch_should_replace_extra_properties(self):
|
||||||
obj = {
|
obj = {
|
||||||
@@ -136,7 +142,7 @@ class TestSchemaBasedModel(testtools.TestCase):
|
|||||||
|
|
||||||
patch = original.patch
|
patch = original.patch
|
||||||
expected = '[{"path": "/weight", "value": "22", "op": "replace"}]'
|
expected = '[{"path": "/weight", "value": "22", "op": "replace"}]'
|
||||||
self.assertEqual(patch, expected)
|
self.assertTrue(compare_json_patches(patch, expected))
|
||||||
|
|
||||||
def test_patch_should_remove_extra_properties(self):
|
def test_patch_should_remove_extra_properties(self):
|
||||||
obj = {
|
obj = {
|
||||||
@@ -149,7 +155,7 @@ class TestSchemaBasedModel(testtools.TestCase):
|
|||||||
|
|
||||||
patch = original.patch
|
patch = original.patch
|
||||||
expected = '[{"path": "/weight", "op": "remove"}]'
|
expected = '[{"path": "/weight", "op": "remove"}]'
|
||||||
self.assertEqual(patch, expected)
|
self.assertTrue(compare_json_patches(patch, expected))
|
||||||
|
|
||||||
def test_patch_should_remove_core_properties(self):
|
def test_patch_should_remove_core_properties(self):
|
||||||
obj = {
|
obj = {
|
||||||
@@ -162,4 +168,4 @@ class TestSchemaBasedModel(testtools.TestCase):
|
|||||||
|
|
||||||
patch = original.patch
|
patch = original.patch
|
||||||
expected = '[{"path": "/color", "op": "remove"}]'
|
expected = '[{"path": "/color", "op": "remove"}]'
|
||||||
self.assertEqual(patch, expected)
|
self.assertTrue(compare_json_patches(patch, expected))
|
||||||
|
Reference in New Issue
Block a user