Example #1
0
def test_context_operations():
    ws = mock.Mock()
    context = base.BaseConnectionContext(ws)
    assert not context.has_operation(1)
    context.register_operation(1, None)
    assert context.has_operation(1)
    context.remove_operation(1)
    assert not context.has_operation(1)
    # Removing a non-existant operation fails silently.
    context.remove_operation(999)
Example #2
0
def test_observer_data():
    ws = mock.Mock()
    context = base.BaseConnectionContext(ws)
    send_result, send_error, send_message = mock.Mock(), mock.Mock(
    ), mock.Mock()
    observer = SubscriptionObserver(
        connection_context=context,
        op_id=1,
        send_execution_result=send_result,
        send_error=send_error,
        send_message=send_message,
    )
    observer.on_next("data")
    assert send_result.called
    assert not send_error.called
 def test_close(self):
     with pytest.raises(NotImplementedError):
         base.BaseConnectionContext(ws=None).close(123)
 def test_send(self):
     with pytest.raises(NotImplementedError):
         base.BaseConnectionContext(ws=None).send("TEST")
 def test_receive(self):
     with pytest.raises(NotImplementedError):
         base.BaseConnectionContext(ws=None).receive()
 def test_no_operations_initially(self):
     cc = base.BaseConnectionContext(ws=None)
     assert not cc.operations
def cc():
    cc = base.BaseConnectionContext(ws=None)
    cc.operations = {"yes": "1"}
    return cc