diff --git a/pgsync/sync.py b/pgsync/sync.py index 9f563c8..e6f8ca2 100644 --- a/pgsync/sync.py +++ b/pgsync/sync.py @@ -983,6 +983,18 @@ def sync( row[META] = Transform.get_primary_keys(keys) + if node.is_root: + primary_key_values: t.List[str] = list( + map(str, primary_keys) + ) + primary_key_names: t.List[str] = [ + primary_key.name for primary_key in node.primary_keys + ] + # TODO: add support for composite pkeys + row[META][node.table] = { + primary_key_names[0]: [primary_key_values[0]], + } + if self.verbose: print(f"{(i+1)})") print(f"pkeys: {primary_keys}") diff --git a/requirements/base.txt b/requirements/base.txt index 762414c..9540fc5 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -6,9 +6,9 @@ # async-timeout==4.0.3 # via redis -boto3==1.34.159 +boto3==1.35.5 # via -r requirements/base.in -botocore==1.34.159 +botocore==1.35.5 # via # boto3 # s3transfer @@ -27,7 +27,7 @@ elasticsearch==8.15.0 # via # -r requirements/base.in # elasticsearch-dsl -elasticsearch-dsl==8.15.0 +elasticsearch-dsl==8.15.1 # via -r requirements/base.in environs==11.0.0 # via -r requirements/base.in @@ -35,17 +35,17 @@ events==0.5 # via opensearch-py greenlet==3.0.3 # via sqlalchemy -idna==3.7 +idna==3.8 # via requests jmespath==1.0.1 # via # boto3 # botocore -marshmallow==3.21.3 +marshmallow==3.22.0 # via environs opensearch-dsl==2.1.0 # via -r requirements/base.in -opensearch-py==2.6.0 +opensearch-py==2.7.1 # via opensearch-dsl packaging==24.1 # via marshmallow @@ -74,7 +74,6 @@ s3transfer==0.10.2 six==1.16.0 # via # opensearch-dsl - # opensearch-py # python-dateutil sqlalchemy==2.0.32 # via -r requirements/base.in diff --git a/requirements/dev.txt b/requirements/dev.txt index f845cc7..bc56290 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -8,9 +8,9 @@ async-timeout==4.0.3 # via redis black==24.8.0 # via -r requirements/dev.in -boto3==1.34.159 +boto3==1.35.5 # via -r requirements/base.in -botocore==1.34.159 +botocore==1.35.5 # via # boto3 # s3transfer @@ -39,7 +39,7 @@ elasticsearch==8.15.0 # via # -r requirements/base.in # elasticsearch-dsl -elasticsearch-dsl==8.15.0 +elasticsearch-dsl==8.15.1 # via -r requirements/base.in environs==11.0.0 # via -r requirements/base.in @@ -47,7 +47,7 @@ events==0.5 # via opensearch-py exceptiongroup==1.2.2 # via pytest -faker==27.0.0 +faker==28.0.0 # via -r requirements/dev.in filelock==3.15.4 # via virtualenv @@ -59,7 +59,7 @@ greenlet==3.0.3 # via sqlalchemy identify==2.6.0 # via pre-commit -idna==3.7 +idna==3.8 # via requests iniconfig==2.0.0 # via pytest @@ -69,7 +69,7 @@ jmespath==1.0.1 # via # boto3 # botocore -marshmallow==3.21.3 +marshmallow==3.22.0 # via environs mccabe==0.7.0 # via flake8 @@ -81,7 +81,7 @@ nodeenv==1.9.1 # via pre-commit opensearch-dsl==2.1.0 # via -r requirements/base.in -opensearch-py==2.6.0 +opensearch-py==2.7.1 # via opensearch-dsl packaging==24.1 # via @@ -140,7 +140,6 @@ s3transfer==0.10.2 six==1.16.0 # via # opensearch-dsl - # opensearch-py # python-dateutil sqlalchemy==2.0.32 # via -r requirements/base.in diff --git a/tests/test_sync_nested_children.py b/tests/test_sync_nested_children.py index 6b73336..f72a0b5 100644 --- a/tests/test_sync_nested_children.py +++ b/tests/test_sync_nested_children.py @@ -391,6 +391,7 @@ def test_sync(self, sync, nodes, data): "_index": "testdb", "_source": { "_meta": { + "book": {"isbn": ["abc"]}, "author": {"id": [1, 4]}, "book_author": {"id": [1, 4]}, "book_language": {"id": [1, 4, 7, 9]}, @@ -449,6 +450,7 @@ def test_sync(self, sync, nodes, data): "_index": "testdb", "_source": { "_meta": { + "book": {"isbn": ["def"]}, "author": {"id": [1, 2]}, "book_author": {"id": [2, 5]}, "book_language": {"id": [2, 5, 8]}, @@ -506,6 +508,7 @@ def test_sync(self, sync, nodes, data): "_index": "testdb", "_source": { "_meta": { + "book": {"isbn": ["ghi"]}, "author": {"id": [2, 3]}, "book_author": {"id": [3, 6]}, "book_language": {"id": [3, 6]}, @@ -708,6 +711,7 @@ def test_insert_root( "_index": "testdb", "_source": { "_meta": { + "book": {"isbn": ["jkl"]}, "author": {"id": [5]}, "book_author": {"id": [7]}, "book_language": {"id": [10, 11]}, @@ -753,6 +757,7 @@ def test_insert_root( "_index": "testdb", "_source": { "_meta": { + "book": {"isbn": ["mno"]}, "author": {"id": [5]}, "book_author": {"id": [8]}, "book_language": {"id": [12, 13]}, @@ -834,6 +839,7 @@ def test_update_root(self, data, nodes, book_cls): "_index": "testdb", "_source": { "_meta": { + "book": {"isbn": ["abc"]}, "author": {"id": [1, 4]}, "book_author": {"id": [1, 4]}, "book_language": {"id": [1, 4, 7, 9]}, @@ -1001,6 +1007,7 @@ def poll_db(): expected = [ { "_meta": { + "book": {"isbn": ["def"]}, "author": {"id": [1, 2]}, "book_author": {"id": [2, 5]}, "book_language": {"id": [2, 5, 8]}, @@ -1054,6 +1061,7 @@ def poll_db(): }, { "_meta": { + "book": {"isbn": ["ghi"]}, "author": {"id": [2, 3]}, "book_author": {"id": [3, 6]}, "book_language": {"id": [3, 6]}, @@ -1174,7 +1182,7 @@ def test_insert_through_child_op2( "isbn": "abc", "group": None, "title": "The Tiger Club", - "_meta": {}, + "_meta": {"book": {"isbn": ["abc"]}}, }, }, { @@ -1184,7 +1192,7 @@ def test_insert_through_child_op2( "isbn": "def", "group": None, "title": "The Lion Club", - "_meta": {}, + "_meta": {"book": {"isbn": ["def"]}}, }, }, { @@ -1194,7 +1202,7 @@ def test_insert_through_child_op2( "isbn": "ghi", "group": None, "title": "The Rabbit Club", - "_meta": {}, + "_meta": {"book": {"isbn": ["ghi"]}}, }, }, ] @@ -1249,6 +1257,7 @@ def poll_db(): ], "title": "The Tiger Club", "_meta": { + "book": {"isbn": ["abc"]}, "group": {"id": [1, 2]}, "book_group": {"id": [1, 2]}, }, @@ -1261,7 +1270,7 @@ def poll_db(): "isbn": "def", "group": None, "title": "The Lion Club", - "_meta": {}, + "_meta": {"book": {"isbn": ["def"]}}, }, }, { @@ -1271,7 +1280,7 @@ def poll_db(): "isbn": "ghi", "group": None, "title": "The Rabbit Club", - "_meta": {}, + "_meta": {"book": {"isbn": ["ghi"]}}, }, }, ] @@ -1346,6 +1355,7 @@ def test_insert_through_child_op( expected = [ { "_meta": { + "book": {"isbn": ["abc"]}, "author": {"id": [1, 4, 5]}, "book_author": {"id": [1, 4, 7]}, "book_language": {"id": [1, 4, 7, 9]}, @@ -1413,6 +1423,7 @@ def test_insert_through_child_op( }, { "_meta": { + "book": {"isbn": ["def"]}, "author": {"id": [1, 2]}, "book_author": {"id": [2, 5]}, "book_language": {"id": [2, 5, 8]}, @@ -1466,6 +1477,7 @@ def test_insert_through_child_op( }, { "_meta": { + "book": {"isbn": ["ghi"]}, "author": {"id": [2, 3]}, "book_author": {"id": [3, 6]}, "book_language": {"id": [3, 6]}, @@ -1602,6 +1614,7 @@ def test_update_through_child_op( expected = [ { "_meta": { + "book": {"isbn": ["abc"]}, "author": {"id": [4, 5]}, "book_author": {"id": [1, 4]}, "book_language": {"id": [1, 4, 7, 9]}, @@ -1656,6 +1669,7 @@ def test_update_through_child_op( }, { "_meta": { + "book": {"isbn": ["def"]}, "author": {"id": [1, 2]}, "book_author": {"id": [2, 5]}, "book_language": {"id": [2, 5, 8]}, @@ -1709,6 +1723,7 @@ def test_update_through_child_op( }, { "_meta": { + "book": {"isbn": ["ghi"]}, "author": {"id": [2, 3]}, "book_author": {"id": [3, 6]}, "book_language": {"id": [3, 6]}, @@ -1818,6 +1833,7 @@ def test_delete_through_child_op(self, sync, data, nodes, book_author_cls): expected = [ { "_meta": { + "book": {"isbn": ["abc"]}, "book_language": {"id": [1, 4, 7, 9]}, "book_subject": {"id": [1, 4, 6]}, "language": {"id": [1, 2, 3, 4]}, @@ -1840,6 +1856,7 @@ def test_delete_through_child_op(self, sync, data, nodes, book_author_cls): }, { "_meta": { + "book": {"isbn": ["def"]}, "author": {"id": [1, 2]}, "book_author": {"id": [2, 5]}, "book_language": {"id": [2, 5, 8]}, @@ -1893,6 +1910,7 @@ def test_delete_through_child_op(self, sync, data, nodes, book_author_cls): }, { "_meta": { + "book": {"isbn": ["ghi"]}, "author": {"id": [2, 3]}, "book_author": {"id": [3, 6]}, "book_language": {"id": [3, 6]}, diff --git a/tests/test_sync_root.py b/tests/test_sync_root.py index 23b2719..da901f0 100644 --- a/tests/test_sync_root.py +++ b/tests/test_sync_root.py @@ -100,7 +100,9 @@ def test_sync2(self, sync, data): "_id": "abc", "_index": "testdb", "_source": { - "_meta": {}, + "_meta": { + "book": {"isbn": ["abc"]}, + }, "description": "Tigers are fierce creatures", "isbn": "abc", "title": "The Tiger Club", @@ -110,7 +112,9 @@ def test_sync2(self, sync, data): "_id": "def", "_index": "testdb", "_source": { - "_meta": {}, + "_meta": { + "book": {"isbn": ["def"]}, + }, "description": "Lion and the mouse", "isbn": "def", "title": "The Lion Club", @@ -120,7 +124,7 @@ def test_sync2(self, sync, data): "_id": "ghi", "_index": "testdb", "_source": { - "_meta": {}, + "_meta": {"book": {"isbn": ["ghi"]}}, "description": "Rabbits on the run", "isbn": "ghi", "title": "The Rabbit Club", @@ -151,7 +155,9 @@ def test_transform(self, sync, data): "_id": "abc", "_index": "testdb", "_source": { - "_meta": {}, + "_meta": { + "book": {"isbn": ["abc"]}, + }, "description": "Tigers are fierce creatures", "book_isbn": "abc", "book_title": "The Tiger Club", @@ -161,7 +167,9 @@ def test_transform(self, sync, data): "_id": "def", "_index": "testdb", "_source": { - "_meta": {}, + "_meta": { + "book": {"isbn": ["def"]}, + }, "description": "Lion and the mouse", "book_isbn": "def", "book_title": "The Lion Club", @@ -171,7 +179,7 @@ def test_transform(self, sync, data): "_id": "ghi", "_index": "testdb", "_source": { - "_meta": {}, + "_meta": {"book": {"isbn": ["ghi"]}}, "description": "Rabbits on the run", "book_isbn": "ghi", "book_title": "The Rabbit Club", @@ -338,19 +346,19 @@ def test_doc_includes_nulls(self, sync, data): assert sources == { "abc": { - "_meta": {}, + "_meta": {"book": {"isbn": ["abc"]}}, "copyright": None, "description": "Tigers are fierce creatures", "isbn": "abc", }, "def": { - "_meta": {}, + "_meta": {"book": {"isbn": ["def"]}}, "copyright": None, "description": "Lion and the mouse", "isbn": "def", }, "ghi": { - "_meta": {}, + "_meta": {"book": {"isbn": ["ghi"]}}, "copyright": None, "description": "Rabbits on the run", "isbn": "ghi", @@ -366,9 +374,9 @@ def test_meta_keys(self, sync, data): docs = [doc for doc in sync.sync()] sources = {doc["_id"]: doc["_source"] for doc in docs} - assert sources["abc"]["_meta"] == {} - assert sources["def"]["_meta"] == {} - assert sources["ghi"]["_meta"] == {} + assert sources["abc"]["_meta"] == {"book": {"isbn": ["abc"]}} + assert sources["def"]["_meta"] == {"book": {"isbn": ["def"]}} + assert sources["ghi"]["_meta"] == {"book": {"isbn": ["ghi"]}} assert_resync_empty(sync, nodes) def test_node_include_table(self, sync, data): @@ -407,9 +415,21 @@ def test_update_primary_key_non_concurrent(self, data, book_cls): docs = search(sync.search_client, "testdb") assert docs == [ - {"_meta": {}, "isbn": "abc", "title": "The Tiger Club"}, - {"_meta": {}, "isbn": "def", "title": "The Lion Club"}, - {"_meta": {}, "isbn": "ghi", "title": "The Rabbit Club"}, + { + "_meta": {"book": {"isbn": ["abc"]}}, + "isbn": "abc", + "title": "The Tiger Club", + }, + { + "_meta": {"book": {"isbn": ["def"]}}, + "isbn": "def", + "title": "The Lion Club", + }, + { + "_meta": {"book": {"isbn": ["ghi"]}}, + "isbn": "ghi", + "title": "The Rabbit Club", + }, ] session = sync.session @@ -426,10 +446,26 @@ def test_update_primary_key_non_concurrent(self, data, book_cls): docs = search(sync.search_client, "testdb") assert docs == [ - {"_meta": {}, "isbn": "abc", "title": "The Tiger Club"}, - {"_meta": {}, "isbn": "cba", "title": "The Tiger Club"}, - {"_meta": {}, "isbn": "def", "title": "The Lion Club"}, - {"_meta": {}, "isbn": "ghi", "title": "The Rabbit Club"}, + { + "_meta": {"book": {"isbn": ["abc"]}}, + "isbn": "abc", + "title": "The Tiger Club", + }, + { + "_meta": {"book": {"isbn": ["cba"]}}, + "isbn": "cba", + "title": "The Tiger Club", + }, + { + "_meta": {"book": {"isbn": ["def"]}}, + "isbn": "def", + "title": "The Lion Club", + }, + { + "_meta": {"book": {"isbn": ["ghi"]}}, + "isbn": "ghi", + "title": "The Rabbit Club", + }, ] assert_resync_empty(sync, doc.get("node", {})) sync.search_client.close() @@ -450,9 +486,21 @@ def test_update_primary_key_concurrent(self, data, book_cls): docs = search(sync.search_client, "testdb") assert docs == [ - {"_meta": {}, "isbn": "abc", "title": "The Tiger Club"}, - {"_meta": {}, "isbn": "def", "title": "The Lion Club"}, - {"_meta": {}, "isbn": "ghi", "title": "The Rabbit Club"}, + { + "_meta": {"book": {"isbn": ["abc"]}}, + "isbn": "abc", + "title": "The Tiger Club", + }, + { + "_meta": {"book": {"isbn": ["def"]}}, + "isbn": "def", + "title": "The Lion Club", + }, + { + "_meta": {"book": {"isbn": ["ghi"]}}, + "isbn": "ghi", + "title": "The Rabbit Club", + }, ] session = sync.session @@ -495,9 +543,21 @@ def poll_db(): assert "abc" not in [doc["isbn"] for doc in docs] assert docs == [ - {"_meta": {}, "isbn": "cba", "title": "The Tiger Club"}, - {"_meta": {}, "isbn": "def", "title": "The Lion Club"}, - {"_meta": {}, "isbn": "ghi", "title": "The Rabbit Club"}, + { + "_meta": {"book": {"isbn": ["cba"]}}, + "isbn": "cba", + "title": "The Tiger Club", + }, + { + "_meta": {"book": {"isbn": ["def"]}}, + "isbn": "def", + "title": "The Lion Club", + }, + { + "_meta": {"book": {"isbn": ["ghi"]}}, + "isbn": "ghi", + "title": "The Rabbit Club", + }, ] assert_resync_empty(sync, doc.get("node", {})) sync.search_client.close() @@ -518,9 +578,21 @@ def test_insert_non_concurrent(self, data, book_cls): docs = search(sync.search_client, "testdb") assert docs == [ - {"_meta": {}, "isbn": "abc", "title": "The Tiger Club"}, - {"_meta": {}, "isbn": "def", "title": "The Lion Club"}, - {"_meta": {}, "isbn": "ghi", "title": "The Rabbit Club"}, + { + "_meta": {"book": {"isbn": ["abc"]}}, + "isbn": "abc", + "title": "The Tiger Club", + }, + { + "_meta": {"book": {"isbn": ["def"]}}, + "isbn": "def", + "title": "The Lion Club", + }, + { + "_meta": {"book": {"isbn": ["ghi"]}}, + "isbn": "ghi", + "title": "The Rabbit Club", + }, ] with subtransactions(session): session.execute( @@ -535,10 +607,26 @@ def test_insert_non_concurrent(self, data, book_cls): docs = search(sync.search_client, "testdb") assert docs == [ - {"_meta": {}, "isbn": "abc", "title": "The Tiger Club"}, - {"_meta": {}, "isbn": "def", "title": "The Lion Club"}, - {"_meta": {}, "isbn": "ghi", "title": "The Rabbit Club"}, - {"_meta": {}, "isbn": "xyz", "title": "Encyclopedia"}, + { + "_meta": {"book": {"isbn": ["abc"]}}, + "isbn": "abc", + "title": "The Tiger Club", + }, + { + "_meta": {"book": {"isbn": ["def"]}}, + "isbn": "def", + "title": "The Lion Club", + }, + { + "_meta": {"book": {"isbn": ["ghi"]}}, + "isbn": "ghi", + "title": "The Rabbit Club", + }, + { + "_meta": {"book": {"isbn": ["xyz"]}}, + "isbn": "xyz", + "title": "Encyclopedia", + }, ] assert_resync_empty(sync, doc.get("node", {})) sync.search_client.close() @@ -559,9 +647,21 @@ def test_update_non_concurrent(self, data, book_cls): docs = search(sync.search_client, "testdb") assert docs == [ - {"_meta": {}, "isbn": "abc", "title": "The Tiger Club"}, - {"_meta": {}, "isbn": "def", "title": "The Lion Club"}, - {"_meta": {}, "isbn": "ghi", "title": "The Rabbit Club"}, + { + "_meta": {"book": {"isbn": ["abc"]}}, + "isbn": "abc", + "title": "The Tiger Club", + }, + { + "_meta": {"book": {"isbn": ["def"]}}, + "isbn": "def", + "title": "The Lion Club", + }, + { + "_meta": {"book": {"isbn": ["ghi"]}}, + "isbn": "ghi", + "title": "The Rabbit Club", + }, ] with subtransactions(session): @@ -577,9 +677,21 @@ def test_update_non_concurrent(self, data, book_cls): docs = search(sync.search_client, "testdb") assert docs == [ - {"_meta": {}, "isbn": "abc", "title": "Tiger Club"}, - {"_meta": {}, "isbn": "def", "title": "The Lion Club"}, - {"_meta": {}, "isbn": "ghi", "title": "The Rabbit Club"}, + { + "_meta": {"book": {"isbn": ["abc"]}}, + "isbn": "abc", + "title": "Tiger Club", + }, + { + "_meta": {"book": {"isbn": ["def"]}}, + "isbn": "def", + "title": "The Lion Club", + }, + { + "_meta": {"book": {"isbn": ["ghi"]}}, + "isbn": "ghi", + "title": "The Rabbit Club", + }, ] assert_resync_empty(sync, doc.get("node", {})) sync.search_client.close() @@ -600,9 +712,21 @@ def test_update_concurrent(self, data, book_cls): docs = search(sync.search_client, "testdb") assert docs == [ - {"_meta": {}, "isbn": "abc", "title": "The Tiger Club"}, - {"_meta": {}, "isbn": "def", "title": "The Lion Club"}, - {"_meta": {}, "isbn": "ghi", "title": "The Rabbit Club"}, + { + "_meta": {"book": {"isbn": ["abc"]}}, + "isbn": "abc", + "title": "The Tiger Club", + }, + { + "_meta": {"book": {"isbn": ["def"]}}, + "isbn": "def", + "title": "The Lion Club", + }, + { + "_meta": {"book": {"isbn": ["ghi"]}}, + "isbn": "ghi", + "title": "The Rabbit Club", + }, ] def pull(): @@ -639,9 +763,21 @@ def poll_db(): docs = search(sync.search_client, "testdb") assert docs == [ - {"_meta": {}, "isbn": "abc", "title": "Tiger Club"}, - {"_meta": {}, "isbn": "def", "title": "The Lion Club"}, - {"_meta": {}, "isbn": "ghi", "title": "The Rabbit Club"}, + { + "_meta": {"book": {"isbn": ["abc"]}}, + "isbn": "abc", + "title": "Tiger Club", + }, + { + "_meta": {"book": {"isbn": ["def"]}}, + "isbn": "def", + "title": "The Lion Club", + }, + { + "_meta": {"book": {"isbn": ["ghi"]}}, + "isbn": "ghi", + "title": "The Rabbit Club", + }, ] assert_resync_empty(sync, doc.get("node", {})) sync.search_client.close() @@ -660,9 +796,21 @@ def test_delete_concurrent(self, data, book_cls): docs = search(sync.search_client, "testdb") assert docs == [ - {"_meta": {}, "isbn": "abc", "title": "The Tiger Club"}, - {"_meta": {}, "isbn": "def", "title": "The Lion Club"}, - {"_meta": {}, "isbn": "ghi", "title": "The Rabbit Club"}, + { + "_meta": {"book": {"isbn": ["abc"]}}, + "isbn": "abc", + "title": "The Tiger Club", + }, + { + "_meta": {"book": {"isbn": ["def"]}}, + "isbn": "def", + "title": "The Lion Club", + }, + { + "_meta": {"book": {"isbn": ["ghi"]}}, + "isbn": "ghi", + "title": "The Rabbit Club", + }, ] def pull(): @@ -699,8 +847,16 @@ def poll_db(): docs = search(sync.search_client, "testdb") assert docs == [ - {"_meta": {}, "isbn": "def", "title": "The Lion Club"}, - {"_meta": {}, "isbn": "ghi", "title": "The Rabbit Club"}, + { + "_meta": {"book": {"isbn": ["def"]}}, + "isbn": "def", + "title": "The Lion Club", + }, + { + "_meta": {"book": {"isbn": ["ghi"]}}, + "isbn": "ghi", + "title": "The Rabbit Club", + }, ] assert_resync_empty(sync, doc.get("node", {})) sync.search_client.close() diff --git a/tests/test_sync_single_child_fk_on_child.py b/tests/test_sync_single_child_fk_on_child.py index 9cb721b..fe5d9fb 100644 --- a/tests/test_sync_single_child_fk_on_child.py +++ b/tests/test_sync_single_child_fk_on_child.py @@ -116,7 +116,7 @@ def test_relationship_object_one_to_one(self, sync, data): docs = [sort_list(doc) for doc in sync.sync()] assert docs[0]["_id"] == "abc" assert docs[0]["_source"] == { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "description": "Tigers are fierce creatures", "isbn": "abc", "rating": {"id": 1, "value": 1.1}, @@ -125,7 +125,7 @@ def test_relationship_object_one_to_one(self, sync, data): assert docs[1]["_id"] == "def" assert docs[1]["_source"] == { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "description": "Lion and the mouse", "isbn": "def", "rating": {"id": 2, "value": 2.2}, @@ -134,7 +134,7 @@ def test_relationship_object_one_to_one(self, sync, data): assert docs[2]["_id"] == "ghi" assert docs[2]["_source"] == { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "description": "Rabbits on the run", "isbn": "ghi", "rating": {"id": 3, "value": 3.3}, @@ -163,7 +163,7 @@ def test_relationship_object_one_to_many(self, sync, data): assert docs[0]["_id"] == "abc" assert docs[0]["_source"] == { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "description": "Tigers are fierce creatures", "isbn": "abc", "rating": [{"id": 1, "value": 1.1}], @@ -172,7 +172,7 @@ def test_relationship_object_one_to_many(self, sync, data): assert docs[1]["_id"] == "def" assert docs[1]["_source"] == { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "description": "Lion and the mouse", "isbn": "def", "rating": [{"id": 2, "value": 2.2}], @@ -181,7 +181,7 @@ def test_relationship_object_one_to_many(self, sync, data): assert docs[2]["_id"] == "ghi" assert docs[2]["_source"] == { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "description": "Rabbits on the run", "isbn": "ghi", "rating": [{"id": 3, "value": 3.3}], @@ -208,7 +208,7 @@ def test_relationship_scalar_one_to_one(self, sync, data): docs = [sort_list(doc) for doc in sync.sync()] assert docs[0]["_id"] == "abc" assert docs[0]["_source"] == { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "description": "Tigers are fierce creatures", "isbn": "abc", "rating": 1.1, @@ -217,7 +217,7 @@ def test_relationship_scalar_one_to_one(self, sync, data): assert docs[1]["_id"] == "def" assert docs[1]["_source"] == { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "description": "Lion and the mouse", "isbn": "def", "rating": 2.2, @@ -226,7 +226,7 @@ def test_relationship_scalar_one_to_one(self, sync, data): assert docs[2]["_id"] == "ghi" assert docs[2]["_source"] == { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "description": "Rabbits on the run", "isbn": "ghi", "rating": 3.3, @@ -254,7 +254,7 @@ def test_relationship_scalar_one_to_many(self, sync, data): docs = sorted(docs, key=lambda k: k["_id"]) assert docs[0]["_id"] == "abc" assert docs[0]["_source"] == { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "description": "Tigers are fierce creatures", "isbn": "abc", "rating": [1.1], @@ -263,7 +263,7 @@ def test_relationship_scalar_one_to_many(self, sync, data): assert docs[1]["_id"] == "def" assert docs[1]["_source"] == { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "description": "Lion and the mouse", "isbn": "def", "rating": [2.2], @@ -272,7 +272,7 @@ def test_relationship_scalar_one_to_many(self, sync, data): assert docs[2]["_id"] == "ghi" assert docs[2]["_source"] == { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "description": "Rabbits on the run", "isbn": "ghi", "rating": [3.3], @@ -300,7 +300,7 @@ def test_label(self, sync, data): docs = [sort_list(doc) for doc in sync.sync()] assert docs[0]["_id"] == "abc" assert docs[0]["_source"] == { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "description": "Tigers are fierce creatures", "isbn": "abc", "rating_x": 1.1, @@ -309,7 +309,7 @@ def test_label(self, sync, data): assert docs[1]["_id"] == "def" assert docs[1]["_source"] == { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "description": "Lion and the mouse", "isbn": "def", "rating_x": 2.2, @@ -318,7 +318,7 @@ def test_label(self, sync, data): assert docs[2]["_id"] == "ghi" assert docs[2]["_source"] == { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "description": "Rabbits on the run", "isbn": "ghi", "rating_x": 3.3, @@ -347,7 +347,7 @@ def test_null_label(self, sync, data): docs = [sort_list(doc) for doc in sync.sync()] assert docs[0]["_id"] == "abc" assert docs[0]["_source"] == { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "description": "Tigers are fierce creatures", "isbn": "abc", "rating": 1.1, @@ -382,7 +382,7 @@ def test_transform(self, sync, data): assert docs[0]["_id"] == "abc" assert docs[0]["_source"] == { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "book_isbn": "abc", "book_title": "The Tiger Club", "description": "Tigers are fierce creatures", @@ -390,7 +390,7 @@ def test_transform(self, sync, data): } assert docs[1]["_id"] == "def" assert docs[1]["_source"] == { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "book_isbn": "def", "book_title": "The Lion Club", "description": "Lion and the mouse", @@ -399,7 +399,7 @@ def test_transform(self, sync, data): assert docs[2]["_id"] == "ghi" assert docs[2]["_source"] == { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "book_isbn": "ghi", "book_title": "The Rabbit Club", "description": "Rabbits on the run", @@ -452,7 +452,7 @@ def test_schema_with_no_column_specified(self, sync, data): sync.tree = Tree(sync.models, nodes) docs = [sort_list(doc) for doc in sync.sync()] assert docs[2]["_source"] == { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "copyright": None, "description": "Rabbits on the run", "isbn": "ghi", @@ -534,9 +534,18 @@ def test_meta_keys(self, sync, data): sync.tree = Tree(sync.models, nodes) docs = [sort_list(doc) for doc in sync.sync()] sources = {doc["_id"]: doc["_source"] for doc in docs} - assert sources["abc"]["_meta"] == {"rating": {"id": [1]}} - assert sources["def"]["_meta"] == {"rating": {"id": [2]}} - assert sources["ghi"]["_meta"] == {"rating": {"id": [3]}} + assert sources["abc"]["_meta"] == { + "book": {"isbn": ["abc"]}, + "rating": {"id": [1]}, + } + assert sources["def"]["_meta"] == { + "book": {"isbn": ["def"]}, + "rating": {"id": [2]}, + } + assert sources["ghi"]["_meta"] == { + "book": {"isbn": ["ghi"]}, + "rating": {"id": [3]}, + } assert_resync_empty(sync, nodes) def test_missing_foreign_keys(self, sync, data): @@ -602,19 +611,19 @@ def test_update_primary_key_non_concurrent( assert docs == [ { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "isbn": "abc", "rating": {"id": 1, "value": 1.1}, "title": "The Tiger Club", }, { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "isbn": "def", "rating": {"id": 2, "value": 2.2}, "title": "The Lion Club", }, { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "isbn": "ghi", "rating": {"id": 3, "value": 3.3}, "title": "The Rabbit Club", @@ -644,25 +653,25 @@ def test_update_primary_key_non_concurrent( docs = search(sync.search_client, "testdb") assert docs == [ { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "isbn": "abc", "rating": {"id": 1, "value": 1.1}, "title": "The Tiger Club", }, { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "isbn": "def", "rating": {"id": 2, "value": 2.2}, "title": "The Lion Club", }, { - "_meta": {}, + "_meta": {"book": {"isbn": ["ghi"]}}, "isbn": "ghi", "rating": None, "title": "The Rabbit Club", }, { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["xyz"]}, "rating": {"id": [3]}}, "isbn": "xyz", "rating": {"id": 3, "value": 3.3}, "title": "Milli and the Ants", @@ -700,19 +709,19 @@ def test_update_primary_key_concurrent(self, data, book_cls, rating_cls): assert docs == [ { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "isbn": "abc", "rating": {"id": 1, "value": 1.1}, "title": "The Tiger Club", }, { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "isbn": "def", "rating": {"id": 2, "value": 2.2}, "title": "The Lion Club", }, { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "isbn": "ghi", "rating": {"id": 3, "value": 3.3}, "title": "The Rabbit Club", @@ -764,25 +773,25 @@ def poll_db(): docs = search(sync.search_client, "testdb") assert docs == [ { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "isbn": "abc", "rating": {"id": 1, "value": 1.1}, "title": "The Tiger Club", }, { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "isbn": "def", "rating": {"id": 2, "value": 2.2}, "title": "The Lion Club", }, { - "_meta": {}, + "_meta": {"book": {"isbn": ["ghi"]}}, "isbn": "ghi", "rating": None, "title": "The Rabbit Club", }, { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["xyz"]}, "rating": {"id": [3]}}, "isbn": "xyz", "rating": {"id": 3, "value": 3.3}, "title": "Milli and the Ants", @@ -820,19 +829,19 @@ def test_insert_non_concurrent(self, data, book_cls, rating_cls): docs = search(sync.search_client, "testdb") assert docs == [ { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "isbn": "abc", "rating": {"id": 1, "value": 1.1}, "title": "The Tiger Club", }, { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "isbn": "def", "rating": {"id": 2, "value": 2.2}, "title": "The Lion Club", }, { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "isbn": "ghi", "rating": {"id": 3, "value": 3.3}, "title": "The Rabbit Club", @@ -865,25 +874,25 @@ def test_insert_non_concurrent(self, data, book_cls, rating_cls): assert docs == [ { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "isbn": "abc", "rating": {"id": 1, "value": 1.1}, "title": "The Tiger Club", }, { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "isbn": "def", "rating": {"id": 2, "value": 2.2}, "title": "The Lion Club", }, { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "isbn": "ghi", "rating": {"id": 3, "value": 3.3}, "title": "The Rabbit Club", }, { - "_meta": {"rating": {"id": [99]}}, + "_meta": {"book": {"isbn": ["xyz"]}, "rating": {"id": [99]}}, "isbn": "xyz", "rating": {"id": 99, "value": 4.4}, "title": "Encyclopedia", @@ -922,19 +931,19 @@ def test_update_non_primary_key_non_concurrent( assert docs == [ { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "isbn": "abc", "rating": {"id": 1, "value": 1.1}, "title": "The Tiger Club", }, { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "isbn": "def", "rating": {"id": 2, "value": 2.2}, "title": "The Lion Club", }, { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "isbn": "ghi", "rating": {"id": 3, "value": 3.3}, "title": "The Rabbit Club", @@ -961,19 +970,19 @@ def test_update_non_primary_key_non_concurrent( assert docs == [ { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "isbn": "abc", "rating": {"id": 1, "value": 1.1}, "title": "The Tiger Club", }, { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "isbn": "def", "rating": {"id": 2, "value": 2.2}, "title": "The Lion Club", }, { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "isbn": "ghi", "rating": {"id": 3, "value": 4.4}, "title": "The Rabbit Club", @@ -1012,19 +1021,19 @@ def test_update_non_primary_key_concurrent( assert docs == [ { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "isbn": "abc", "rating": {"id": 1, "value": 1.1}, "title": "The Tiger Club", }, { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "isbn": "def", "rating": {"id": 2, "value": 2.2}, "title": "The Lion Club", }, { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "isbn": "ghi", "rating": {"id": 3, "value": 3.3}, "title": "The Rabbit Club", @@ -1068,19 +1077,19 @@ def poll_db(): assert docs == [ { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "isbn": "abc", "rating": {"id": 1, "value": 1.1}, "title": "The Tiger Club", }, { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "isbn": "def", "rating": {"id": 2, "value": 2.2}, "title": "The Lion Club", }, { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "isbn": "ghi", "rating": {"id": 3, "value": 4.4}, "title": "The Rabbit Club", @@ -1118,19 +1127,19 @@ def test_delete_concurrent(self, data, book_cls, rating_cls): assert docs == [ { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "isbn": "abc", "rating": {"id": 1, "value": 1.1}, "title": "The Tiger Club", }, { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "isbn": "def", "rating": {"id": 2, "value": 2.2}, "title": "The Lion Club", }, { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "rating": {"id": [3]}}, "isbn": "ghi", "rating": {"id": 3, "value": 3.3}, "title": "The Rabbit Club", @@ -1187,19 +1196,19 @@ def poll_db(): docs = search(sync.search_client, "testdb") assert docs == [ { - "_meta": {"rating": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "rating": {"id": [1]}}, "isbn": "abc", "rating": {"id": 1, "value": 1.1}, "title": "The Tiger Club", }, { - "_meta": {"rating": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "rating": {"id": [2]}}, "isbn": "def", "rating": {"id": 2, "value": 2.2}, "title": "The Lion Club", }, { - "_meta": {"rating": {"id": [3]}}, + "_meta": {"book": {"isbn": ["xyz"]}, "rating": {"id": [3]}}, "isbn": "xyz", "rating": {"id": 3, "value": 3.3}, "title": "The End of time", diff --git a/tests/test_sync_single_child_fk_on_parent.py b/tests/test_sync_single_child_fk_on_parent.py index 6490183..9ba7bb1 100644 --- a/tests/test_sync_single_child_fk_on_parent.py +++ b/tests/test_sync_single_child_fk_on_parent.py @@ -107,7 +107,7 @@ def test_relationship_object_one_to_one(self, sync, data): docs = [sort_list(doc) for doc in sync.sync()] assert docs[0]["_id"] == "abc" assert docs[0]["_source"] == { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "description": "Tigers are fierce creatures", "isbn": "abc", "publisher": {"id": 1, "name": "Tiger publishing"}, @@ -116,7 +116,7 @@ def test_relationship_object_one_to_one(self, sync, data): assert docs[1]["_id"] == "def" assert docs[1]["_source"] == { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "description": "Lion and the mouse", "isbn": "def", "publisher": {"id": 2, "name": "Lion publishing"}, @@ -125,7 +125,7 @@ def test_relationship_object_one_to_one(self, sync, data): assert docs[2]["_id"] == "ghi" assert docs[2]["_source"] == { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "description": "Rabbits on the run", "isbn": "ghi", "publisher": {"id": 3, "name": "Hop Bunny publishing"}, @@ -154,7 +154,7 @@ def test_relationship_object_one_to_many(self, sync, data): assert docs[0]["_id"] == "abc" assert docs[0]["_source"] == { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "description": "Tigers are fierce creatures", "isbn": "abc", "publisher": [{"id": 1, "name": "Tiger publishing"}], @@ -163,7 +163,7 @@ def test_relationship_object_one_to_many(self, sync, data): assert docs[1]["_id"] == "def" assert docs[1]["_source"] == { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "description": "Lion and the mouse", "isbn": "def", "publisher": [{"id": 2, "name": "Lion publishing"}], @@ -172,7 +172,7 @@ def test_relationship_object_one_to_many(self, sync, data): assert docs[2]["_id"] == "ghi" assert docs[2]["_source"] == { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "description": "Rabbits on the run", "isbn": "ghi", "publisher": [{"id": 3, "name": "Hop Bunny publishing"}], @@ -199,7 +199,7 @@ def test_relationship_scalar_one_to_one(self, sync, data): docs = [sort_list(doc) for doc in sync.sync()] assert docs[0]["_id"] == "abc" assert docs[0]["_source"] == { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "description": "Tigers are fierce creatures", "isbn": "abc", "publisher": "Tiger publishing", @@ -208,7 +208,7 @@ def test_relationship_scalar_one_to_one(self, sync, data): assert docs[1]["_id"] == "def" assert docs[1]["_source"] == { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "description": "Lion and the mouse", "isbn": "def", "publisher": "Lion publishing", @@ -217,7 +217,7 @@ def test_relationship_scalar_one_to_one(self, sync, data): assert docs[2]["_id"] == "ghi" assert docs[2]["_source"] == { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "description": "Rabbits on the run", "isbn": "ghi", "publisher": "Hop Bunny publishing", @@ -245,7 +245,7 @@ def test_relationship_scalar_one_to_many(self, sync, data): docs = sorted(docs, key=lambda k: k["_id"]) assert docs[0]["_id"] == "abc" assert docs[0]["_source"] == { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "description": "Tigers are fierce creatures", "isbn": "abc", "publisher": ["Tiger publishing"], @@ -254,7 +254,7 @@ def test_relationship_scalar_one_to_many(self, sync, data): assert docs[1]["_id"] == "def" assert docs[1]["_source"] == { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "description": "Lion and the mouse", "isbn": "def", "publisher": ["Lion publishing"], @@ -263,7 +263,7 @@ def test_relationship_scalar_one_to_many(self, sync, data): assert docs[2]["_id"] == "ghi" assert docs[2]["_source"] == { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "description": "Rabbits on the run", "isbn": "ghi", "publisher": ["Hop Bunny publishing"], @@ -291,7 +291,7 @@ def test_label(self, sync, data): docs = [sort_list(doc) for doc in sync.sync()] assert docs[0]["_id"] == "abc" assert docs[0]["_source"] == { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "description": "Tigers are fierce creatures", "isbn": "abc", "publisher_x": "Tiger publishing", @@ -300,7 +300,7 @@ def test_label(self, sync, data): assert docs[1]["_id"] == "def" assert docs[1]["_source"] == { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "description": "Lion and the mouse", "isbn": "def", "publisher_x": "Lion publishing", @@ -309,7 +309,7 @@ def test_label(self, sync, data): assert docs[2]["_id"] == "ghi" assert docs[2]["_source"] == { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "description": "Rabbits on the run", "isbn": "ghi", "publisher_x": "Hop Bunny publishing", @@ -338,7 +338,7 @@ def test_null_label(self, sync, data): docs = [sort_list(doc) for doc in sync.sync()] assert docs[0]["_id"] == "abc" assert docs[0]["_source"] == { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "description": "Tigers are fierce creatures", "isbn": "abc", "publisher": "Tiger publishing", @@ -375,7 +375,7 @@ def test_transform(self, sync, data): docs = [sort_list(doc) for doc in sync.sync()] assert docs[0]["_id"] == "abc" assert docs[0]["_source"] == { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "book_isbn": "abc", "book_title": "The Tiger Club", "description": "Tigers are fierce creatures", @@ -387,7 +387,7 @@ def test_transform(self, sync, data): assert docs[1]["_id"] == "def" assert docs[1]["_source"] == { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "book_isbn": "def", "book_title": "The Lion Club", "description": "Lion and the mouse", @@ -399,7 +399,7 @@ def test_transform(self, sync, data): assert docs[2]["_id"] == "ghi" assert docs[2]["_source"] == { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "book_isbn": "ghi", "book_title": "The Rabbit Club", "description": "Rabbits on the run", @@ -455,7 +455,7 @@ def test_schema_with_no_column_specified(self, sync, data): sync.tree = Tree(sync.models, nodes) docs = [sort_list(doc) for doc in sync.sync()] assert docs[2]["_source"] == { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "copyright": None, "description": "Rabbits on the run", "isbn": "ghi", @@ -540,9 +540,18 @@ def test_meta_keys(self, sync, data): sync.tree = Tree(sync.models, nodes) docs = [sort_list(doc) for doc in sync.sync()] sources = {doc["_id"]: doc["_source"] for doc in docs} - assert sources["abc"]["_meta"] == {"publisher": {"id": [1]}} - assert sources["def"]["_meta"] == {"publisher": {"id": [2]}} - assert sources["ghi"]["_meta"] == {"publisher": {"id": [3]}} + assert sources["abc"]["_meta"] == { + "book": {"isbn": ["abc"]}, + "publisher": {"id": [1]}, + } + assert sources["def"]["_meta"] == { + "book": {"isbn": ["def"]}, + "publisher": {"id": [2]}, + } + assert sources["ghi"]["_meta"] == { + "book": {"isbn": ["ghi"]}, + "publisher": {"id": [3]}, + } assert_resync_empty(sync, nodes) def test_missing_foreign_keys(self, sync, data): @@ -608,19 +617,19 @@ def test_update_primary_key_non_concurrent( assert docs == [ { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "isbn": "abc", "publisher": {"id": 1, "name": "Tiger publishing"}, "title": "The Tiger Club", }, { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "isbn": "def", "publisher": {"id": 2, "name": "Lion publishing"}, "title": "The Lion Club", }, { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "isbn": "ghi", "publisher": {"id": 3, "name": "Hop Bunny publishing"}, "title": "The Rabbit Club", @@ -651,19 +660,22 @@ def test_update_primary_key_non_concurrent( assert docs == [ { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "isbn": "abc", "publisher": {"id": 1, "name": "Tiger publishing"}, "title": "The Tiger Club", }, { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "isbn": "def", "publisher": {"id": 2, "name": "Lion publishing"}, "title": "The Lion Club", }, { - "_meta": {"publisher": {"id": [99]}}, + "_meta": { + "book": {"isbn": ["ghi"]}, + "publisher": {"id": [99]}, + }, "isbn": "ghi", "publisher": {"id": 99, "name": "Rabbit publishers"}, "title": "The Rabbit Club", @@ -704,19 +716,19 @@ def test_update_primary_key_concurrent( assert docs == [ { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "isbn": "abc", "publisher": {"id": 1, "name": "Tiger publishing"}, "title": "The Tiger Club", }, { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "isbn": "def", "publisher": {"id": 2, "name": "Lion publishing"}, "title": "The Lion Club", }, { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "isbn": "ghi", "publisher": {"id": 3, "name": "Hop Bunny publishing"}, "title": "The Rabbit Club", @@ -768,19 +780,22 @@ def poll_db(): assert docs == [ { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "isbn": "abc", "publisher": {"id": 1, "name": "Tiger publishing"}, "title": "The Tiger Club", }, { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "isbn": "def", "publisher": {"id": 2, "name": "Lion publishing"}, "title": "The Lion Club", }, { - "_meta": {"publisher": {"id": [99]}}, + "_meta": { + "book": {"isbn": ["ghi"]}, + "publisher": {"id": [99]}, + }, "isbn": "ghi", "publisher": {"id": 99, "name": "Rabbit publishers"}, "title": "The Rabbit Club", @@ -818,19 +833,19 @@ def test_insert_non_concurrent(self, data, book_cls, publisher_cls): docs = search(sync.search_client, "testdb") assert docs == [ { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "isbn": "abc", "publisher": {"id": 1, "name": "Tiger publishing"}, "title": "The Tiger Club", }, { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "isbn": "def", "publisher": {"id": 2, "name": "Lion publishing"}, "title": "The Lion Club", }, { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "isbn": "ghi", "publisher": {"id": 3, "name": "Hop Bunny publishing"}, "title": "The Rabbit Club", @@ -860,25 +875,28 @@ def test_insert_non_concurrent(self, data, book_cls, publisher_cls): assert docs == [ { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "isbn": "abc", "publisher": {"id": 1, "name": "Tiger publishing"}, "title": "The Tiger Club", }, { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "isbn": "def", "publisher": {"id": 2, "name": "Lion publishing"}, "title": "The Lion Club", }, { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "isbn": "ghi", "publisher": {"id": 3, "name": "Hop Bunny publishing"}, "title": "The Rabbit Club", }, { - "_meta": {"publisher": {"id": [99]}}, + "_meta": { + "book": {"isbn": ["xyz"]}, + "publisher": {"id": [99]}, + }, "isbn": "xyz", "publisher": {"id": 99, "name": "Rabbit publishers"}, "title": "Encyclopedia", @@ -917,19 +935,19 @@ def test_update_non_primary_key_non_concurrent( assert docs == [ { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "isbn": "abc", "publisher": {"id": 1, "name": "Tiger publishing"}, "title": "The Tiger Club", }, { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "isbn": "def", "publisher": {"id": 2, "name": "Lion publishing"}, "title": "The Lion Club", }, { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "isbn": "ghi", "publisher": {"id": 3, "name": "Hop Bunny publishing"}, "title": "The Rabbit Club", @@ -956,19 +974,19 @@ def test_update_non_primary_key_non_concurrent( assert docs == [ { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "isbn": "abc", "publisher": {"id": 1, "name": "Tiger publishing"}, "title": "The Tiger Club", }, { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "isbn": "def", "publisher": {"id": 2, "name": "Lion publishing"}, "title": "The Lion Club", }, { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "isbn": "ghi", "publisher": {"id": 3, "name": "Rabbit publishers"}, "title": "The Rabbit Club", @@ -1007,19 +1025,19 @@ def test_update_non_primary_key_concurrent( assert docs == [ { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "isbn": "abc", "publisher": {"id": 1, "name": "Tiger publishing"}, "title": "The Tiger Club", }, { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "isbn": "def", "publisher": {"id": 2, "name": "Lion publishing"}, "title": "The Lion Club", }, { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "isbn": "ghi", "publisher": {"id": 3, "name": "Hop Bunny publishing"}, "title": "The Rabbit Club", @@ -1063,19 +1081,19 @@ def poll_db(): assert docs == [ { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "isbn": "abc", "publisher": {"id": 1, "name": "Tiger publishing"}, "title": "The Tiger Club", }, { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "isbn": "def", "publisher": {"id": 2, "name": "Lion publishing"}, "title": "The Lion Club", }, { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "isbn": "ghi", "publisher": {"id": 3, "name": "Rabbit publishers"}, "title": "The Rabbit Club", @@ -1113,19 +1131,19 @@ def test_delete_concurrent(self, data, book_cls, publisher_cls): assert docs == [ { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "isbn": "abc", "publisher": {"id": 1, "name": "Tiger publishing"}, "title": "The Tiger Club", }, { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "isbn": "def", "publisher": {"id": 2, "name": "Lion publishing"}, "title": "The Lion Club", }, { - "_meta": {"publisher": {"id": [3]}}, + "_meta": {"book": {"isbn": ["ghi"]}, "publisher": {"id": [3]}}, "isbn": "ghi", "publisher": {"id": 3, "name": "Hop Bunny publishing"}, "title": "The Rabbit Club", @@ -1182,19 +1200,22 @@ def poll_db(): assert docs == [ { - "_meta": {"publisher": {"id": [1]}}, + "_meta": {"book": {"isbn": ["abc"]}, "publisher": {"id": [1]}}, "isbn": "abc", "publisher": {"id": 1, "name": "Tiger publishing"}, "title": "The Tiger Club", }, { - "_meta": {"publisher": {"id": [2]}}, + "_meta": {"book": {"isbn": ["def"]}, "publisher": {"id": [2]}}, "isbn": "def", "publisher": {"id": 2, "name": "Lion publishing"}, "title": "The Lion Club", }, { - "_meta": {"publisher": {"id": [99]}}, + "_meta": { + "book": {"isbn": ["ghi"]}, + "publisher": {"id": [99]}, + }, "isbn": "ghi", "publisher": {"id": 99, "name": "Rabbit publishers"}, "title": "The Rabbit Club", diff --git a/tests/test_unique_behaviour.py b/tests/test_unique_behaviour.py index 2d24499..637ff93 100644 --- a/tests/test_unique_behaviour.py +++ b/tests/test_unique_behaviour.py @@ -220,6 +220,7 @@ def test_sync_multiple_children_empty_leaf( "_index": "testdb", "_source": { "_meta": { + "book": {"isbn": ["abc"]}, "contact": {"id": [1, 2]}, "user": {"id": [1, 2]}, },