Merge "Python 3: Fix JsonPatch-related issues"

This commit is contained in:
Jenkins
2014-02-25 10:06:15 +00:00
committed by Gerrit Code Review

View File

@@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from jsonpatch import JsonPatch
import testtools
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):
def test_property_minimum(self):
prop = schemas.SchemaProperty('size')
@@ -111,7 +117,7 @@ class TestSchemaBasedModel(testtools.TestCase):
patch = original.patch
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):
obj = {
@@ -123,7 +129,7 @@ class TestSchemaBasedModel(testtools.TestCase):
patch = original.patch
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):
obj = {
@@ -136,7 +142,7 @@ class TestSchemaBasedModel(testtools.TestCase):
patch = original.patch
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):
obj = {
@@ -149,7 +155,7 @@ class TestSchemaBasedModel(testtools.TestCase):
patch = original.patch
expected = '[{"path": "/weight", "op": "remove"}]'
self.assertEqual(patch, expected)
self.assertTrue(compare_json_patches(patch, expected))
def test_patch_should_remove_core_properties(self):
obj = {
@@ -162,4 +168,4 @@ class TestSchemaBasedModel(testtools.TestCase):
patch = original.patch
expected = '[{"path": "/color", "op": "remove"}]'
self.assertEqual(patch, expected)
self.assertTrue(compare_json_patches(patch, expected))