Example #1
0
 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)
Example #2
0
    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()
Example #3
0
 def test_recv_without_socket_must_raise(self):
     p = NetworkHandler("tcp://localhost:28000")
     with pytest.raises(SystemError):
         p.recv()
Example #4
0
 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())
Example #5
0
 def test_send_without_socket_must_raise(self):
     p = NetworkHandler("tcp://localhost:28000")
     with pytest.raises(SystemError):
         p.send(BatsimMessage(0))
Example #6
0
 def test_close(self):
     p = NetworkHandler("tcp://localhost:28000")
     p.bind()
     p.close()
     protocol.zmq.Socket.close.assert_called()
Example #7
0
 def test_bind_when_connected_must_raise(self):
     p = NetworkHandler("tcp://localhost:28000")
     p.bind()
     with pytest.raises(SystemError):
         p.bind()