# Path: pypi_redirect/pypi_redirect/server_app/handler/root_index_handler.py
# class RootIndexHandler(object):
#     def __init__(self, build_index_fn):
#         self.build_index_fn = build_index_fn
# 
#     @ensure_index
#     def handle(self, path, request, response):
#         html_str = self.build_index_fn(
#             index_rows=OrderedDict([('python/', None)]))
# 
#         return html_str


from collections import OrderedDict
from functools import partial
from nose.tools import eq_
from _utils import RequestStub, FunctionStub, ResponseStub
from _utils import assert_http_redirect
from ...server_app.handler.root_index_handler import RootIndexHandler


def empty_path_is_index_test():
    _check_root_path([], is_index=True)


def empty_path_not_index_test():
    handler_runner = partial(
        _check_root_path,
        path=[],
        is_index=False)

    assert_http_redirect(
        run_handler_fn=handler_runner,
        expected_url='/',
        expected_status=301,
        failure_description='Index handler did not redirect to directory')


def _check_root_path(path, is_index):
    dumb_response = "be dumb"

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


# Path: pypi_redirect/pypi_redirect/server_app/handler/root_index_handler.py
# class RootIndexHandler(object):
#     def __init__(self, build_index_fn):
#         self.build_index_fn = build_index_fn
# 
#     @ensure_index
#     def handle(self, path, request, response):
#         html_str = self.build_index_fn(
#             index_rows=OrderedDict([('python/', None)]))
# 
#         return html_str


# Path: pypi_redirect/pypi_redirect/test/unit_tests/root_index_handler_test.py
from collections import OrderedDict
from functools import partial
from nose.tools import eq_
from _utils import RequestStub, FunctionStub, ResponseStub
from _utils import assert_http_redirect
from ...server_app.handler.root_index_handler import RootIndexHandler



def empty_path_is_index_test():
    _check_root_path([], is_index=True)


def empty_path_not_index_test():
    handler_runner = partial(
        _check_root_path,
        path=[],
        is_index=False)

    assert_http_redirect(
        run_handler_fn=handler_runner,
        expected_url='/',
        expected_status=301,
        failure_description='Index handler did not redirect to directory')


def _check_root_path(path, is_index):
    dumb_response = "be dumb"

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


    handler = RootIndexHandler(build_index_fn=builder_stub)