コード例 #1
0
ファイル: test_connection.py プロジェクト: alozovskoy/pyredis
    def test__connect_ipv6(self):
        sock_mock = Mock()
        self.socket_mock.socket.return_value = sock_mock
        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(host='::1')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        connection._connect()

        sock_mock.settimeout.assert_called_with(2)
コード例 #2
0
ファイル: test_connection.py プロジェクト: alozovskoy/pyredis
    def test__close(self):
        sock_mock = Mock()
        self.socket_mock.socket.return_value = sock_mock

        connection = pyredis.connection.Connection(unix_sock='/tmp/test.sock')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        connection._connect()
        connection.close()

        sock_mock.close.assert_called_with()
        self.assertIsNone(connection._sock)
        self.assertIsNone(connection._reader)
        self.assertTrue(connection._closed)
コード例 #3
0
ファイル: test_connection.py プロジェクト: d0znpp/pyredis
    def test__connect_ipv6(self):
        sock_mock = Mock()
        self.socket_mock.socket.return_value = sock_mock
        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(host='::1')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        connection._connect()

        sock_mock.settimeout.assert_called_with(2)
        connection._authenticate.assertcalledwith()
        connection._setdb.assertcalledwith()
コード例 #4
0
ファイル: test_connection.py プロジェクト: d0znpp/pyredis
    def test__close(self):
        sock_mock = Mock()
        self.socket_mock.socket.return_value = sock_mock

        connection = pyredis.connection.Connection(unix_sock='/tmp/test.sock')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        connection._connect()
        connection.close()

        sock_mock.close.assert_called_with()
        self.assertIsNone(connection._sock)
        self.assertIsNone(connection._reader)
        self.assertTrue(connection._closed)
コード例 #5
0
ファイル: test_connection.py プロジェクト: alozovskoy/pyredis
    def test_read_exception_connection_lost(self):
        sock_mock = Mock()
        sock_mock.recv.side_effect = ['']
        self.socket_mock.socket.return_value = sock_mock

        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(host='127.0.0.1', encoding='utf-8')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        pyredis.connection.Reader = Reader
        connection._connect()
        self.assertRaises(PyRedisConnClosed, connection.read)
        self.assertTrue(connection.closed)
コード例 #6
0
ファイル: test_connection.py プロジェクト: d0znpp/pyredis
    def test_read_exception_connection_lost(self):
        sock_mock = Mock()
        sock_mock.recv.side_effect = ['']
        self.socket_mock.socket.return_value = sock_mock

        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(host='127.0.0.1', encoding='utf-8')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        pyredis.connection.Reader = Reader
        connection._connect()
        self.assertRaises(PyRedisConnClosed, connection.read)
        self.assertTrue(connection.closed)
コード例 #7
0
ファイル: test_connection.py プロジェクト: d0znpp/pyredis
    def test__connect_unix(self):
        sock_mock = Mock()
        self.socket_mock.socket.return_value = sock_mock
        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(unix_sock='/tmp/test.sock')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        connection._connect()

        sock_mock.settimeout.assert_called_with(2)
        self.assertEqual(connection._sock, self.socket_mock.socket())
        connection._authenticate.assertcalledwith()
        connection._setdb.assertcalledwith()
コード例 #8
0
ファイル: test_connection.py プロジェクト: qygaojs/pyredis
    def test__connect_unix(self):
        sock_mock = Mock()
        self.socket_mock.socket.return_value = sock_mock
        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(unix_sock='/tmp/test.sock')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        connection._connect()

        sock_mock.settimeout.assert_called_with(2)
        self.assertEqual(connection._sock, self.socket_mock.socket())
        connection._authenticate.assertcalledwith()
        connection._setdb.assertcalledwith()
コード例 #9
0
ファイル: test_connection.py プロジェクト: d0znpp/pyredis
    def test_read_exception_socket_timeout_close_on_timeout_false(self):
        sock_mock = Mock()
        sock_mock.recv.side_effect = [socket.timeout]
        self.socket_mock.socket.return_value = sock_mock
        self.socket_mock.timeout = socket.timeout

        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(host='127.0.0.1', encoding='utf-8')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        pyredis.connection.Reader = Reader
        connection._connect()
        self.assertRaises(PyRedisConnReadTimeout, connection.read, close_on_timeout=False)
        self.assertFalse(connection.closed)
コード例 #10
0
ファイル: test_connection.py プロジェクト: alozovskoy/pyredis
    def test__connect_ipv4_encoding_utf_8(self):
        sock_mock = Mock()
        self.socket_mock.socket.return_value = sock_mock
        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(host='127.0.0.1', encoding='utf-8')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        connection._connect()

        sock_mock.settimeout.assert_called_with(2)
        self.assertEqual(connection._sock, self.socket_mock.socket())
        self.assertEqual(connection._encoding, 'utf-8')
        self.assertEqual(connection._reader, reader_mock)
        self.reader_mock.assert_called_with(encoding='utf-8')
コード例 #11
0
ファイル: test_connection.py プロジェクト: alozovskoy/pyredis
    def test_read_exception_socket_timeout_close_on_timeout_false(self):
        sock_mock = Mock()
        sock_mock.recv.side_effect = [socket.timeout]
        self.socket_mock.socket.return_value = sock_mock
        self.socket_mock.timeout = socket.timeout

        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(host='127.0.0.1', encoding='utf-8')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        pyredis.connection.Reader = Reader
        connection._connect()
        self.assertRaises(PyRedisConnReadTimeout, connection.read, close_on_timeout=False)
        self.assertFalse(connection.closed)
