# Path: pypi_redirect/pypi_redirect/server_app/handler/pypi_index_handler.py
# class PyPIIndexHandler(object):
#     def __init__(
#             self,
#             pypi_base_url,
#             http_get_fn,
#             parse_index_fn,
#             build_index_fn):
#         self.pypi_base_url = pypi_base_url
#         self.http_get_fn = http_get_fn
#         self.parse_index_fn = parse_index_fn
#         self.build_index_fn = build_index_fn
# 
#     def _simple_pypi_or_package(self, path):
#         """
#         Determines whether the given path points to a specific package
#         or to the root of the "simple" PyPI structure.
#         """
#         if len(path) == 2:
#             py, package_name = path
#             index_url = '{}/{}/'.format(self.pypi_base_url, package_name)
#         else:
#             package_name = 'python'
#             index_url = '{}/'.format(self.pypi_base_url)
#         return index_url, package_name
# 
#     @ensure_python_dir
#     @ensure_index
#     def handle(self, path, request, response):
#         index_url, package_name = self._simple_pypi_or_package(path)
# 
#         index_rows = fetch_and_parse_index(
#             http_get_fn=self.http_get_fn,
#             parse_index_fn=self.parse_index_fn,
#             pypi_base_url=self.pypi_base_url,
#             index_url=index_url,
#             package_path=package_name)
# 
#         rebuilt_html_str = self.build_index_fn(
#             index_rows=index_rows)
# 
#         return rebuilt_html_str


from functools import partial
from lxml.etree import ParseError
from nose.tools import eq_
from requests import RequestException
from _utils import RequestStub, ResponseStub, FunctionStub
from _utils import assert_http_redirect, assert_http_not_found
from ...server_app.handler.pypi_index_handler import PyPIIndexHandler
        run_handler_fn=handler_runner,
        failure_description='Failed to return 404 on non-"/python/" path')


def _check_main_index_path(
        path,
        is_index,
        http_get_exception=None,
        parse_index_exception=None):

    pypi_base_url = 'http://dumb_url.com'
    builder_response = 'be dumb builder'
    parser_response = 'be dumb parser'
    html_get_response = 'be dumb html'
    py, package_path = path

    html_get_stub = FunctionStub(
        name='HTML Get',
        dummy_result=html_get_response,
        dummy_exception=http_get_exception)

    parser_stub = FunctionStub(
        name='Parser',
        dummy_result=parser_response,
        dummy_exception=parse_index_exception)

    builder_stub = FunctionStub(
        name='Builder',
        dummy_result=builder_response)


# Path: pypi_redirect/pypi_redirect/server_app/handler/pypi_index_handler.py
# class PyPIIndexHandler(object):
#     def __init__(
#             self,
#             pypi_base_url,
#             http_get_fn,
#             parse_index_fn,
#             build_index_fn):
#         self.pypi_base_url = pypi_base_url
#         self.http_get_fn = http_get_fn
#         self.parse_index_fn = parse_index_fn
#         self.build_index_fn = build_index_fn
# 
#     def _simple_pypi_or_package(self, path):
#         """
#         Determines whether the given path points to a specific package
#         or to the root of the "simple" PyPI structure.
#         """
#         if len(path) == 2:
#             py, package_name = path
#             index_url = '{}/{}/'.format(self.pypi_base_url, package_name)
#         else:
#             package_name = 'python'
#             index_url = '{}/'.format(self.pypi_base_url)
#         return index_url, package_name
# 
#     @ensure_python_dir
#     @ensure_index
#     def handle(self, path, request, response):
#         index_url, package_name = self._simple_pypi_or_package(path)
# 
#         index_rows = fetch_and_parse_index(
#             http_get_fn=self.http_get_fn,
#             parse_index_fn=self.parse_index_fn,
#             pypi_base_url=self.pypi_base_url,
#             index_url=index_url,
#             package_path=package_name)
# 
#         rebuilt_html_str = self.build_index_fn(
#             index_rows=index_rows)
# 
#         return rebuilt_html_str


# Path: pypi_redirect/pypi_redirect/test/unit_tests/pypi_index_handler_test.py
from functools import partial
from lxml.etree import ParseError
from nose.tools import eq_
from requests import RequestException
from _utils import RequestStub, ResponseStub, FunctionStub
from _utils import assert_http_redirect, assert_http_not_found
from ...server_app.handler.pypi_index_handler import PyPIIndexHandler

        run_handler_fn=handler_runner,
        failure_description='Failed to return 404 on non-"/python/" path')


def _check_main_index_path(
        path,
        is_index,
        http_get_exception=None,
        parse_index_exception=None):

    pypi_base_url = 'http://dumb_url.com'
    builder_response = 'be dumb builder'
    parser_response = 'be dumb parser'
    html_get_response = 'be dumb html'
    py, package_path = path

    html_get_stub = FunctionStub(
        name='HTML Get',
        dummy_result=html_get_response,
        dummy_exception=http_get_exception)

    parser_stub = FunctionStub(
        name='Parser',
        dummy_result=parser_response,
        dummy_exception=parse_index_exception)

    builder_stub = FunctionStub(
        name='Builder',
        dummy_result=builder_response)


    handler = PyPIIndexHandler(