def test_bind(self): a = "tcp://localhost:28000" p = NetworkHandler(a) p.bind() assert p.is_connected assert p.address == a protocol.zmq.Socket.bind.assert_called_once_with(a)
def test_recv(self, mocker): msg = BatsimMessage(0) mocker.patch.object(protocol.zmq.Socket, 'recv_json', return_value=msg) p = NetworkHandler("tcp://localhost:28000") p.bind() m = p.recv() assert m == msg protocol.zmq.Socket.recv_json.assert_called_once()
def test_recv_without_socket_must_raise(self): p = NetworkHandler("tcp://localhost:28000") with pytest.raises(SystemError): p.recv()
def test_send(self): msg = BatsimMessage(0) p = NetworkHandler("tcp://localhost:28000") p.bind() p.send(msg) protocol.zmq.Socket.send_json.assert_called_once_with(msg.to_json())
def test_send_without_socket_must_raise(self): p = NetworkHandler("tcp://localhost:28000") with pytest.raises(SystemError): p.send(BatsimMessage(0))
def test_close(self): p = NetworkHandler("tcp://localhost:28000") p.bind() p.close() protocol.zmq.Socket.close.assert_called()
def test_bind_when_connected_must_raise(self): p = NetworkHandler("tcp://localhost:28000") p.bind() with pytest.raises(SystemError): p.bind()