Ejemplo n.º 1
0
def mock_http_with_file(request):
    content = ''.join(
        chr(randrange(0, 256))
        for x in xrange(0, 1024 * randrange(3, 10) + randrange(0, 1024)))

    def iter_content(chunk_size=1024):
        for i in xrange(0, len(content), chunk_size):
            yield content[i:i + chunk_size]

    mock_response = NonCallableMagicMock()
    mock_response.iter_content = MagicMock(side_effect=iter_content)
    mock_requests = NonCallableMagicMock()
    mock_requests.get = MagicMock(return_value=mock_response)
    mock_requests._mock_response = mock_response
    mock_requests._content = content

    patcher = patch(
        target='fabric_ovirt.lib.remote_files.requests',
        new=mock_requests,
    )

    def finalizer():
        patcher.stop()

    return patcher.start()
Ejemplo n.º 2
0
def mock_http_with_digest_file(request, mock_digests_and_files):
    digest_file_lines = ('  '.join(pair) for pair in mock_digests_and_files)
    mock_response = NonCallableMagicMock()
    mock_response.iter_lines = MagicMock(return_value=digest_file_lines)
    mock_requests = NonCallableMagicMock()
    mock_requests.get = MagicMock(return_value=mock_response)
    mock_requests._mock_response = mock_response

    patcher = patch(
        target='fabric_ovirt.lib.remote_files.requests',
        new=mock_requests,
    )

    def finalizer():
        patcher.stop()

    return patcher.start()