-
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.
test case to validate with two level in json object
- Loading branch information
1 parent
e77e2e6
commit 9d0ae54
Showing
1 changed file
with
71 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
|
||
def test_single_object(): | ||
"""test write to single object""" | ||
"""test generation of entities and schema for a simple JSON object.""" | ||
test_data = """ | ||
{ | ||
"name": "sai", | ||
|
@@ -29,7 +29,8 @@ def test_single_object(): | |
|
||
|
||
def test_single_object_one_level(): | ||
"""test write to single object with one level""" | ||
"""test generation of entities and schema for a JSON object with one level of | ||
hierarchy""" | ||
test_data = """ | ||
{ | ||
"name": "sai", | ||
|
@@ -70,7 +71,8 @@ def test_single_object_one_level(): | |
|
||
|
||
def test_single_object_one_level_array(): | ||
"""test write to single object with array in first level""" | ||
"""test generation of entities and schema for a JSON object with array object in | ||
first level of hierarchy""" | ||
test_data = """ | ||
{ | ||
"name": "sai", | ||
|
@@ -112,3 +114,69 @@ def test_single_object_one_level_array(): | |
EntityPath("country", False, is_attribute=True) | ||
] | ||
) | ||
|
||
|
||
def test_single_object_two_level_array(): | ||
"""test generation of entities and schema for a JSON object with two levels of | ||
hierarchy""" | ||
test_data = """ | ||
{ | ||
"name": "sai", | ||
"email": "[email protected]", | ||
"city": [ | ||
{ | ||
"name": "San Francisco", | ||
"country": "United States", | ||
"geo_location": { | ||
"lat": "37.773972", | ||
"long": "-122.431297" | ||
} | ||
}, | ||
{ | ||
"name": "New York", | ||
"country": "United States", | ||
"geo_location": { | ||
"lat": "40.730610", | ||
"long": "-73.935242" | ||
} | ||
} | ||
] | ||
}""" | ||
data = json.loads(test_data) | ||
entities = build_entities_from_data(data) | ||
assert len(list(entities.entities)) == 1 | ||
for _ in entities.entities: | ||
assert len(_.values) == 3 | ||
assert _.values[0:2] == [["sai"], ["[email protected]"]] | ||
assert _.values[2][0].startswith("urn:x-ulid:") | ||
assert len(entities.schema.paths) == 3 | ||
assert entities.schema == EntitySchema( | ||
type_uri="", | ||
paths=[ | ||
EntityPath("name", False, is_attribute=True), | ||
EntityPath("email", False, is_attribute=True), | ||
EntityPath("city", True, is_attribute=False), | ||
] | ||
) | ||
# Validate sub entities | ||
location_entities = entities.sub_entities[0] | ||
city_entities = entities.sub_entities[1] | ||
assert len(list(city_entities.entities)) == 2 | ||
assert len(list(location_entities.entities)) == 2 | ||
|
||
assert city_entities.schema == EntitySchema( | ||
type_uri="", | ||
paths=[ | ||
EntityPath("name", False, is_attribute=True), | ||
EntityPath("country", False, is_attribute=True), | ||
EntityPath("geo_location", True, is_attribute=True), | ||
] | ||
) | ||
|
||
assert location_entities.schema == EntitySchema( | ||
type_uri="", | ||
paths=[ | ||
EntityPath("lat", False, is_attribute=True), | ||
EntityPath("long", False, is_attribute=True), | ||
] | ||
) |