예제 #1
0
def test_mangle_response_drop(req_w_rsp, mock_deep_save, mock_tempfile, ignore_edit, ignore_delete):
    # Intercepting is off, request in scope
    tfile_obj, tfile_instance, new_open, fake_file = mock_tempfile
    r = req_w_rsp
    old_rsp = r.response.full_response
    new_contents = ""
    fake_file.read.return_value = new_contents
    mangled_rsp = yield async_mangle_response(r)

    assert mangled_rsp is None
예제 #2
0
def test_mangle_response_drop(req_w_rsp, mock_deep_save, mock_tempfile,
                              ignore_edit, ignore_delete):
    # Intercepting is off, request in scope
    tfile_obj, tfile_instance, new_open, fake_file = mock_tempfile
    r = req_w_rsp
    old_rsp = r.response.full_response
    new_contents = ''
    fake_file.read.return_value = new_contents
    mangled_rsp = yield async_mangle_response(r)

    assert mangled_rsp is None
예제 #3
0
def test_mangle_response_new_len(req_w_rsp, mock_deep_save, mock_tempfile, ignore_edit, ignore_delete):
    # Intercepting is off, request in scope
    tfile_obj, tfile_instance, new_open, fake_file = mock_tempfile
    r = req_w_rsp
    old_rsp = r.response.full_response
    new_contents = "HTTP/1.1 403 NOTOKIEDOKIE\n" "Content-Length: 4\n" "Other-Header: foobles\r\n\n" "BBBBAAAA"
    fake_file.read.return_value = new_contents
    mangled_rsp = yield async_mangle_response(r)

    assert mangled_rsp.full_response == (
        "HTTP/1.1 403 NOTOKIEDOKIE\r\n" "Content-Length: 8\r\n" "Other-Header: foobles\r\n\r\n" "BBBBAAAA"
    )
예제 #4
0
def test_mangle_response_edit(req_w_rsp, mock_deep_save, mock_tempfile, ignore_edit, ignore_delete):
    # Intercepting is on, edit
    tfile_obj, tfile_instance, new_open, fake_file = mock_tempfile
    r = req_w_rsp
    old_rsp = r.response.full_response
    new_contents = "HTTP/1.1 403 NOTOKIEDOKIE\r\n" "Content-Length: 4\r\n" "Other-Header: foobles\r\n\r\n" "BBBB"
    fake_file.read.return_value = new_contents
    mangled_rsp = yield async_mangle_response(r)
    assert not mock_deep_save.called
    assert tfile_obj.called
    assert tfile_instance.write.called
    assert tfile_instance.write.call_args == ((old_rsp,),)
    assert new_open.called
    assert fake_file.read.called

    assert mangled_rsp.full_response == new_contents
예제 #5
0
def test_mangle_response_new_len(req_w_rsp, mock_deep_save, mock_tempfile,
                                 ignore_edit, ignore_delete):
    # Intercepting is off, request in scope
    tfile_obj, tfile_instance, new_open, fake_file = mock_tempfile
    r = req_w_rsp
    old_rsp = r.response.full_response
    new_contents = ('HTTP/1.1 403 NOTOKIEDOKIE\n'
                    'Content-Length: 4\n'
                    'Other-Header: foobles\r\n\n'
                    'BBBBAAAA')
    fake_file.read.return_value = new_contents
    mangled_rsp = yield async_mangle_response(r)

    assert mangled_rsp.full_response == ('HTTP/1.1 403 NOTOKIEDOKIE\r\n'
                                         'Content-Length: 8\r\n'
                                         'Other-Header: foobles\r\n\r\n'
                                         'BBBBAAAA')
예제 #6
0
def test_mangle_response_edit(req_w_rsp, mock_deep_save, mock_tempfile,
                              ignore_edit, ignore_delete):
    # Intercepting is on, edit
    tfile_obj, tfile_instance, new_open, fake_file = mock_tempfile
    r = req_w_rsp
    old_rsp = r.response.full_response
    new_contents = ('HTTP/1.1 403 NOTOKIEDOKIE\r\n'
                    'Content-Length: 4\r\n'
                    'Other-Header: foobles\r\n\r\n'
                    'BBBB')
    fake_file.read.return_value = new_contents
    mangled_rsp = yield async_mangle_response(r)
    assert not mock_deep_save.called
    assert tfile_obj.called
    assert tfile_instance.write.called
    assert tfile_instance.write.call_args == ((old_rsp, ), )
    assert new_open.called
    assert fake_file.read.called

    assert mangled_rsp.full_response == new_contents