def test_load_countries(): """Load countries dataset.""" gj_countries = get_countries_data() keys = gj_countries.keys() assert "type" in keys assert "features" in keys assert len(gj_countries["features"]) == 180 datasets_home = Path(xyzspaces.datasets.__file__).parent url_countries = ("https://raw.githubusercontent.com" "/johan/world.geo.json/master/countries.geo.json") fn_countries = datasets_home / Path(url_countries).name try: fn_countries.unlink() except OSError: pass assert not fn_countries.exists() gj_countries = get_countries_data()
def space_id(): """Create shared XYZ space with countries data as a pytest fixture.""" api = HubApi(credentials=XYZ_TOKEN) # setup, create temporary space res = api.post_space( data={ "title": "Testing xyzspaces", "description": "Temporary space containing countries data.", }) space_id = res["id"] # add features to space gj_countries = get_countries_data() sleep(0.5) api.put_space_features(space_id=space_id, data=gj_countries) yield space_id # now teardown (delete temporary space) api.delete_space(space_id=space_id)
"""Module for testing xyzspaces.spaces.""" import json from pathlib import Path import pytest from geojson import GeoJSON from xyzspaces import XYZ from xyzspaces.datasets import get_chicago_parks_data, get_countries_data from xyzspaces.exceptions import ApiError from xyzspaces.spaces import Space from xyzspaces.utils import get_xyz_token XYZ_TOKEN = get_xyz_token() gj_countries = get_countries_data() gj_chicago_parks = get_chicago_parks_data() @pytest.mark.skipif(not XYZ_TOKEN, reason="No token found.") 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) @pytest.mark.skipif(not XYZ_TOKEN, reason="No token found.") def test_new_space(): """Test create and delete a new space.""" # create space space = Space.new(title="Foo", description="Bar")