Ejemplo n.º 1
0
def test_delitem(app):
    signal = Signal(app)
    m1 = mock.Mock()
    signal.append(m1)
    assert len(signal) == 1
    del signal[0]
    assert len(signal) == 0
Ejemplo n.º 2
0
def function2805(function1121):
    var1658 = Signal(function1121)
    var921 = mock.Mock()
    var1658.append(var921)
    assert (len(var1658) == 1)
    del var1658[0]
    assert (len(var1658) == 0)
Ejemplo n.º 3
0
def test_delitem(app):
    signal = Signal(app)
    m1 = mock.Mock()
    signal.append(m1)
    assert len(signal) == 1
    del signal[0]
    assert len(signal) == 0
Ejemplo n.º 4
0
def test_setitem(app):
    signal = Signal(app)
    m1 = mock.Mock()
    signal.append(m1)
    assert signal[0] is m1
    m2 = mock.Mock()
    signal[0] = m2
    assert signal[0] is m2
Ejemplo n.º 5
0
def function1396(function1121):
    var3642 = Signal(function1121)
    var1856 = mock.Mock()
    var3642.append(var1856)
    assert (var3642[0] is var1856)
    var259 = mock.Mock()
    var3642[0] = var259
    assert (var3642[0] is var259)
Ejemplo n.º 6
0
def test_setitem(app):
    signal = Signal(app)
    m1 = mock.Mock()
    signal.append(m1)
    assert signal[0] is m1
    m2 = mock.Mock()
    signal[0] = m2
    assert signal[0] is m2
Ejemplo n.º 7
0
async def test_repr(app: Any) -> None:
    signal = Signal(app)

    callback = make_mocked_coro()

    signal.append(callback)

    assert Matches(r"<Signal owner=<Application .+>, frozen=False, "
                   r"\[<Mock id='\d+'>\]>") == repr(signal)
Ejemplo n.º 8
0
def test_cannot_delitem_in_frozen_signal(app):
    signal = Signal(app)
    m1 = mock.Mock()
    signal.append(m1)
    signal.freeze()
    with pytest.raises(RuntimeError):
        del signal[0]

    assert list(signal) == [m1]
Ejemplo n.º 9
0
def test_non_coroutine(loop, app):
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback = mock.Mock()

    signal.append(callback)

    loop.run_until_complete(signal.send(**kwargs))
    callback.assert_called_once_with(**kwargs)
Ejemplo n.º 10
0
async def test_repr(app) -> None:
    signal = Signal(app)

    callback = make_mocked_coro()

    signal.append(callback)

    assert re.match(r"<Signal owner=<Application .+>, frozen=False, "
                    r"\[<Mock id='\d+'>\]>",
                    repr(signal))
Ejemplo n.º 11
0
def test_cannot_setitem_in_frozen_signal(app) -> None:
    signal = Signal(app)
    m1 = mock.Mock()
    m2 = mock.Mock()
    signal.append(m1)
    signal.freeze()
    with pytest.raises(RuntimeError):
        signal[0] = m2

    assert list(signal) == [m1]
Ejemplo n.º 12
0
async def test_repr(app):
    signal = Signal(app)

    callback = make_mocked_coro()

    signal.append(callback)

    assert re.match(
        r"<Signal owner=<Application .+>, frozen=False, "
        r"\[<Mock id='\d+'>\]>", repr(signal))
Ejemplo n.º 13
0
def test_non_coroutine(app):
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback = mock.Mock()

    signal.append(callback)

    yield from signal.send(**kwargs)
    callback.assert_called_once_with(**kwargs)
Ejemplo n.º 14
0
def function1362(function1121):
    var676 = Signal(function1121)
    var2961 = {
        'foo': 1,
        'bar': 2,
    }
    function382 = mock.Mock()
    var676.append(function382)
    yield from var676.send(None=var2961)
    function382.assert_called_once_with(None=var2961)
