Skip to content

Commit

Permalink
Added layer tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kharude, Sachin <sachin.kharude@here.com>
  • Loading branch information
Kharude, Sachin committed Jul 29, 2021
1 parent f37b32c commit 8da0abc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
22 changes: 22 additions & 0 deletions tests/iml/test_iml.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# License-Filename: LICENSE
"""This module will test functionality in IML class."""

import json
from pathlib import Path
from time import sleep

Expand Down Expand Up @@ -96,3 +97,24 @@ def test_catalog_lifecycle():
iml.layer.update_feature(feature_id="test-delete", data=feature)
sleep(1)
iml.layer.delete_feature(feature_id="test-delete")
# Add new layer to the catalog.
layer2 = {
"id": "countries-test2",
"name": "countries-test2",
"summary": "Borders of world countries second layer.",
"description": "Borders of world countries.",
"layerType": "interactivemap",
"interactiveMapProperties": {},
}
iml.add_interactive_map_layer(
catalog_hrn="hrn:here:data::olp-here:test-catalog-iml-remove",
layer_details=layer2,
credentials=cred,
)
assert iml.layer.id == "countries-test2"
with open(file_path) as fh:
countries_data = json.load(fh)
iml.layer.write_features(features=countries_data)
assert iml.layer.statistics["count"]["value"] == 179
iml.layer.delete_features(feature_ids=["IND", "USA", "DEU"])
assert iml.layer.statistics["count"]["value"] == 176
20 changes: 15 additions & 5 deletions tests/iml/test_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from geojson import Feature, FeatureCollection, Point

from tests.iml.conftest import env_setup_done
from xyzspaces.iml.layer import HexbinClustering

# Read operation on layer.

Expand All @@ -29,6 +30,7 @@ def test_statistics(read_layer):
"""Test statistics of interactive map layer."""
stats = read_layer.statistics
assert stats["count"]["value"] == 179
assert str(read_layer) == "layer_id: countries"


@pytest.mark.skipif(not env_setup_done(), reason="Credentials are not setup in env.")
Expand Down Expand Up @@ -62,7 +64,10 @@ def test_get_features(read_layer):
@pytest.mark.skipif(not env_setup_done(), reason="Credentials are not setup in env.")
def test_search_features(read_layer):
"""Test search features."""
int_resp = read_layer.search_features(params={"p.name": "India"})
int_resp = read_layer.search_features(
params={"p.name": "India"},
selection=["name"],
)
fc = int_resp.to_geojson()
assert isinstance(fc, FeatureCollection)
assert fc["features"][0]["id"] == "IND"
Expand All @@ -71,16 +76,19 @@ def test_search_features(read_layer):
@pytest.mark.skipif(not env_setup_done(), reason="Credentials are not setup in env.")
def test_iter_feature(read_layer):
"""Test iter features"""
itr = read_layer.iter_features()
itr = read_layer.iter_features(selection=["name"])
feature = next(itr)
assert isinstance(feature, Feature)


@pytest.mark.skipif(not env_setup_done(), reason="Credentials are not setup in env.")
def test_get_features_in_bounding_box(read_layer):
"""Test features in bounding box."""
clustering = HexbinClustering()
int_resp = read_layer.get_features_in_bounding_box(
bounds=(68.1766451354, 7.96553477623, 97.4025614766, 35.4940095078)
bounds=(68.1766451354, 7.96553477623, 97.4025614766, 35.4940095078),
clustering=clustering,
selection=["name"],
)
fc = int_resp.to_geojson()
assert isinstance(fc, FeatureCollection)
Expand All @@ -89,7 +97,7 @@ def test_get_features_in_bounding_box(read_layer):
@pytest.mark.skipif(not env_setup_done(), reason="Credentials are not setup in env.")
def test_spatial_search(read_layer):
"""Test spatial search."""
int_resp = read_layer.spatial_search(lng=73, lat=19, radius=1000)
int_resp = read_layer.spatial_search(lng=73, lat=19, radius=1000, selection=["name"])
fc = int_resp.to_geojson()
assert fc["features"][0]["id"] == "IND"

Expand All @@ -99,6 +107,8 @@ def test_spatial_search_geometry(read_layer):
"""Test spatial search using geometry."""
pt = Point((73, 19))
feature = Feature(geometry=pt)
int_resp = read_layer.spatial_search_geometry(geometry=feature, radius=1000)
int_resp = read_layer.spatial_search_geometry(
geometry=feature, radius=1000, selection=["name"]
)
fc = int_resp.to_geojson()
assert fc["features"][0]["id"] == "IND"

0 comments on commit 8da0abc

Please sign in to comment.