summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Kelly <skelly@dimagi.com>2021-06-24 11:15:47 +0200
committerSimon Kelly <skelly@dimagi.com>2021-06-24 11:15:47 +0200
commit749d123ab37a0fa7593f50058a90f6fa477dcc51 (patch)
treeb46bdd197a02358d613ccf8544c27c4de76e2381
parentb008a97c247cd0f309e85db98e37d0c14e8dc81c (diff)
downloadjsonpath-rw-749d123ab37a0fa7593f50058a90f6fa477dcc51.tar.gz
test case for existing auto id
-rw-r--r--tests/test_jsonpath.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/test_jsonpath.py b/tests/test_jsonpath.py
index 33c0ea6..271e2bc 100644
--- a/tests/test_jsonpath.py
+++ b/tests/test_jsonpath.py
@@ -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, ['1.m.a2id']),
+ ('m.[1].$.b.id', data, ['1.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]']),