Ejemplo n.º 15
0
async def test_non_coroutine(app):
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback = mock.Mock()

    signal.append(callback)

    await signal.send(**kwargs)
    callback.assert_called_once_with(**kwargs)
Ejemplo n.º 16
0
async def test_cannot_send_non_frozen_signal(app) -> None:
    signal = Signal(app)

    callback = make_mocked_coro()

    signal.append(callback)

    with pytest.raises(RuntimeError):
        await signal.send()

    assert not callback.called
Ejemplo n.º 17
0
async def test_non_coroutine(app) -> None:
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback = mock.Mock()

    signal.append(callback)
    signal.freeze()

    with pytest.raises(TypeError):
        await signal.send(**kwargs)
Ejemplo n.º 18
0
async def test_cannot_send_non_frozen_signal(app):
    signal = Signal(app)

    callback = make_mocked_coro()

    signal.append(callback)

    with pytest.raises(RuntimeError):
        await signal.send()

    assert not callback.called
Ejemplo n.º 19
0
def function1281(function2688):
    assert function2688.debug, 'Should be True'
    var3888 = Signal(function2688)
    function382 = mock.Mock()
    var3839 = mock.Mock()
    var835 = mock.Mock()
    var3888.append(function382)
    function2688.on_pre_signal.append(var3839)
    function2688.on_post_signal.append(var835)
    yield from var3888.send(1, a=2)
    function382.assert_called_once_with(1, a=2)
    var3839.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2)
    var835.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2)
Ejemplo n.º 20
0
async def test_function_signal_dispatch(app):
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback_mock = mock.Mock()

    async def callback(**kwargs):
        callback_mock(**kwargs)

    signal.append(callback)

    await signal.send(**kwargs)
    callback_mock.assert_called_once_with(**kwargs)
Ejemplo n.º 21
0
def test_function_signal_dispatch(loop, app):
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback_mock = mock.Mock()

    @asyncio.coroutine
    def callback(**kwargs):
        callback_mock(**kwargs)

    signal.append(callback)

    loop.run_until_complete(signal.send(**kwargs))
    callback_mock.assert_called_once_with(**kwargs)
Ejemplo n.º 22
0
def test_function_signal_dispatch(app):
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback_mock = mock.Mock()

    @asyncio.coroutine
    def callback(**kwargs):
        callback_mock(**kwargs)

    signal.append(callback)

    yield from signal.send(**kwargs)
    callback_mock.assert_called_once_with(**kwargs)
Ejemplo n.º 23
0
async def test_function_signal_dispatch(app) -> None:
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback_mock = mock.Mock()

    async def callback(**kwargs):
        callback_mock(**kwargs)

    signal.append(callback)
    signal.freeze()

    await signal.send(**kwargs)
    callback_mock.assert_called_once_with(**kwargs)
Ejemplo n.º 24
0
async def test_function_signal_dispatch2(app):
    signal = Signal(app)
    args = {'a', 'b'}
    kwargs = {'foo': 1, 'bar': 2}

    callback_mock = mock.Mock()

    @asyncio.coroutine
    def callback(*args, **kwargs):
        callback_mock(*args, **kwargs)

    signal.append(callback)

    await signal.send(*args, **kwargs)
    callback_mock.assert_called_once_with(*args, **kwargs)
Ejemplo n.º 25
0
def test_function_signal_dispatch2(loop, app):
    signal = Signal(app)
    args = {"a", "b"}
    kwargs = {"foo": 1, "bar": 2}

    callback_mock = mock.Mock()

    @asyncio.coroutine
    def callback(*args, **kwargs):
        callback_mock(*args, **kwargs)

    signal.append(callback)

    loop.run_until_complete(signal.send(*args, **kwargs))
    callback_mock.assert_called_once_with(*args, **kwargs)
Ejemplo n.º 26
0
def test_sort_forbidden(app):
    def l1():
        pass

    def l2():
        pass

    def l3():
        pass

    signal = Signal(app)
    signal.extend([l1, l2, l3])
    with pytest.raises(NotImplementedError):
        signal.sort()
    assert signal == [l1, l2, l3]
