Ejemplo n.º 1
0
    def test_write_two_chunks(self):
        cmd = 'ECHO'
        payload = "x" * 512
        msg = writer(cmd, payload)

        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.write(cmd, payload)

        self.assertEqual(sock_mock.sendall.call_args_list, [call(msg)])
Ejemplo n.º 2
0
    def test_write_two_chunks(self):
        cmd = 'ECHO'
        payload = "x" * 512
        msg = writer(cmd, payload)

        sock_mock = Mock()

        sock_mock.send.side_effect = [500, 34]
        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.write(cmd, payload)

        self.assertEqual(sock_mock.send.call_args_list, [call(msg), call(msg[500:])])
Ejemplo n.º 3
0
    def test_write_one_chunk(self):
        cmd = u'ECHO'
        payload = u"x" * 512
        msg = writer(cmd, payload)
        length = 534

        sock_mock = Mock()

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

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

        connection = pyredis.connection.Connection(host=u'127.0.0.1', encoding=u'utf-8')
        connection._authenticate = Mock()
        connection._setdb = Mock()
        connection.write(cmd, payload)

        self.assertEqual(sock_mock.send.call_args_list, [call(msg)])
Ejemplo n.º 4
0
 def test_encode_3_args(self):
     expected = b'*3\r\n$3\r\nSET\r\n$8\r\nKey/Name\r\n$19\r\nSomeValue_?#!\xc3\x84\xc3\x9c\xc3\x96\r\n'
     self.assertEqual(writer('SET', 'Key/Name', 'SomeValue_?#!ÄÜÖ'),
                      expected)
Ejemplo n.º 5
0
 def test_encode_2_args(self):
     expected = b'*2\r\n$4\r\nECHO\r\n$14\r\nTest!!!!111elf\r\n'
     self.assertEqual(writer('ECHO', 'Test!!!!111elf'), expected)
Ejemplo n.º 6
0
 def test_encode_1_args(self):
     expected = b'*1\r\n$4\r\nPING\r\n'
     self.assertEqual(writer('PING'), expected)
Ejemplo n.º 7
0
 def test_encode_0_args(self):
     expected = b'*0\r\n'
     self.assertEqual(writer(), expected)
Ejemplo n.º 8
0
 def test_encode_3_args(self):
     expected = b'*3\r\n$3\r\nSET\r\n$8\r\nKey/Name\r\n$19\r\nSomeValue_?#!\xc3\x84\xc3\x9c\xc3\x96\r\n'
     self.assertEqual(
         writer('SET', 'Key/Name', 'SomeValue_?#!ÄÜÖ'),
         expected)
Ejemplo n.º 9
0
 def test_encode_2_args(self):
     expected = b'*2\r\n$4\r\nECHO\r\n$14\r\nTest!!!!111elf\r\n'
     self.assertEqual(
         writer('ECHO', 'Test!!!!111elf'),
         expected)
Ejemplo n.º 10
0
 def test_encode_1_args(self):
     expected = b'*1\r\n$4\r\nPING\r\n'
     self.assertEqual(
         writer('PING'),
         expected)
Ejemplo n.º 11
0
 def test_encode_0_args(self):
     expected = b'*0\r\n'
     self.assertEqual(
         writer(),
         expected)