-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee83f2a
commit 1e9a6e7
Showing
5 changed files
with
32 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,25 @@ | |
|
||
import json | ||
|
||
from cmem_plugin_base.dataintegration.entity import EntityPath, EntitySchema | ||
from cmem_plugin_base.dataintegration.entity import EntityPath, EntitySchema, Entities | ||
from cmem_plugin_base.dataintegration.utils.entity_builder import build_entities_from_data | ||
|
||
|
||
def build_entities_from_json(json_data: str) -> Entities: | ||
data = json.loads(json_data) | ||
entities = build_entities_from_data(data) | ||
assert entities is not None | ||
return entities | ||
|
||
|
||
def test_single_object() -> None: | ||
"""Test generation of entities and schema for a simple JSON object.""" | ||
test_data = """ | ||
{ | ||
"name": "sai", | ||
"email": "[email protected]" | ||
}""" | ||
data = json.loads(test_data) | ||
entities = build_entities_from_data(data) | ||
entities = build_entities_from_json(test_data) | ||
assert len(list(entities.entities)) == 1 | ||
for _ in entities.entities: | ||
assert len(_.values) == 2 | ||
|
@@ -42,8 +48,7 @@ def test_single_object_one_level() -> None: | |
"country": "United States" | ||
} | ||
}""" | ||
data = json.loads(test_data) | ||
entities = build_entities_from_data(data) | ||
entities = build_entities_from_json(test_data) | ||
assert len(list(entities.entities)) == 1 | ||
for _ in entities.entities: | ||
assert len(_.values) == 3 | ||
|
@@ -59,6 +64,7 @@ def test_single_object_one_level() -> None: | |
], | ||
) | ||
# Validate sub entities | ||
assert entities.sub_entities is not None | ||
for _ in entities.sub_entities: | ||
for _entity in _.entities: | ||
assert len(_entity.values) == 2 | ||
|
@@ -89,8 +95,7 @@ def test_single_object_one_level_array() -> None: | |
"country": "United States" | ||
}] | ||
}""" | ||
data = json.loads(test_data) | ||
entities = build_entities_from_data(data) | ||
entities = build_entities_from_json(test_data) | ||
assert len(list(entities.entities)) == 1 | ||
for _ in entities.entities: | ||
assert len(_.values) == 3 | ||
|
@@ -106,6 +111,7 @@ def test_single_object_one_level_array() -> None: | |
], | ||
) | ||
# Validate sub entities | ||
assert entities.sub_entities is not None | ||
for _ in entities.sub_entities: | ||
assert len(list(_.entities)) == 2 | ||
for _entity in _.entities: | ||
|
@@ -146,8 +152,7 @@ def test_single_object_two_level_array() -> None: | |
} | ||
] | ||
}""" | ||
data = json.loads(test_data) | ||
entities = build_entities_from_data(data) | ||
entities = build_entities_from_json(test_data) | ||
assert len(list(entities.entities)) == 1 | ||
for _ in entities.entities: | ||
assert len(_.values) == 3 | ||
|
@@ -163,6 +168,7 @@ def test_single_object_two_level_array() -> None: | |
], | ||
) | ||
# Validate sub entities | ||
assert entities.sub_entities is not None | ||
location_entities = entities.sub_entities[0] | ||
city_entities = entities.sub_entities[1] | ||
assert len(list(city_entities.entities)) == 2 | ||
|
@@ -196,8 +202,7 @@ def test_array_object() -> None: | |
"name": "sai", | ||
"email": "[email protected]" | ||
}]""" | ||
data = json.loads(test_data) | ||
entities = build_entities_from_data(data) | ||
entities = build_entities_from_json(test_data) | ||
_ = next(entities.entities) | ||
assert len(_.values) == 2 | ||
assert _.values == [["seebi"], [""]] | ||
|