# Path: crosscompute/scripts/serve.py
# def do(arguments=None):
# def configure_argument_parser_for_serving(a):
# def serve_with(automation, args):
# def serve(
#         automation, host=HOST, port=PORT, with_browser=True,
#         is_static=False, is_production=False,
#         base_uri='', allowed_origins=None,
#         disk_poll_in_milliseconds=DISK_POLL_IN_MILLISECONDS,
#         disk_debounce_in_milliseconds=DISK_DEBOUNCE_IN_MILLISECONDS):
# L = getLogger(__name__)


from crosscompute.models import Result
from crosscompute.types import DataItem
from crosscompute.scripts.serve import (
    get_result_file_response, get_tool_file_response,
    parse_result_relative_path, parse_template_parts)
from invisibleroads_macros.disk import copy_path, make_folder
from invisibleroads_macros.exceptions import BadPath
from invisibleroads_uploads.models import Upload
from invisibleroads_uploads.tests import prepare_field_storage
from os.path import join
from pyramid.httpexceptions import HTTPBadRequest, HTTPForbidden, HTTPNotFound
from pytest import raises
from webob.multidict import MultiDict
from conftest import TOOL_FOLDER, WheeType
        f(posts_request, TOOL_FOLDER, tool_definition)

    get_absolute_path.side_effect = None
    exists.return_value = False
    with raises(HTTPNotFound):
        f(posts_request, TOOL_FOLDER, tool_definition)

    exists.return_value = True
    del tool_definition['x.a_path']
    with raises(HTTPNotFound):
        f(posts_request, TOOL_FOLDER, tool_definition)


def test_get_result_file_response(posts_request, result, mocker):
    x = 'crosscompute.scripts.serve.'
    get_absolute_path = mocker.patch(x + 'get_absolute_path')
    exists = mocker.patch(x + 'exists')

    posts_request.matchdict = {'folder_name': 'a', 'path': 'x'}
    with raises(HTTPForbidden):
        get_result_file_response(posts_request, result)

    posts_request.matchdict = {'folder_name': 'x', 'path': 'x'}
    get_absolute_path.side_effect = BadPath()
    with raises(HTTPNotFound):
        get_result_file_response(posts_request, result)

    get_absolute_path.side_effect = None
    exists.return_value = False
    with raises(HTTPNotFound):

# Path: crosscompute/scripts/serve.py
# def do(arguments=None):
# def configure_argument_parser_for_serving(a):
# def serve_with(automation, args):
# def serve(
#         automation, host=HOST, port=PORT, with_browser=True,
#         is_static=False, is_production=False,
#         base_uri='', allowed_origins=None,
#         disk_poll_in_milliseconds=DISK_POLL_IN_MILLISECONDS,
#         disk_debounce_in_milliseconds=DISK_DEBOUNCE_IN_MILLISECONDS):
# L = getLogger(__name__)


# Path: experiments/0.7/tests/x_serve.py
from crosscompute.models import Result
from crosscompute.types import DataItem
from crosscompute.scripts.serve import (
    get_result_file_response, get_tool_file_response,
    parse_result_relative_path, parse_template_parts)
from invisibleroads_macros.disk import copy_path, make_folder
from invisibleroads_macros.exceptions import BadPath
from invisibleroads_uploads.models import Upload
from invisibleroads_uploads.tests import prepare_field_storage
from os.path import join
from pyramid.httpexceptions import HTTPBadRequest, HTTPForbidden, HTTPNotFound
from pytest import raises
from webob.multidict import MultiDict
from conftest import TOOL_FOLDER, WheeType

        f(posts_request, TOOL_FOLDER, tool_definition)

    get_absolute_path.side_effect = None
    exists.return_value = False
    with raises(HTTPNotFound):
        f(posts_request, TOOL_FOLDER, tool_definition)

    exists.return_value = True
    del tool_definition['x.a_path']
    with raises(HTTPNotFound):
        f(posts_request, TOOL_FOLDER, tool_definition)


def test_get_result_file_response(posts_request, result, mocker):
    x = 'crosscompute.scripts.serve.'
    get_absolute_path = mocker.patch(x + 'get_absolute_path')
    exists = mocker.patch(x + 'exists')

    posts_request.matchdict = {'folder_name': 'a', 'path': 'x'}
    with raises(HTTPForbidden):
        get_result_file_response(posts_request, result)

    posts_request.matchdict = {'folder_name': 'x', 'path': 'x'}
    get_absolute_path.side_effect = BadPath()
    with raises(HTTPNotFound):
        get_result_file_response(posts_request, result)

    get_absolute_path.side_effect = None
    exists.return_value = False
    with raises(HTTPNotFound):

        get_result_file_response(posts_request, result)