def test_image_input_http_request_malformatted_input_missing_image_file():
    test_image_input = ImageInput(input_names=("my_image",))
    request = mock.MagicMock(spec=flask.Request)

    request.method = "POST"
    request.files = {}
    request.headers = {}
    request.get_data.return_value = None

    with pytest.raises(BadInput) as e:
        test_image_input.handle_request(request, predict)

    assert "unexpected HTTP request format" in str(e.value)
def test_image_input_http_request_post_binary(img_file):
    test_image_input = ImageInput()
    request = mock.MagicMock(spec=flask.Request)
    request.method = "POST"
    request.files = {}
    request.headers = {}
    request.get_data.return_value = open(str(img_file), 'rb')

    response = test_image_input.handle_request(request, predict)

    assert response.status_code == 200
    assert "[10, 10, 3]" in str(response.response)
def test_image_input_http_request_single_image_different_name(img_file):
    test_image_input = ImageInput(input_names=("my_image",))
    request = mock.MagicMock(spec=flask.Request)
    file_attr = {
        'filename': 'test_img.png',
        'read.return_value': open(str(img_file), 'rb').read(),
    }
    file = mock.Mock(**file_attr)

    request.method = "POST"
    request.files = {"a_differnt_name_used": file}
    request.headers = {}
    request.get_data.return_value = None

    response = test_image_input.handle_request(request, predict)

    assert response.status_code == 200
    assert "[10, 10, 3]" in str(response.response)