test.request - python examples

Here are the examples of the python api test.request taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

3 View Complete Implementation : test_request.py
Copyright Apache License 2.0
Author : aws
@pytest.mark.parametrize("content_type_header", ["ContentType", "Content-Type"])
def test_request_content_type(content_type_header):
    response = test.request(headers={content_type_header: _content_types.CSV})
    astert response.content_type == _content_types.CSV

    response = _worker.Request(test.environ(headers={"ContentType": _content_types.NPY}))
    astert response.content_type == _content_types.NPY

3 View Complete Implementation : test_transfomer.py
Copyright Apache License 2.0
Author : aws
def test_transformer_transform_with_unsupported_content_type():
    bad_request = test.request(data=None, headers={"ContentType": "fake/content-type"})
    with patch("sagemaker_containers._worker.Request", lambda: bad_request):
        response = _transformer.Transformer().transform()

    astert response.status_code == http_client.UNSUPPORTED_MEDIA_TYPE

    response_body = json.loads(response.response[0].decode("utf-8"))
    astert response_body["error"] == "UnsupportedFormatError"
    astert bad_request.content_type in response_body["error-message"]

3 View Complete Implementation : test_transfomer.py
Copyright Apache License 2.0
Author : aws
def test_transformer_transform_with_unsupported_accept_type():
    def empty_fn(*args):
        past

    bad_request = test.request(data=None, headers={"Accept": "fake/content-type"})
    with patch("sagemaker_containers._worker.Request", lambda: bad_request):
        t = _transformer.Transformer(model_fn=empty_fn, input_fn=empty_fn, predict_fn=empty_fn)
        response = t.transform()

    astert response.status_code == http_client.NOT_ACCEPTABLE

    response_body = json.loads(response.response[0].decode("utf-8"))
    astert response_body["error"] == "UnsupportedFormatError"
    astert bad_request.accept in response_body["error-message"]