예제 #1
0
    def test_is_expired(self, mock_socket):
        conn = TcpConnection('localhost', 2000, lifetime=1)
        conn.open()

        ok_(not conn.is_expired())
        time.sleep(1)
        ok_(conn.is_expired())
예제 #2
0
    def test_close(self, mock_socket):
        conn = TcpConnection('localhost', 2000)
        conn.open()
        conn.close()

        conn.get().close.assert_called_once_with()
        ok_(not conn.is_connected())
예제 #3
0
    def test_recv(self, mock_socket):
        conn = TcpConnection('localhost', 2000)
        conn.open()

        conn.recv(20)
        conn.socket.recv.assert_called_once_with(20)
예제 #4
0
    def test_send(self, mock_socket):
        conn = TcpConnection('localhost', 2000)
        conn.open()

        conn.send('dummy')
        conn.socket.send.assert_called_once_with('dummy')
예제 #5
0
    def test_open_with_timeout(self, mock_socket):
        conn = TcpConnection('localhost', 2000, timeout=10)
        conn.open()

        conn.socket.settimeout.assert_called_once_with(10)
예제 #6
0
    def test_open(self, mock_socket):
        conn = TcpConnection('localhost', 2000)
        conn.open()
        conn.socket.connect.assert_called_once_with(('localhost', 2000))

        ok_(conn.is_connected())
예제 #7
0
    def test_socket_creation(self, mock_socket):
        TcpConnection('localhost', 2000)

        mock_socket.assert_called_once_with(socket.AF_INET, socket.SOCK_STREAM)
예제 #8
0
    def test_recv(self, mock_socket):
        conn = TcpConnection('localhost', 2000)
        conn.open()

        conn.recv(20)
        conn.get().recv.assert_called_once_with(20)