Ejemplo n.º 27
0
def function105(function1121):
    var3164 = Signal(function1121)
    var96 = {
        'foo': 1,
        'bar': 2,
    }
    var2570 = mock.Mock()

    @asyncio.coroutine
    def function382(**kwargs):
        var2570(None=var96)

    var3164.append(function382)
    yield from var3164.send(None=var96)
    var2570.assert_called_once_with(None=var96)
Ejemplo n.º 28
0
async def test_debug_signal(debug_app):
    assert debug_app.debug, "Should be True"
    signal = Signal(debug_app)

    callback = mock.Mock()
    pre = mock.Mock()
    post = mock.Mock()

    signal.append(callback)
    debug_app.on_pre_signal.append(pre)
    debug_app.on_post_signal.append(post)

    await signal.send(1, a=2)
    callback.assert_called_once_with(1, a=2)
    pre.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2)
    post.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2)
Ejemplo n.º 29
0
    def make_request(self,
                     method,
                     path,
                     query_params={},
                     headers=None,
                     match_info=None):
        if query_params:
            path = '%s?%s' % (path, urllib.parse.urlencode(query_params))

        # Ported from:
        # https://github.com/KeepSafe/aiohttp/blob/fa06acc2392c516491bdb25301ad3ef2b700ff5f/tests/test_web_websocket.py#L21-L45  # noqa
        self.app = mock.Mock()
        self.app._debug = 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-PROTOCOL': 'chat, superchat',
                'SEC-WEBSOCKET-VERSION': '13'
            })

        message = make_raw_request_message(method, path, headers)
        self.payload = mock.Mock()
        self.transport = mock.Mock()
        self.reader = mock.Mock()
        self.writer = mock.Mock()
        self.app.loop = self.loop
        self.app.on_response_prepare = Signal(self.app)
        req = Request(self.app, message, self.payload, self.transport,
                      self.reader, self.writer)
        req._match_info = match_info
        return req
Ejemplo n.º 30
0
def test_debug_signal(loop, debug_app):
    assert debug_app.debug, "Should be True"
    signal = Signal(debug_app)

    callback = mock.Mock()
    pre = mock.Mock()
    post = mock.Mock()

    signal.append(callback)
    debug_app.on_pre_signal.append(pre)
    debug_app.on_post_signal.append(post)

    loop.run_until_complete(signal.send(1, a=2))
    callback.assert_called_once_with(1, a=2)
    pre.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2)
    post.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2)
Ejemplo n.º 31
0
def test_debug_signal(debug_app):
    assert debug_app.debug, "Should be True"
    signal = Signal(debug_app)

    callback = mock.Mock()
    pre = mock.Mock()
    post = mock.Mock()

    signal.append(callback)
    debug_app.on_pre_signal.append(pre)
    debug_app.on_post_signal.append(post)

    yield from signal.send(1, a=2)
    callback.assert_called_once_with(1, a=2)
    pre.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2)
    post.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2)
Ejemplo n.º 32
0
def function590(function1121):
    var906 = Signal(function1121)
    var730 = {'a', 'b'}
    var1090 = {
        'foo': 1,
        'bar': 2,
    }
    var852 = mock.Mock()

    @asyncio.coroutine
    def function382(*args, **kwargs):
        var852(*var730, None=var1090)

    var906.append(function382)
    yield from var906.send(*var730, None=var1090)
    var852.assert_called_once_with(*var730, None=var1090)
