def api(): """Create shared XYZ Token API instance as a pytest fixture.""" try: api = TokenApi(config=XYZConfig.from_default()) except AuthenticationError: api = TokenApi() warnings.warn("Ignoring invalid credentials, creating TokenApi " "instance without. Access limitations may apply.") return api
def test_config_from_file(): """Test configurations using file.""" root = Path(__file__).parent.parent.parent file_path = (root / Path("docs") / Path("notebooks") / Path("data") / "xyz_configuration.conf") xyzconfig = XYZConfig.from_file(file_path) assert xyzconfig.config["credentials"]["XYZ_TOKEN"] == "MY-XYZ-TOKEN" assert xyzconfig.config["url"] == "https://xyz.api.here.com" assert (xyzconfig.config["http_headers"]["Authorization"] == "Bearer MY-XYZ-TOKEN") assert (xyzconfig.config["http_headers"]["Content-Type"] == "application/geo+json")
def test_default_config(): """Test default config.""" xyzconfig = XYZConfig.from_default() assert xyzconfig.config["credentials"]["XYZ_TOKEN"] == os.environ.get( "XYZ_TOKEN") assert xyzconfig.config["credentials"]["HERE_USER"] == os.environ.get( "HERE_USER") assert xyzconfig.config["credentials"]["HERE_PASSWORD"] == os.environ.get( "HERE_PASSWORD") assert xyzconfig.config["url"] == "https://xyz.api.here.com" assert (xyzconfig.config["http_headers"]["Authorization"] == f"Bearer {os.environ.get('XYZ_TOKEN')}") assert (xyzconfig.config["http_headers"]["Content-Type"] == "application/geo+json")
def test_config_object(): """Test configurations using config object.""" xyzconfig = XYZConfig(**DEFAULT_CONFIG) assert xyzconfig.config["credentials"]["XYZ_TOKEN"] == os.environ.get( "XYZ_TOKEN") assert xyzconfig.config["credentials"]["HERE_USER"] == os.environ.get( "HERE_USER") assert xyzconfig.config["credentials"]["HERE_PASSWORD"] == os.environ.get( "HERE_PASSWORD") assert xyzconfig.config["url"] == "https://xyz.api.here.com" assert (xyzconfig.config["http_headers"]["Authorization"] == f"Bearer {os.environ.get('XYZ_TOKEN')}") assert (xyzconfig.config["http_headers"]["Content-Type"] == "application/geo+json")
def point_space_id(): """Create shared XYZ space with Chicago Parks data.""" api = HubApi(config=XYZConfig.from_default()) # setup, create temporary space res = api.post_space( data={ "title": "Testing xyzspaces", "description": "Temporary space containing Chicago Parks data", }) space_id = res["id"] gj_chicago_parks = get_chicago_parks_data() sleep(0.5) api.put_space_features(space_id=space_id, data=gj_chicago_parks) yield space_id # now teardown (delete temporary space) api.delete_space(space_id=space_id)
def space_id(): """Create shared XYZ space with countries data as a pytest fixture.""" api = HubApi(config=XYZConfig.from_default()) # 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)
def api(): """Create shared XYZ Project Api instance as a pytest fixture.""" api = ProjectApi(config=XYZConfig.from_default()) return api