aiohttp.test_utils.make_mocked_request

Here are the examples of the python api aiohttp.test_utils.make_mocked_request taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

26 Examples 7

Example 1

Project: aiohttp
License: View license
Source File: test_web_request.py
@asyncio.coroutine
def test_cannot_clone_after_read(loop):
    payload = StreamReader(loop=loop)
    payload.feed_data(b'data')
    payload.feed_eof()
    req = make_mocked_request('GET', '/path', payload=payload)
    yield from req.read()
    with pytest.raises(RuntimeError):
        req.clone()

Example 2

Project: rororo
License: View license
Source File: test_aio.py
    def test_is_xhr_request(self):
        non_xhr_request = make_mocked_request('GET', '/')
        self.assertFalse(is_xhr_request(non_xhr_request))

        xhr_request = make_mocked_request('GET', '/api/', headers=CIMultiDict({
            'X-Requested-With': 'XMLHttpRequest',
        }))
        self.assertTrue(is_xhr_request(xhr_request))

Example 3

Project: aiohttp-session
License: View license
Source File: test_get_session.py
@asyncio.coroutine
def test_get_stored_session():
    req = make_mocked_request('GET', '/')
    session = Session('identity', data=None, new=False)
    req[SESSION_KEY] = session

    ret = yield from get_session(req)
    assert session is ret

Example 4

Project: aiohttp-session
License: View license
Source File: test_get_session.py
@asyncio.coroutine
def test_session_is_not_stored():
    req = make_mocked_request('GET', '/')

    with pytest.raises(RuntimeError):
        yield from get_session(req)

Example 5

Project: aiohttp
License: View license
Source File: test_test_utils.py
@pytest.mark.parametrize(
    "headers", [{'token': 'x'}, CIMultiDict({'token': 'x'}), {}])
def test_make_mocked_request(headers):
    req = make_mocked_request('GET', '/', headers=headers)
    assert req.method == "GET"
    assert req.path == "/"
    assert isinstance(req, web_reqrep.Request)
    assert isinstance(req.headers, CIMultiDictProxy)

Example 6

Project: aiohttp
License: View license
Source File: test_urldispatch.py
@asyncio.coroutine
def test_static_not_match(router):
    router.add_static('/pre', os.path.dirname(aiohttp.__file__),
                      name='name')
    resource = router['name']
    ret = yield from resource.resolve(
        make_mocked_request('GET', '/another/path'))
    assert (None, set()) == ret

Example 7

Project: aiohttp
License: View license
Source File: test_urldispatch.py
@asyncio.coroutine
def test_404_for_static_resource(router):
    resource = router.add_static('/st',
                                 os.path.dirname(aiohttp.__file__))
    ret = yield from resource.resolve(
        make_mocked_request('GET', '/unknown/path'))
    assert (None, set()) == ret

Example 8

Project: aiohttp
License: View license
Source File: test_urldispatch.py
@asyncio.coroutine
def test_405_for_resource_adapter(router):
    resource = router.add_static('/st',
                                 os.path.dirname(aiohttp.__file__))
    ret = yield from resource.resolve(
        make_mocked_request('POST', '/st/abc.py'))
    assert (None, {'HEAD', 'GET'}) == ret

Example 9

Project: aiohttp
License: View license
Source File: test_urldispatch.py
@asyncio.coroutine
def test_check_allowed_method_for_found_resource(router):
    handler = make_handler()
    resource = router.add_resource('/')
    resource.add_route('GET', handler)
    ret = yield from resource.resolve(make_mocked_request('GET', '/'))
    assert ret[0] is not None
    assert {'GET'} == ret[1]

Example 10

Project: aiohttp
License: View license
Source File: test_web_exceptions.py
@pytest.fixture
def request(buf):
    method = 'GET'
    path = '/'
    writer = mock.Mock()
    writer.drain.return_value = ()

    def append(data):
        buf.extend(data)
    writer.write.side_effect = append
    app = mock.Mock()
    app._debug = False
    app.on_response_prepare = signals.Signal(app)
    req = make_mocked_request(method, path, app=app, writer=writer)
    return req

Example 11

Project: aiohttp
License: View license
Source File: test_web_request_handler.py
def test_repr(loop):
    app = web.Application(loop=loop)
    manager = app.make_handler()
    handler = manager()

    assert '<RequestHandler none:none disconnected>' == repr(handler)

    handler.transport = object()
    request = make_mocked_request('GET', '/index.html')
    handler._request = request
    assert '<RequestHandler GET:/index.html connected>' == repr(handler)

Example 12

