def test_clean_mime_type_format_iana(): iana_fmt = f"{f.IANA_NAMESPACE}:{f.ContentType.APP_JSON}" # "iana:mime_type" res_type = f.clean_mime_type_format(iana_fmt) assert res_type == f.ContentType.APP_JSON iana_url = list(f.IANA_NAMESPACE_DEFINITION.values())[0] iana_fmt = os.path.join(iana_url, f.ContentType.APP_JSON) res_type = f.clean_mime_type_format(iana_fmt) assert res_type == f.ContentType.APP_JSON # application/json
def test_clean_mime_type_format_default(): assert f.clean_mime_type_format( "", suffix_subtype=False, strip_parameters=False) is None assert f.clean_mime_type_format( "", suffix_subtype=False, strip_parameters=True) is None assert f.clean_mime_type_format( "", suffix_subtype=True, strip_parameters=False) is None assert f.clean_mime_type_format( "", suffix_subtype=True, strip_parameters=True) is None
def test_clean_mime_type_format_iana(): iana_fmt = "{}:{}".format(f.IANA_NAMESPACE, f.CONTENT_TYPE_APP_JSON) # "iana:mime_type" res_type = f.clean_mime_type_format(iana_fmt) assert res_type == f.CONTENT_TYPE_APP_JSON iana_url = list(f.IANA_NAMESPACE_DEFINITION.values())[0] iana_fmt = os.path.join(iana_url, f.CONTENT_TYPE_APP_JSON) res_type = f.clean_mime_type_format(iana_fmt) assert res_type == f.CONTENT_TYPE_APP_JSON # application/json
def test_clean_mime_type_format_opengis(): mime_type, fmt = list(f.OPENGIS_MAPPING.items())[0] gis_fmt = f"{f.OPENGIS_NAMESPACE}:{fmt}" # "edam:format_####" res_type = f.clean_mime_type_format(gis_fmt) assert res_type == mime_type gis_fmt = os.path.join( list(f.OPENGIS_NAMESPACE_DEFINITION.values())[0], fmt) # "edam-url/format_####" res_type = f.clean_mime_type_format(gis_fmt) assert res_type == mime_type # application/x-type
def test_clean_mime_type_format_edam(): mime_type, fmt = list(f.EDAM_MAPPING.items())[0] edam_fmt = "{}:{}".format(f.EDAM_NAMESPACE, fmt) # "edam:format_####" res_type = f.clean_mime_type_format(edam_fmt) assert res_type == mime_type edam_fmt = os.path.join( list(f.EDAM_NAMESPACE_DEFINITION.values())[0], fmt) # "edam-url/format_####" res_type = f.clean_mime_type_format(edam_fmt) assert res_type == mime_type # application/x-type
def test_clean_mime_type_format_io_remove_extra_parameters(): test_input_formats = [ (f.ContentType.APP_JSON, f.ContentType.APP_JSON), (f.ContentType.APP_JSON, f.ContentType.APP_JSON + "; charset=UTF-8"), (f.ContentType.APP_XML, f.ContentType.APP_XML + "; charset=UTF-8; version=1.0"), ("application/vnd.api+json", "application/vnd.api+json; charset=UTF-8"), ("application/vnd.api+json", "application/vnd.api+json"), ] for expect_fmt, test_fmt in test_input_formats: res_type = f.clean_mime_type_format(test_fmt, strip_parameters=True) assert res_type == expect_fmt
def test_clean_mime_type_format_io_strip_base_type(): test_input_formats = [ (f.ContentType.APP_JSON, f.ContentType.APP_JSON), (f.ContentType.APP_JSON + "; charset=UTF-8", f.ContentType.APP_JSON + "; charset=UTF-8"), (f.ContentType.APP_XML + "; charset=UTF-8; version=1.0", f.ContentType.APP_XML + "; charset=UTF-8; version=1.0"), (f.ContentType.APP_JSON + "; charset=UTF-8", "application/vnd.api+json; charset=UTF-8"), (f.ContentType.APP_JSON, "application/vnd.api+json"), ] for expect_fmt, test_fmt in test_input_formats: res_type = f.clean_mime_type_format(test_fmt, suffix_subtype=True) assert res_type == expect_fmt
def test_clean_mime_type_format_io_strip_base_and_remove_parameters(): test_input_formats = [ (f.CONTENT_TYPE_APP_JSON, f.CONTENT_TYPE_APP_JSON), (f.CONTENT_TYPE_APP_JSON, f.CONTENT_TYPE_APP_JSON + "; charset=UTF-8"), (f.CONTENT_TYPE_APP_XML, f.CONTENT_TYPE_APP_XML + "; charset=UTF-8; version=1.0"), (f.CONTENT_TYPE_APP_JSON, "application/vnd.api+json; charset=UTF-8"), (f.CONTENT_TYPE_APP_JSON, "application/vnd.api+json"), ] for expect_fmt, test_fmt in test_input_formats: res_type = f.clean_mime_type_format(test_fmt, suffix_subtype=True, strip_parameters=True) assert res_type == expect_fmt
def submit_local_job(request): # type: (PyramidRequest) -> AnyViewResponse """ Execute a process registered locally. Execution location and method is according to deployed Application Package. """ process = get_process(request=request) ctype = clean_mime_type_format(get_header("content-type", request.headers, default=None), strip_parameters=True) if ctype in ContentType.ANY_XML: # Send the XML request to the WPS endpoint which knows how to parse it properly. # Execution will end up in the same 'submit_job_handler' function as other branch for JSON. service = get_pywps_service() wps_params = {"version": "1.0.0", "request": "Execute", "service": "WPS", "identifier": process.id} request.path_info = get_wps_path(request) request.query_string = get_path_kvp("", **wps_params)[1:] location = request.application_url + request.path_info + request.query_string LOGGER.warning("Route redirection [%s] -> [%s] for WPS-XML support.", request.url, location) http_request = extend_instance(request, WerkzeugRequest) http_request.shallow = False return service.call(http_request) return submit_job(request, process, tags=["wps-rest"])