Ejemplo n.º 33
0
    def maker(method, path, headers=CIMultiDict(), *,
              version=HttpVersion(1, 1), closing=False,
              sslcontext=None,
              secure_proxy_ssl_header=None):
        if version < HttpVersion(1, 1):
            closing = True
        app = mock.Mock()
        app._debug = False
        app.on_response_prepare = Signal(app)
        message = RawRequestMessage(method, path, version, headers,
                                    [(k.encode('utf-8'), v.encode('utf-8'))
                                     for k, v in headers.items()],
                                    closing, False)
        payload = mock.Mock()
        transport = mock.Mock()

        def get_extra_info(key):
            if key == 'sslcontext':
                return sslcontext
            else:
                return None

        transport.get_extra_info.side_effect = get_extra_info
        writer = mock.Mock()
        reader = mock.Mock()
        req = Request(app, message, payload,
                      transport, reader, writer,
                      secure_proxy_ssl_header=secure_proxy_ssl_header)

        assert req.app is app
        assert req.content is payload
        assert req.transport is transport

        return req
Ejemplo n.º 34
0
def function2183(function1121):
    var4737 = Signal(function1121)
    var805 = mock.Mock()
    var3494 = mock.Mock()
    var4737.append(var805)
    var4737.freeze()
    with pytest.raises(RuntimeError):
        var4737.append(var3494)
    assert (list(var4737) == [var805])
Ejemplo n.º 35
0
def test_cannot_append_to_frozen_signal(app):
    signal = Signal(app)
    m1 = mock.Mock()
    m2 = mock.Mock()
    signal.append(m1)
    signal.freeze()
    with pytest.raises(RuntimeError):
        signal.append(m2)

    assert list(signal) == [m1]
Ejemplo n.º 36
0
def test_cannot_append_to_frozen_signal(app):
    signal = Signal(app)
    m1 = mock.Mock()
    m2 = mock.Mock()
    signal.append(m1)
    signal.freeze()
    with pytest.raises(RuntimeError):
        signal.append(m2)

    assert list(signal) == [m1]
Ejemplo n.º 37
0
    def __init__(self):
        self._state = {}
        self._frozen = False

        self._on_startup = Signal(self)
        self._on_shutdown = Signal(self)
        self._on_cleanup = Signal(self)
Ejemplo n.º 38
0
def function2296(function1121):
    var2457 = Signal(function1121)
    var2367 = mock.Mock()
    var2457.append(var2367)
    var2457.freeze()
    with pytest.raises(RuntimeError):
        del var2457[0]
    assert (list(var2457) == [var2367])
Ejemplo n.º 39
0
def test_cannot_delitem_in_frozen_signal(app):
    signal = Signal(app)
    m1 = mock.Mock()
    signal.append(m1)
    signal.freeze()
    with pytest.raises(RuntimeError):
        del signal[0]

    assert list(signal) == [m1]
Ejemplo n.º 40
0
def function2559(function1121):
    var98 = Signal(function1121)
    var2142 = mock.Mock()
    var516 = mock.Mock()
    var98.append(var2142)
    var98.freeze()
    with pytest.raises(RuntimeError):
        var98[0] = var516
    assert (list(var98) == [var2142])
Ejemplo n.º 41
0
def test_sort_forbidden(app):
    l1 = lambda: None
    l2 = lambda: None
    l3 = lambda: None
    signal = Signal(app)
    signal.extend([l1, l2, l3])
    with pytest.raises(NotImplementedError):
        signal.sort()
    assert signal == [l1, l2, l3]
Ejemplo n.º 42
0
def test_cannot_setitem_in_frozen_signal(app: Any) -> None:
    signal = Signal(app)
    m1 = mock.Mock()
    m2 = mock.Mock()
    signal.append(m1)
    signal.freeze()
    with pytest.raises(RuntimeError):
        signal[0] = m2

    assert list(signal) == [m1]
Ejemplo n.º 43
0
async def test_non_coroutine(app):
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback = mock.Mock()

    signal.append(callback)
    signal.freeze()

    with pytest.raises(TypeError):
        await signal.send(**kwargs)
Ejemplo n.º 44
0
def test_copy_forbidden(app):
    signal = Signal(app)
    with pytest.raises(NotImplementedError):
        signal.copy()