def test_virtual_space_group(upstream_spaces): """Test virtual-space with group operation.""" # Test group operation on upstream spaces. title = "Virtual Space for coutries and chicago parks data" description = "Test group functionality of virtual space" kwargs = {"virtualspace": dict(group=upstream_spaces)} vspace = Space.virtual(title=title, description=description, **kwargs) vpace_stats = vspace.get_statistics() assert set(vpace_stats["geometryTypes"]["value"]) == { "MultiPolygon", "Polygon", "Point", } assert vpace_stats["count"]["value"] == 189 feature1 = vspace.get_feature(feature_id="FRA") assert (feature1["properties"]["@ns:com:here:xyz"]["space"] == upstream_spaces[0]) feature2 = vspace.get_feature(feature_id="LP") assert (feature2["properties"]["@ns:com:here:xyz"]["space"] == upstream_spaces[1]) vspace.delete_feature(feature_id="FRA") with pytest.raises(ApiError): vspace.get_feature("FRA") sp1 = Space.from_id(space_id=upstream_spaces[0]) with pytest.raises(ApiError): sp1.get_feature("FRA") vspace.delete()
def activity_log_space(): """Create a new space supporting activity log.""" listeners = { "id": "activity-log", "params": { "states": 5, "storageMode": "DIFF_ONLY", "writeInvalidatedAt": "true", }, "eventTypes": ["ModifySpaceEvent.request"], } space = Space.new( title="Activity-Log Test", description="A test space for Activity-Log", enable_uuid=True, listeners=listeners, ) sleep(0.5) yield space # now teardown (delete temporary space and activity log space) activity_log_spaceid = space.info["listeners"]["activity-log-writer"][0][ "params" ]["spaceId"] space2 = Space.from_id(activity_log_spaceid) space.delete() space2.delete()
def empty_space(api): """Create shared empty XYZ space as a pytest fixture.""" # setup, create temporary space space = Space(api=api).new( title="Testing xyzspaces", description="Temporary empty space containing no features.", ) sleep(0.5) yield space # now teardown (delete temporary space) space.delete()
def __init__(self, credentials: Optional[str] = None): """Instantiate an XYZ object, optionally with access credentials.""" if credentials: os.environ["XYZ_TOKEN"] = str(credentials) self.hub_api = HubApi(credentials=credentials) else: self.hub_api = HubApi() self.spaces = Space(api=self.hub_api)
def test_virtual_space_custom(space_id, empty_space): """Test virtual-space with custom operation.""" empty_space.add_features(features=gj_countries) title = "Virtual Space to check merge operation" description = "Test merge functionality of virtual space" kwargs = {"virtualspace": {"custom": [space_id, empty_space.info["id"]]}} vspace = Space.virtual(title=title, description=description, **kwargs) # TODO: Add assertions once custom connector is enabled for token. vspace.delete()
def test_virtual_space_merge(space_id, empty_space): """Test virtual-space with a merge operation.""" # Creating duplicate space_id and checking post merge there are no duplicate features. empty_space.add_features(features=gj_countries) title = "Virtual Space to check merge operation" kwargs = {"virtualspace": {"merge": [space_id, empty_space.info["id"]]}} vspace = Space.virtual(title=title, **kwargs) feature = vspace.get_feature(feature_id="FRA") assert feature["properties"]["@ns:com:here:xyz"]["space"] is None vspace.delete()
def test_new_space(): """Test create and delete a new space.""" # create space space = Space.new(title="Foo", description="Bar") assert space.info["title"] == "Foo" space_id = space.info["id"] # delete space space.delete() assert space.info == {} with pytest.raises(ApiError): space.read(id=space_id)
def shared_space(): """Create a new shared space.""" space = Space.new( title="test shared space", description="test shared space", shared=True ) sleep(0.5) yield space # now teardown (delete temporary space) space.delete()
def test_virtual_space_override(space_id, empty_space): """Test virtual-space with override operation.""" # Creating duplicate space_id and checking post override operation on virtual-space # duplicate features from 2nd space in list of upstream spaces get overridden. empty_space.add_features(features=gj_countries) title = "Virtual Space to check merge operation" description = "Test merge functionality of virtual space" kwargs = {"virtualspace": {"override": [space_id, empty_space.info["id"]]}} vspace = Space.virtual(title=title, description=description, **kwargs) feature = vspace.get_feature(feature_id="FRA") assert (feature["properties"]["@ns:com:here:xyz"]["space"] == empty_space.info["id"]) vspace.delete()
def schema_validation_space(): """Create a space with schema validation.""" schema = ( '{"definitions":{},"$schema":"http://json-schema.org/draft-07/schema#",' '"$id":"http://example.com/root.json","type":"object",' '"title":"TheRootSchema","required":["geometry","type","properties"]}') space = Space.new( title="test schema validation space", description="test schema validation space", schema=schema, ) yield space # now teardown (delete temporary space) space.delete()
def __init__(self, config: Optional[XYZConfig] = None): """Instantiate an XYZ object, optionally with custom configuration for your credentials and base URL. :param config: An object of `class:XYZConfig`, If not provied ``XYZ_TOKEN`` will be used from environment variable and other configurations will be used as defined in module :py:mod:`default_config` """ if config: self.hub_api = HubApi(config) else: config = XYZConfig.from_default() self.hub_api = HubApi(config) self.spaces = Space(api=self.hub_api)
def test_create_delete_1(api): """Test create and delete a new space.""" # create space space = Space.new(title="Foo", description="Bar") sleep(0.5) assert space.info["title"] == "Foo" assert "id" in space.info # add features _ = space.add_features(features=gj_countries) # get feature _ = space.get_feature(feature_id="FRA") # delete space space.delete() assert space.info == {}
def test_new_space(): """Test create and delete a new space.""" # create space space = Space.new(title="Foo", description="Bar") sleep(0.5) space_info = space.info assert space_info["title"] == "Foo" assert "shared" not in space_info assert not space.isshared() space_id = space.info["id"] # delete space space.delete() sleep(1) assert space.info == {} with pytest.raises(ApiError): space.read(id=space_id)
def __init__(self, credentials: Optional[str] = None, server: str = XYZ_BASE_URL): """Instantiate an XYZ object, optionally with access credentials and custom base URL. :param credentials: A string to serve as authentication (a bearer token). Will be looked up in environment variable ``XYZ_TOKEN`` if not provided. :param server: A string as base URL for Data Hub APIs. Required only if Data Hub APIs are self-hosted. For self-hosted Data Hub instances ``credentials`` is not required. """ if credentials: os.environ["XYZ_TOKEN"] = str(credentials) self.hub_api = HubApi(credentials=credentials, server=server) else: self.hub_api = HubApi(server=server) self.spaces = Space(api=self.hub_api, server=server)
def test_create_delete_1(api): """Test create and delete a new space.""" # create space space = Space.new(title="Foo", description="Bar") assert space.info["title"] == "Foo" print("created", space.info) id = space.info["id"] assert "id" in space.info # add features res = space.add_features(features=gj_countries) # get feature res = space.get_feature(feature_id="FRA") print(res) # delete space space.delete() print("deleted", id) assert space.info == {}
def large_data_space(): """Create a new large data space.""" space = Space.new( title="test large data space", description="test large data space", shared=True, ) path = Path(__file__).parent.parent / "data" / "large_data.geojson" with open(path) as json_file: data = json.load(json_file) space.add_features(data, features_size=5000, chunk_size=2) sleep(0.5) yield space # now teardown (delete temporary space) space.delete()
def test_get_space_tile_sampling(api): """Get space tile and compare all available sampling rates.""" space = Space.from_id(MICROSOFT_BUILDINGS_SPACE_ID) params = dict( tile_type="web", tile_id="11_585_783", ) tile_raw = list(space.features_in_tile(mode="raw", **params)) tile_viz_off = list( space.features_in_tile(mode="viz", viz_sampling="off", **params)) tile_viz_low = list( space.features_in_tile(mode="viz", viz_sampling="low", **params)) tile_viz_med = list( space.features_in_tile(mode="viz", viz_sampling="med", **params)) tile_viz_high = list( space.features_in_tile(mode="viz", viz_sampling="high", **params)) len_raw = len(tile_raw) len_viz_off = len(tile_viz_off) len_viz_low = len(tile_viz_low) len_viz_med = len(tile_viz_med) len_viz_high = len(tile_viz_high) assert len_raw > len_viz_off >= len_viz_low > len_viz_med >= len_viz_high
def test_create_from_id(api, space_id): """Test create from an existing space ID.""" space = Space.from_id(space_id) assert space.info == api.get_space(space_id=space_id)
def space_object(api, space_id): """Create from an existing space ID.""" space = Space.from_id(space_id) return space
def test__gen_id_from_properties_exception(): """Test exception is raised when feature has no properties.""" space = Space() with pytest.raises(Exception): space._gen_id_from_properties(feature={}, id_properties=[])