コード例 #12
0
ファイル: test_connection.py プロジェクト: d0znpp/pyredis
    def test_write_exception_brokenpipeerror(self):
        cmd = 'ECHO'
        payload = "x" * 512

        sock_mock = Mock()

        sock_mock.send.side_effect = [BrokenPipeError]
        self.socket_mock.socket.return_value = sock_mock

        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(host='127.0.0.1', encoding='utf-8')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        connection._connect()
        self.assertRaises(PyRedisConnError, connection.write, cmd, payload)
コード例 #13
0
ファイル: test_connection.py プロジェクト: alozovskoy/pyredis
    def test_write_exception_brokenpipeerror(self):
        cmd = 'ECHO'
        payload = "x" * 512

        sock_mock = Mock()

        sock_mock.sendall.side_effect = [BrokenPipeError]
        self.socket_mock.socket.return_value = sock_mock

        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(host='127.0.0.1', encoding='utf-8')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        connection._connect()
        self.assertRaises(PyRedisConnError, connection.write, cmd, payload)
コード例 #14
0
ファイル: test_connection.py プロジェクト: w-vi/pyredis
    def test_authenticate_sentinel(self):
        connection = pyredis.connection.Connection(host='127.0.0.1',
                                                   encoding='utf-8',
                                                   sentinel=True)
        authenticate_mock = Mock()
        setdb_mock = Mock()
        set_read_only_mock = Mock()

        connection._authenticate = authenticate_mock
        connection._setdb = setdb_mock
        connection._set_read_only = set_read_only_mock

        connection._connect()

        authenticate_mock.assert_called()
        setdb_mock.assert_not_called()
        set_read_only_mock.assert_not_called()
コード例 #15
0
ファイル: test_connection.py プロジェクト: d0znpp/pyredis
    def test_read_one_chunk_two_messages(self):
        raw_answer = b'$10\r\nXXXXXXXXXX\r\n$10\r\nYYYYYYYYYY\r\n'
        answer = 'XXXXXXXXXX'

        sock_mock = Mock()
        sock_mock.recv.side_effect = [raw_answer]
        self.socket_mock.socket.return_value = sock_mock

        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(host='127.0.0.1', encoding='utf-8')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        pyredis.connection.Reader = Reader
        connection._connect()
        result = connection.read()
        self.assertEqual(result, answer)
コード例 #16
0
ファイル: test_connection.py プロジェクト: d0znpp/pyredis
    def test__connect_ipv4_encoding_utf_8(self):
        sock_mock = Mock()
        self.socket_mock.socket.return_value = sock_mock
        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(host='127.0.0.1', encoding='utf-8')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        connection._connect()

        sock_mock.settimeout.assert_called_with(2)
        self.assertEqual(connection._sock, self.socket_mock.socket())
        self.assertEqual(connection._encoding, 'utf-8')
        self.assertEqual(connection._reader, reader_mock)
        self.reader_mock.assert_called_with(encoding='utf-8')
        connection._authenticate.assertcalledwith()
        connection._setdb.assertcalledwith()
コード例 #17
0
ファイル: test_connection.py プロジェクト: alozovskoy/pyredis
    def test_read_one_chunk_two_messages(self):
        raw_answer = b'$10\r\nXXXXXXXXXX\r\n$10\r\nYYYYYYYYYY\r\n'
        answer = 'XXXXXXXXXX'

        sock_mock = Mock()
        sock_mock.recv.side_effect = [raw_answer]
        self.socket_mock.socket.return_value = sock_mock

        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(host='127.0.0.1', encoding='utf-8')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        pyredis.connection.Reader = Reader
        connection._connect()
        result = connection.read()
        self.assertEqual(result, answer)
コード例 #18
0
ファイル: test_connection.py プロジェクト: d0znpp/pyredis
    def test_read_message_ready_from_previous_chunck(self):
        raw_answer = b'$10\r\nXXXXXXXXXX\r\n$10\r\nYYYYYYYYYY\r\n'
        answer1 = 'XXXXXXXXXX'
        answer2 = 'YYYYYYYYYY'

        sock_mock = Mock()
        sock_mock.recv.side_effect = [raw_answer]
        self.socket_mock.socket.return_value = sock_mock

        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(host='127.0.0.1', encoding='utf-8')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        pyredis.connection.Reader = Reader
        connection._connect()
        result1 = connection.read()
        result2 = connection.read()
        self.assertEqual(result1, answer1)
        self.assertEqual(result2, answer2)
        self.assertEqual(sock_mock.recv.call_args_list, [call(1500)])
コード例 #19
0
ファイル: test_connection.py プロジェクト: alozovskoy/pyredis
    def test_read_message_ready_from_previous_chunck(self):
        raw_answer = b'$10\r\nXXXXXXXXXX\r\n$10\r\nYYYYYYYYYY\r\n'
        answer1 = 'XXXXXXXXXX'
        answer2 = 'YYYYYYYYYY'

        sock_mock = Mock()
        sock_mock.recv.side_effect = [raw_answer]
        self.socket_mock.socket.return_value = sock_mock

        reader_mock = Mock()
        self.reader_mock.return_value = reader_mock

        connection = pyredis.connection.Connection(host='127.0.0.1', encoding='utf-8')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        pyredis.connection.Reader = Reader
        connection._connect()
        result1 = connection.read()
        result2 = connection.read()
        self.assertEqual(result1, answer1)
        self.assertEqual(result2, answer2)
        self.assertEqual(sock_mock.recv.call_args_list, [call(1500)])