def test_ogr_wfs_fake_wfs_server(): if gdaltest.wfs_drv is None: pytest.skip() (process, port) = webserver.launch(handler=WFSHTTPHandler) if port == 0: pytest.skip() gdal.SetConfigOption('OGR_WFS_LOAD_MULTIPLE_LAYER_DEFN', 'NO') ds = ogr.Open("WFS:http://127.0.0.1:%d/fakewfs?OUTPUTFORMAT=application/flatgeobuf" % port) gdal.SetConfigOption('OGR_WFS_LOAD_MULTIPLE_LAYER_DEFN', None) if ds is None: webserver.server_stop(process, port) pytest.fail('did not managed to open WFS datastore') lyr = ds.GetLayerByName('topp:tasmania_water_bodies') if lyr == None: webserver.server_stop(process, port) pytest.fail('did not get expected layer') name = lyr.GetName() if name != 'topp:tasmania_water_bodies': print(name) webserver.server_stop(process, port) pytest.fail('did not get expected layer name (got %s)' % name) feat = lyr.GetNextFeature() if feat.GetField('CONTINENT') != 'Australia' or \ ogrtest.check_feature_geometry(feat, 'MULTIPOLYGON (((146.232727 -42.157501,146.238007 -42.16111,146.24411 -42.169724,146.257202 -42.193329,146.272217 -42.209442,146.274689 -42.214165,146.27832 -42.21833,146.282471 -42.228882,146.282745 -42.241943,146.291351 -42.255836,146.290253 -42.261948,146.288025 -42.267502,146.282471 -42.269997,146.274994 -42.271111,146.266663 -42.270279,146.251373 -42.262505,146.246918 -42.258057,146.241333 -42.256111,146.23468 -42.257782,146.221344 -42.269165,146.210785 -42.274445,146.20163 -42.27417,146.196075 -42.271385,146.186646 -42.258057,146.188568 -42.252785,146.193298 -42.249443,146.200806 -42.248055,146.209137 -42.249168,146.217468 -42.248611,146.222473 -42.245277,146.22525 -42.240555,146.224121 -42.22805,146.224396 -42.221382,146.228302 -42.217216,146.231354 -42.212502,146.231628 -42.205559,146.219421 -42.186943,146.21637 -42.17028,146.216644 -42.16333,146.219696 -42.158607,146.225525 -42.156105,146.232727 -42.157501)))', max_error=0.00001) != 0: feat.DumpReadable() webserver.server_stop(process, port) pytest.fail('did not get expected feature') webserver.server_stop(process, port)
def test_ogr_wfs3_cleanup(): if gdaltest.wfs3_drv is None: pytest.skip() if gdaltest.webserver_port != 0: webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port)
def ogr_mvt_http_stop(): if gdaltest.webserver_port == 0: return 'skip' webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port) return 'success'
def vsis3_stop_webserver(): if gdaltest.webserver_port == 0: return 'skip' webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port) return 'success'
def vsicurl_stop_webserver(): if gdaltest.webserver_port == 0: return 'skip' webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port) return 'success'
def test_eedai_gce_credentials(): if gdaltest.eedai_drv is None: pytest.skip() gdaltest.webserver_process = None gdaltest.webserver_port = 0 if not gdaltest.built_against_curl(): pytest.skip() (gdaltest.webserver_process, gdaltest.webserver_port) = webserver.launch(handler=webserver.DispatcherHttpHandler) if gdaltest.webserver_port == 0: pytest.skip() gdal.SetConfigOption('CPL_GCE_CREDENTIALS_URL', 'http://localhost:%d/computeMetadata/v1/instance/service-accounts/default/token' % gdaltest.webserver_port) # Disable hypervisor related check to test if we are really on EC2 gdal.SetConfigOption('CPL_GCE_CHECK_LOCAL_FILES', 'NO') gdal.VSICurlClearCache() def method(request): if 'Authorization' not in request.headers: sys.stderr.write('Bad headers: %s\n' % str(request.headers)) request.send_response(403) return expected_authorization = 'Bearer ACCESS_TOKEN' if request.headers['Authorization'] != expected_authorization: sys.stderr.write("Bad Authorization: '%s'\n" % str(request.headers['Authorization'])) request.send_response(403) return request.send_response(200) request.send_header('Content-type', 'text/plain') request.send_header('Content-Length', 3) request.end_headers() request.wfile.write("""foo""".encode('ascii')) handler = webserver.SequentialHandler() handler.add('GET', '/computeMetadata/v1/instance/service-accounts/default/token', 200, {}, """{ "access_token" : "ACCESS_TOKEN", "token_type" : "Bearer", "expires_in" : 3600, }""") with webserver.install_http_handler(handler): gdal.SetConfigOption('EEDA_URL', '/vsimem/ee/') ds = gdal.Open('EEDAI:image') gdal.SetConfigOption('EEDA_URL', None) gdal.SetConfigOption('CPL_GCE_CREDENTIALS_URL', None) gdal.SetConfigOption('CPL_GCE_CHECK_LOCAL_FILES', None) webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port) assert ds is not None
def ogr_wfs3_cleanup(): if gdaltest.wfs3_drv is None: return 'skip' if gdaltest.webserver_port != 0: webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port) return 'success'
def test_mbtiles_stop_webserver(): if gdaltest.mbtiles_drv is None: pytest.skip() if gdal.GetDriverByName('HTTP') is None: pytest.skip() if gdaltest.webserver_port != 0: webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port)
def test_vsicurl_stop_webserver(): if gdaltest.webserver_port == 0: pytest.skip() # Clearcache needed to close all connections, since the Python server # can only handle one connection at a time gdal.VSICurlClearCache() webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port)
def test_visoss_stop_webserver(): if gdaltest.webserver_port == 0: pytest.skip() # Clearcache needed to close all connections, since the Python server # can only handle one connection at a time gdal.VSICurlClearCache() webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port)
def vsiswift_stop_webserver(): if gdaltest.webserver_port == 0: return 'skip' # Clearcache needed to close all connections, since the Python server # can only handle one connection at a time gdal.VSICurlClearCache() webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port) return 'success'
def mbtiles_stop_webserver(): if gdaltest.mbtiles_drv is None: return 'skip' if gdal.GetDriverByName('HTTP') is None: return 'skip' if gdaltest.webserver_port != 0: webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port) return 'success'
def vsiaz_stop_webserver(): if gdaltest.webserver_port == 0: return 'skip' # Clearcache needed to close all connections, since the Python server # can only handle one connection at a time gdal.VSICurlClearCache() webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port) return 'success'
def ogr_wfs_fake_wfs_server(): if gdaltest.wfs_drv is None: return 'skip' if not gdaltest.have_gml_reader: return 'skip' (process, port) = webserver.launch() if port == 0: return 'skip' gdal.SetConfigOption('OGR_WFS_LOAD_MULTIPLE_LAYER_DEFN', 'NO') ds = ogr.Open("WFS:http://127.0.0.1:%d/fakewfs" % port) gdal.SetConfigOption('OGR_WFS_LOAD_MULTIPLE_LAYER_DEFN', None) if ds is None: gdaltest.post_reason('did not managed to open WFS datastore') webserver.server_stop(process, port) return 'fail' lyr = ds.GetLayerByName('rijkswegen') if lyr.GetName() != 'rijkswegen': gdaltest.post_reason('did not get expected layer name') print(lyr.GetName()) webserver.server_stop(process, port) return 'fail' sr = lyr.GetSpatialRef() sr2 = osr.SpatialReference() sr2.ImportFromEPSG(28992) if not sr.IsSame(sr2): gdaltest.post_reason('did not get expected SRS') print(sr) webserver.server_stop(process, port) return 'fail' feat = lyr.GetNextFeature() if feat.GetField('MPLength') != '33513.' or \ ogrtest.check_feature_geometry(feat,'MULTILINESTRING ((154898.65286 568054.62753,160108.36082 566076.78094,164239.254332 563024.70188,170523.31535 561231.219583,172676.42256 559253.37299,175912.80562 557459.89069,180043.699132 553508.779495,183294.491306 552250.182732))', max_error = 0.00001 ) != 0: gdaltest.post_reason('did not get expected feature') feat.DumpReadable() webserver.server_stop(process, port) return 'fail' webserver.server_stop(process, port) return 'success'
def startup_and_cleanup(): # Unset all env vars that could influence the tests az_vars = {} for var, reset_val in ( ('AZURE_STORAGE_CONNECTION_STRING', None), ('AZURE_STORAGE_ACCOUNT', None), ('AZURE_STORAGE_ACCESS_KEY', None), ('AZURE_STORAGE_SAS_TOKEN', None), ('AZURE_NO_SIGN_REQUEST', None), ('AZURE_CONFIG_DIR', ''), ('AZURE_STORAGE_ACCESS_TOKEN', '')): az_vars[var] = gdal.GetConfigOption(var) gdal.SetConfigOption(var, reset_val) with gdaltest.config_option('CPL_AZURE_VM_API_ROOT_URL', 'disabled'): assert gdal.GetSignedURL('/vsiadls/foo/bar') is None gdaltest.webserver_process = None gdaltest.webserver_port = 0 if not gdaltest.built_against_curl(): pytest.skip() (gdaltest.webserver_process, gdaltest.webserver_port) = webserver.launch(handler=webserver.DispatcherHttpHandler) if gdaltest.webserver_port == 0: pytest.skip() gdal.SetConfigOption('AZURE_STORAGE_CONNECTION_STRING', 'DefaultEndpointsProtocol=http;AccountName=myaccount;AccountKey=MY_ACCOUNT_KEY;BlobEndpoint=http://127.0.0.1:%d/azure/blob/myaccount' % gdaltest.webserver_port) gdal.SetConfigOption('AZURE_STORAGE_ACCOUNT', '') gdal.SetConfigOption('AZURE_STORAGE_ACCESS_KEY', '') gdal.SetConfigOption('CPL_AZURE_TIMESTAMP', 'my_timestamp') yield # Clearcache needed to close all connections, since the Python server # can only handle one connection at a time gdal.VSICurlClearCache() webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port) for var in az_vars: gdal.SetConfigOption(var, az_vars[var])
def startup_and_cleanup(): # Unset all env vars that could influence the tests az_vars = {} for var in ('AZURE_STORAGE_CONNECTION_STRING', 'AZURE_STORAGE_ACCOUNT', 'AZURE_STORAGE_ACCESS_KEY', 'AZURE_SAS', 'AZURE_NO_SIGN_REQUEST'): az_vars[var] = gdal.GetConfigOption(var) if az_vars[var] is not None: gdal.SetConfigOption(var, "") assert gdal.GetSignedURL('/vsiadls/foo/bar') is None gdaltest.webserver_process = None gdaltest.webserver_port = 0 if not gdaltest.built_against_curl(): pytest.skip() (gdaltest.webserver_process, gdaltest.webserver_port) = webserver.launch( handler=webserver.DispatcherHttpHandler) if gdaltest.webserver_port == 0: pytest.skip() gdal.SetConfigOption( 'AZURE_STORAGE_CONNECTION_STRING', 'DefaultEndpointsProtocol=http;AccountName=myaccount;AccountKey=MY_ACCOUNT_KEY;EndpointSuffix=127.0.0.1:%d' % gdaltest.webserver_port) gdal.SetConfigOption('AZURE_STORAGE_ACCOUNT', '') gdal.SetConfigOption('AZURE_STORAGE_ACCESS_KEY', '') gdal.SetConfigOption('CPL_AZURE_TIMESTAMP', 'my_timestamp') yield # Clearcache needed to close all connections, since the Python server # can only handle one connection at a time gdal.VSICurlClearCache() webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port) for var in az_vars: gdal.SetConfigOption(var, az_vars[var])
def ogr_elasticsearch_fake_server(): if ogrtest.elasticsearch_drv is None: return 'skip' (process, port) = webserver.launch() if port == 0: return 'skip' gdal.SetConfigOption('ES_OVERWRITE', '1') ds = ogrtest.elasticsearch_drv.CreateDataSource( "http://127.0.0.1:%d/fakeelasticsearch" % port) gdal.SetConfigOption('ES_OVERWRITE', None) if ds is None: gdaltest.post_reason('did not managed to open ElasticSearch datastore') webserver.server_stop(process, port) return 'fail' lyr = ds.CreateLayer('foo') feat = ogr.Feature(lyr.GetLayerDefn()) lyr.CreateFeature(feat) feat = None lyr = ds.CreateLayer('foo2') lyr.CreateField(ogr.FieldDefn('str_field', ogr.OFTString)) lyr.CreateField(ogr.FieldDefn('int_field', ogr.OFTInteger)) lyr.CreateField(ogr.FieldDefn('real_field', ogr.OFTReal)) lyr.CreateField(ogr.FieldDefn('real_field_unset', ogr.OFTReal)) feat = ogr.Feature(lyr.GetLayerDefn()) feat.SetField('str_field', 'a') feat.SetField('int_field', 1) feat.SetField('real_field', 2.34) feat.SetGeometry(ogr.CreateGeometryFromWkt('POINT(0 1)')) lyr.CreateFeature(feat) feat = None webserver.server_stop(process, port) return 'success'
def ogr_elasticsearch_fake_server(): if ogrtest.elasticsearch_drv is None: return 'skip' (process, port) = webserver.launch() if port == 0: return 'skip' gdal.SetConfigOption('ES_OVERWRITE', '1') ds = ogrtest.elasticsearch_drv.CreateDataSource("http://127.0.0.1:%d/fakeelasticsearch" % port) gdal.SetConfigOption('ES_OVERWRITE', None) if ds is None: gdaltest.post_reason('did not managed to open ElasticSearch datastore') webserver.server_stop(process, port) return 'fail' lyr = ds.CreateLayer('foo') feat = ogr.Feature(lyr.GetLayerDefn()) lyr.CreateFeature(feat) feat = None lyr = ds.CreateLayer('foo2') lyr.CreateField(ogr.FieldDefn('str_field', ogr.OFTString)) lyr.CreateField(ogr.FieldDefn('int_field', ogr.OFTInteger)) lyr.CreateField(ogr.FieldDefn('real_field', ogr.OFTReal)) lyr.CreateField(ogr.FieldDefn('real_field_unset', ogr.OFTReal)) feat = ogr.Feature(lyr.GetLayerDefn()) feat.SetField('str_field', 'a') feat.SetField('int_field', 1) feat.SetField('real_field', 2.34) feat.SetGeometry(ogr.CreateGeometryFromWkt('POINT(0 1)')) lyr.CreateFeature(feat) feat = None webserver.server_stop(process, port) return 'success'
def wcs_6(): driver = gdal.GetDriverByName('WCS') if driver is None: return 'skip' # Generating various URLs from the driver and comparing them to ones # that have worked. first_call = True size = 60 cache = 'CACHE=wcs_cache' global urls urls = read_urls() (process, port) = webserver.launch(handler=WCSHTTPHandler) url = "http://127.0.0.1:" + str(port) setup = setupFct() servers = [] for server in setup: servers.append(server) for server in sorted(servers): for i, v in enumerate(setup[server]['Versions']): version = str(int(v / 100)) + '.' + str(int( v % 100 / 10)) + '.' + str((v % 10)) if not server + '-' + version in urls: print("Error: " + server + '-' + version + " not in urls") global wcs_6_ok wcs_6_ok = False continue options = [cache] if first_call: options.append('CLEAR_CACHE') first_call = False query = 'server=' + server + '&version=' + version ds = gdal.OpenEx(utf8_path="WCS:" + url + "/?" + query, open_options=options) coverage = setup[server]['Coverage'] if isinstance(coverage, list): coverage = coverage[i] if isinstance(coverage, numbers.Number): coverage = str(coverage) query += '&coverage=' + coverage options = [cache] if isinstance(setup[server]['Options'], list): oo = setup[server]['Options'][i] else: oo = setup[server]['Options'] oo = oo.split() for o in oo: if o != '-oo': options.append(o) options.append('GetCoverageExtra=test=none') ds = gdal.OpenEx(utf8_path="WCS:" + url + "/?" + query, open_options=options) ds = 0 options = [cache] options.append('GetCoverageExtra=test=scaled') options.append('INTERLEAVE=PIXEL') ds = gdal.OpenEx(utf8_path="WCS:" + url + "/?" + query, open_options=options) if not ds: print("OpenEx failed: WCS:" + url + "/?" + query) wcs_6_ok = False break projwin = setup[server]['Projwin'].replace('-projwin ', '').split() for i, c in enumerate(projwin): projwin[i] = int(c) options = [cache] tmpfile = "tmp/" + server + version + ".tiff" gdal.Translate(tmpfile, ds, projWin=projwin, width=size, options=options) os.remove(tmpfile) if os.path.isfile('data/wcs/' + server + '-' + version + '-non_scaled.tiff'): options = [cache] options.append('GetCoverageExtra=test=non_scaled') options.append('INTERLEAVE=PIXEL') ds = gdal.OpenEx(utf8_path="WCS:" + url + "/?" + query, open_options=options) if not ds: print("OpenEx failed: WCS:" + url + "/?" + query) wcs_6_ok = False break options = [cache] gdal.Translate(tmpfile, ds, srcWin=[0, 0, 2, 2], options=options) os.remove(tmpfile) else: print(server + ' ' + version + ' non_scaled skipped (no response file)') webserver.server_stop(process, port) return 'success' if wcs_6_ok else 'fail'
def test_eedai_gce_credentials(): if gdaltest.eedai_drv is None: pytest.skip() if sys.platform not in ('linux', 'linux2', 'win32'): pytest.skip() gdaltest.webserver_process = None gdaltest.webserver_port = 0 if not gdaltest.built_against_curl(): pytest.skip() (gdaltest.webserver_process, gdaltest.webserver_port) = webserver.launch(handler=webserver.DispatcherHttpHandler) if gdaltest.webserver_port == 0: pytest.skip() gdal.SetConfigOption('CPL_GCE_CREDENTIALS_URL', 'http://localhost:%d/computeMetadata/v1/instance/service-accounts/default/token' % gdaltest.webserver_port) # Disable hypervisor related check to test if we are really on EC2 gdal.SetConfigOption('CPL_GCE_CHECK_LOCAL_FILES', 'NO') gdal.VSICurlClearCache() def method(request): if 'Authorization' not in request.headers: sys.stderr.write('Bad headers: %s\n' % str(request.headers)) request.send_response(403) return expected_authorization = 'Bearer ACCESS_TOKEN' if request.headers['Authorization'] != expected_authorization: sys.stderr.write("Bad Authorization: '%s'\n" % str(request.headers['Authorization'])) request.send_response(403) return request.send_response(200) request.send_header('Content-type', 'text/plain') request.send_header('Content-Length', 3) request.end_headers() request.wfile.write("""foo""".encode('ascii')) handler = webserver.SequentialHandler() handler.add('GET', '/computeMetadata/v1/instance/service-accounts/default/token', 200, {}, """{ "access_token" : "ACCESS_TOKEN", "token_type" : "Bearer", "expires_in" : 3600, }""") with webserver.install_http_handler(handler): gdal.SetConfigOption('EEDA_URL', '/vsimem/ee/') ds = gdal.Open('EEDAI:image') gdal.SetConfigOption('EEDA_URL', None) gdal.SetConfigOption('CPL_GCE_CREDENTIALS_URL', None) gdal.SetConfigOption('CPL_GCE_CHECK_LOCAL_FILES', None) webserver.server_stop(gdaltest.webserver_process, gdaltest.webserver_port) assert ds is not None
def wcs_6(): driver = gdal.GetDriverByName('WCS') if driver is None: return 'skip' # Generating various URLs from the driver and comparing them to ones # that have worked. first_call = True size = 60 cache = 'CACHE=wcs_cache' global urls urls = read_urls() (process, port) = webserver.launch(handler=WCSHTTPHandler) url = "http://127.0.0.1:" + str(port) setup = setupFct() servers = [] for server in setup: servers.append(server) for server in sorted(servers): for i, v in enumerate(setup[server]['Versions']): version = str(int(v / 100)) + '.' + str(int(v % 100 / 10)) + '.' + str((v % 10)) if not server + '-' + version in urls: print("Error: " + server + '-' + version + " not in urls") global wcs_6_ok wcs_6_ok = False continue options = [cache] if first_call: options.append('CLEAR_CACHE') first_call = False query = 'server=' + server + '&version=' + version ds = gdal.OpenEx(utf8_path="WCS:" + url + "/?" + query, open_options=options) coverage = setup[server]['Coverage'] if isinstance(coverage, list): coverage = coverage[i] if isinstance(coverage, numbers.Number): coverage = str(coverage) query += '&coverage=' + coverage options = [cache] if isinstance(setup[server]['Options'], list): oo = setup[server]['Options'][i] else: oo = setup[server]['Options'] oo = oo.split() for o in oo: if o != '-oo': options.append(o) options.append('GetCoverageExtra=test=none') ds = gdal.OpenEx(utf8_path="WCS:" + url + "/?" + query, open_options=options) ds = 0 options = [cache] options.append('GetCoverageExtra=test=scaled') options.append('INTERLEAVE=PIXEL') ds = gdal.OpenEx(utf8_path="WCS:" + url + "/?" + query, open_options=options) if not ds: print("OpenEx failed: WCS:" + url + "/?" + query) global wcs_6_ok wcs_6_ok = False break projwin = setup[server]['Projwin'].replace('-projwin ', '').split() for i, c in enumerate(projwin): projwin[i] = int(c) options = [cache] tmpfile = "tmp/" + server + version + ".tiff" gdal.Translate(tmpfile, ds, projWin=projwin, width=size, options=options) os.remove(tmpfile) if os.path.isfile('data/wcs/' + server + '-' + version + '-non_scaled.tiff'): options = [cache] options.append('GetCoverageExtra=test=non_scaled') options.append('INTERLEAVE=PIXEL') ds = gdal.OpenEx(utf8_path="WCS:" + url + "/?" + query, open_options=options) if not ds: print("OpenEx failed: WCS:" + url + "/?" + query) global wcs_6_ok wcs_6_ok = False break options = [cache] gdal.Translate(tmpfile, ds, srcWin=[0, 0, 2, 2], options=options) os.remove(tmpfile) else: print(server + ' ' + version + ' non_scaled skipped (no response file)') webserver.server_stop(process, port) return 'success' if wcs_6_ok else 'fail'