Beispiel #1
0
def _create_normal_happy_handlers(number_of_handlers):
    handlers = []
    for n in xrange(number_of_handlers):
        handlers.append(FunctionStub(
            name='Path length {} handler'.format(n),
            dummy_result='Path length {} handler result'.format(n)))
    return handlers
Beispiel #2
0
def _create_normal_sad_handlers(number_of_handlers):
    handlers = []
    for n in xrange(number_of_handlers):
        handlers.append(FunctionStub(
            name='Path length {} handler'.format(n),
            dummy_exception=HandlerException(
                wrapped_exception=_UniqueException)))
    return handlers
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(pypi_base_url=pypi_base_url,
                               http_get_fn=html_get_stub,
                               parse_index_fn=parser_stub,
                               build_index_fn=builder_stub)

    request = RequestStub(is_index=is_index)
    response = ResponseStub()

    response_str = handler.handle(path=path,
                                  request=request,
                                  response=response)

    eq_(response.headers, {}, msg='Headers are expected to be unaffected')

    eq_(response_str,
        builder_response,
        msg='Handler did not return builder result')

    builder_stub.assert_single_kw_call(
        expected_kwargs={'index_rows': parser_response})

    parser_stub.assert_single_kw_call(
        expected_kwargs={
            'base_url': pypi_base_url,
            'package_path': package_path,
            'html_str': html_get_response
        })
Beispiel #4
0
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)
    request = RequestStub(is_index=is_index)
    response = ResponseStub()

    response_str = handler.handle(
        path=path,
        request=request,
        response=response)

    eq_(response.headers, {},
        msg='Headers are expected to be unaffected')

    eq_(response_str, dumb_response,
        msg='Handler did not return builder result')

    builder_stub.assert_single_kw_call(expected_kwargs={
        'index_rows': OrderedDict([('python/', None)])})
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(
        pypi_base_url=pypi_base_url,
        http_get_fn=html_get_stub,
        parse_index_fn=parser_stub,
        build_index_fn=builder_stub)

    request = RequestStub(is_index=is_index)
    response = ResponseStub()

    response_str = handler.handle(
        path=path,
        request=request,
        response=response)

    eq_(response.headers, {},
        msg='Headers are expected to be unaffected')

    eq_(response_str, builder_response,
        msg='Handler did not return builder result')

    builder_stub.assert_single_kw_call(expected_kwargs={
        'index_rows': parser_response})

    parser_stub.assert_single_kw_call(expected_kwargs={
        'base_url': pypi_base_url,
        'package_path': package_path,
        'html_str': html_get_response})
Beispiel #6
0
def _create_sad_exception_handler():
    handler = FunctionStub(
        name='Invalid path handler',
        dummy_exception=_UniqueException)
    return handler
Beispiel #7
0
def _create_happy_exception_handler():
    handler = FunctionStub(
        name='Invalid path handler',
        dummy_result='Invalid path handler result')
    return handler
Beispiel #8
0
def _check_file_handler(
        file_entry,
        file_requested,
        root_dir='python',
        expected_checksum=None,
        http_get_exception=None,
        parse_index_exception=None):

    pypi_base_url = 'http://dumb_url.com'

    parser_response = OrderedDict([
        ('nose-1.2.0.tar.gz', IndexRow(
            download_url='http://some_url.com/nose/nose-1.2.0.tar.gz',
            checksums=Checksums(
                md5='MD5-nose-1.2.0.tar.gz',
                sha1=None))),
        (file_entry.filename, file_entry.index_row),
        ('nose-1.2.1.egg', IndexRow(
            download_url='http://some_url.com/nose/nose-1.2.1.egg',
            checksums=Checksums(
                md5='MD5-nose-1.2.1.egg',
                sha1=None))),
    ])

    html_get_response = 'be dumb html'

    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)

    handler = FileHandler(
        pypi_base_url=pypi_base_url,
        http_get_fn=html_get_stub,
        parse_index_fn=parser_stub)

    request = RequestStub(is_index=False)
    response = ResponseStub()

    # When not retrieving a checksum, we expect a redirection exception to be
    # thrown here. Asserting correct redirect behavior is performed in the
    # calling test function.
    response_str = handler.handle(
        path=[root_dir, file_entry.pkg_name, file_requested],
        request=request,
        response=response)

    expected_headers = {'Content-Type': 'application/x-checksum'}

    eq_(response.headers, expected_headers,
        msg='Response headers did not match the expected headers')

    eq_(response_str, expected_checksum,
        msg='Response checksum did not match the expected checksum')

    html_get_stub.assert_single_kw_call(expected_kwargs={
        'url': '{}/{}/'.format(pypi_base_url, file_entry.pkg_name)})

    parser_stub.assert_single_kw_call(expected_kwargs={
        'base_url': pypi_base_url,
        'package_path': file_entry.pkg_name,
        'html_str': html_get_response})