summaryrefslogtreecommitdiff
path: root/tests/test_jsonpath.py
diff options
context:
space:
mode:
authorKenn Knowles <kenn@kennknowles.com>2021-06-24 10:59:21 -0700
committerGitHub <noreply@github.com>2021-06-24 10:59:21 -0700
commit6f5647bb3ad2395c20f0191fef07a1df51c9fed8 (patch)
tree6c99504715ad60f36ea9edd3a926541cddfe7743 /tests/test_jsonpath.py
parentb008a97c247cd0f309e85db98e37d0c14e8dc81c (diff)
parent08231fb66f73b83a2b5a1acc2abef49ca3be3b4c (diff)
downloadjsonpath-rw-master.tar.gz
Merge pull request #96: Don't clobber existing IDs with 'auto_id' HEADmaster
Diffstat (limited to 'tests/test_jsonpath.py')
-rw-r--r--tests/test_jsonpath.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/test_jsonpath.py b/tests/test_jsonpath.py
index 33c0ea6..8f4ae3c 100644
--- a/tests/test_jsonpath.py
+++ b/tests/test_jsonpath.py
@@ -244,7 +244,7 @@ class TestJsonPath(unittest.TestCase):
('*.id',
{'foo':{'id': 1},
'baz': 2},
- set(['1', 'baz'])) ])
+ set([1, 'baz'])) ])
def test_root_auto_id(self):
jsonpath.auto_id_field = 'id'
@@ -267,6 +267,19 @@ class TestJsonPath(unittest.TestCase):
self.check_cases([('[0].id', [42], ['[0]']),
('[2].id', [34, 65, 29, 59], ['[2]'])])
+ def test_nested_index_auto_id(self):
+ jsonpath.auto_id_field = "id"
+ data = {
+ "id": 1,
+ "b": {'id': 'bid', 'name': 'bob'},
+ "m": [
+ {'a': 'a1'}, {'a': 'a2', 'id': 'a2id'}
+ ]
+ }
+ self.check_cases([('m.[1].id', data, ['a2id']),
+ ('m.[1].$.b.id', data, ['bid']),
+ ('m.[0].id', data, ['1.m.[0]'])])
+
def test_slice_auto_id(self):
jsonpath.auto_id_field = "id"
self.check_cases([ ('[*].id', [1, 2, 3], ['[0]', '[1]', '[2]']),
@@ -277,7 +290,7 @@ class TestJsonPath(unittest.TestCase):
self.check_cases([('foo.baz.id', {'foo': {'baz': 3}}, ['foo.baz']),
('foo.baz.id', {'foo': {'baz': [3]}}, ['foo.baz']),
('foo.baz.id', {'foo': {'id': 'bizzle', 'baz': 3}}, ['bizzle.baz']),
- ('foo.baz.id', {'foo': {'baz': {'id': 'hi'}}}, ['foo.hi']),
+ ('foo.baz.id', {'foo': {'baz': {'id': 'hi'}}}, ['hi']),
('foo.baz.bizzle.id', {'foo': {'baz': {'bizzle': 5}}}, ['foo.baz.bizzle'])])
def test_descendants_auto_id(self):