summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacopo Notarstefano <jacopo.notarstefano@cern.ch>2015-04-13 10:13:54 +0200
committerJacopo Notarstefano <jacopo.notarstefano@cern.ch>2015-04-13 10:13:54 +0200
commit279384fe93d32a496857a7d192e817b3f37d5a21 (patch)
treedcc5d347b623da59918860e932cd1c8a33380e20
parenta3987847483f93d2c1bd425a0f518b1146f20c90 (diff)
downloadwarlock-279384fe93d32a496857a7d192e817b3f37d5a21.tar.gz
Compare JSON strings as JSON instead of strings.
Fixes #13.
-rw-r--r--test/test_core.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/test/test_core.py b/test/test_core.py
index 6b3be39..c1f6118 100644
--- a/test/test_core.py
+++ b/test/test_core.py
@@ -15,6 +15,8 @@
import copy
import unittest
+import json
+
import six
import warlock
@@ -169,14 +171,17 @@ class TestCore(unittest.TestCase):
sweden = Country(name='Sweden', population=9379116)
sweden['name'] = 'Finland'
self.assertEqual(
- sweden.patch,
- '[{"path": "/name", "value": "Finland", "op": "replace"}]')
+ json.loads(sweden.patch),
+ json.loads(
+ '[{"path": "/name", "value": "Finland", "op": "replace"}]'))
def test_patch_drop_attribute(self):
Country = warlock.model_factory(fixture)
sweden = Country(name='Sweden', population=9379116)
del sweden['name']
- self.assertEqual(sweden.patch, '[{"path": "/name", "op": "remove"}]')
+ self.assertEqual(
+ json.loads(sweden.patch),
+ json.loads('[{"path": "/name", "op": "remove"}]'))
def test_patch_reduce_operations(self):
Country = warlock.model_factory(fixture)
@@ -184,13 +189,15 @@ class TestCore(unittest.TestCase):
sweden['name'] = 'Finland'
self.assertEqual(
- sweden.patch,
- '[{"path": "/name", "value": "Finland", "op": "replace"}]')
+ json.loads(sweden.patch),
+ json.loads(
+ '[{"path": "/name", "value": "Finland", "op": "replace"}]'))
sweden['name'] = 'Norway'
self.assertEqual(
- sweden.patch,
- '[{"path": "/name", "value": "Norway", "op": "replace"}]')
+ json.loads(sweden.patch),
+ json.loads(
+ '[{"path": "/name", "value": "Norway", "op": "replace"}]'))
def test_patch_multiple_operations(self):
Country = warlock.model_factory(fixture)
@@ -198,7 +205,12 @@ class TestCore(unittest.TestCase):
sweden['name'] = 'Finland'
sweden['population'] = 5387000
- self.assertEqual(
- sweden.patch,
+
+ self.assertEqual(len(json.loads(sweden.patch)), 2)
+
+ patches = json.loads(
'[{"path": "/name", "value": "Finland", "op": "replace"}, '
'{"path": "/population", "value": 5387000, "op": "replace"}]')
+
+ for patch in json.loads(sweden.patch):
+ self.assertTrue(patch in patches)