Project: aiohttp
License: View license
Source File: test_web_response.py
Function: make_request
def make_request(method, path, headers=CIMultiDict(),
                 version=HttpVersion11, **kwargs):
    app = kwargs.pop('app', None) or mock.Mock()
    app._debug = False
    app.on_response_prepare = signals.Signal(app)
    writer = kwargs.pop('writer', None) or mock.Mock()
    return make_mocked_request(method, path, headers,
                               version=version, writer=writer,
                               app=app, **kwargs)

Example 13

Project: aiohttp
License: View license
Source File: test_web_websocket.py
Function: make_request
@pytest.fixture
def make_request(app, writer, reader):
    def maker(method, path, headers=None, protocols=False):
        if headers is None:
            headers = CIMultiDict(
                {'HOST': 'server.example.com',
                 'UPGRADE': 'websocket',
                 'CONNECTION': 'Upgrade',
                 'SEC-WEBSOCKET-KEY': 'dGhlIHNhbXBsZSBub25jZQ==',
                 'ORIGIN': 'http://example.com',
                 'SEC-WEBSOCKET-VERSION': '13'})
        if protocols:
            headers['SEC-WEBSOCKET-PROTOCOL'] = 'chat, superchat'

        return make_mocked_request(method, path, headers,
                                   app=app, writer=writer, reader=reader)

    return maker

Example 14

Project: aiohttp
License: View license
Source File: test_signals.py
Function: make_request
def make_request(app, method, path, headers=CIMultiDict()):
    return make_mocked_request(method, path, headers, app=app)

Example 15

Project: aiohttp
License: View license
Source File: test_test_utils.py
def test_make_mocked_request_sslcontext():
    req = make_mocked_request('GET', '/')
    assert req.transport.get_extra_info('sslcontext') is None

Example 16

Project: aiohttp
License: View license
Source File: test_test_utils.py
def test_make_mocked_request_unknown_extra_info():
    req = make_mocked_request('GET', '/')
    assert req.transport.get_extra_info('unknown_extra_info') is None

Example 17

Project: aiohttp
License: View license
Source File: test_test_utils.py
def test_make_mocked_request_app():
    app = mock.Mock()
    req = make_mocked_request('GET', '/', app=app)
    assert req.app is app

Example 18

Project: aiohttp
License: View license
Source File: test_test_utils.py
def test_make_mocked_request_content():
    payload = mock.Mock()
    req = make_mocked_request('GET', '/', payload=payload)
    assert req.content is payload

Example 19

Project: aiohttp
License: View license
Source File: test_test_utils.py
def test_make_mocked_request_transport():
    transport = mock.Mock()
    req = make_mocked_request('GET', '/', transport=transport)
    assert req.transport is transport

Example 20

Project: aiohttp
License: View license
Source File: test_urldispatch.py
Function: make_request
def make_request(method, path):
    return make_mocked_request(method, path)

Example 21

Project: aiohttp
License: View license
Source File: test_web_request.py
Function: test_clone
def test_clone():
    req = make_mocked_request('GET', '/path')
    req2 = req.clone()
    assert req2.method == 'GET'
    assert req2.rel_url == URL('/path')

Example 22

Project: aiohttp
License: View license
Source File: test_web_request.py
def test_clone_method():
    req = make_mocked_request('GET', '/path')
    req2 = req.clone(method='POST')
    assert req2.method == 'POST'
    assert req2.rel_url == URL('/path')

Example 23

Project: aiohttp
License: View license
Source File: test_web_request.py
def test_clone_rel_url():
    req = make_mocked_request('GET', '/path')
    req2 = req.clone(rel_url=URL('/path2'))
    assert req2.rel_url == URL('/path2')

Example 24

Project: aiohttp
License: View license
Source File: test_web_request.py
def test_clone_rel_url_str():
    req = make_mocked_request('GET', '/path')
    req2 = req.clone(rel_url='/path2')
    assert req2.rel_url == URL('/path2')

Example 25

Project: aiohttp
License: View license
Source File: test_web_request.py
def test_clone_headers():
    req = make_mocked_request('GET', '/path', headers={'A': 'B'})
    req2 = req.clone(headers=CIMultiDict({'B': 'C'}))
    assert req2.headers == CIMultiDict({'B': 'C'})
    assert req2.raw_headers == ((b'B', b'C'),)

Example 26

Project: aiohttp
License: View license
Source File: test_web_request.py
def test_clone_headers_dict():
    req = make_mocked_request('GET', '/path', headers={'A': 'B'})
    req2 = req.clone(headers={'B': 'C'})
    assert req2.headers == CIMultiDict({'B': 'C'})
    assert req2.raw_headers == ((b'B', b'C'),)