Beispiel #1
0
 def test_empty_data(self, *args):
     c = Client()
     c._socket.send_recv.return_value = b'200 OK'
     resp = c.call('PING', {'key': 'value'})
     c._socket.send_recv.assert_called_with(b'PING key=value')
     self.assertEqual(resp.code, 200)
     self.assertEqual(resp.message, 'OK')
     self.assertFalse(resp.data)
Beispiel #2
0
 def test_single_data(self, *args):
     c = Client()
     c._socket.send_recv.return_value = b'200 OK\nA|B|C'
     resp = c.call('PING', {'key': 'value'})
     c._socket.send_recv.assert_called_with(b'PING key=value')
     self.assertEqual(resp.code, 200)
     self.assertEqual(resp.message, 'OK')
     self.assertTupleEqual(resp.data, (('A', 'B', 'C'), ))
Beispiel #3
0
    def test_ping(self, *args):
        c = Client()

        c.call.return_value = Response(300, 'PONG')
        pong = c.ping()
        c.call.assert_called_with('PING')
        self.assertTrue(pong)

        c.call.return_value = Response(500, 'SOME ERROR')
        pong = c.ping()
        c.call.assert_called_with('PING')
        self.assertFalse(pong)
Beispiel #4
0
    def test_auth_logout(self, *args):
        c = Client()

        c.call.return_value = Response(200, 'sess LOGIN ACCEPTED')

        c.auth('user', 'pass')

        # First item is list of positional arguments
        call_command, call_params = c.call.call_args[0]

        self.assertEqual(call_command, 'AUTH')

        for param in ('user', 'pass', 'protover', 'client', 'clientver'):
            self.assertIn(param, call_params)

        self.assertEqual(call_params['user'], 'user')
        self.assertEqual(call_params['pass'], 'pass')

        self.assertTrue(c.is_logged_in())
        self.assertEqual(c._session, 'sess')

        c.call.return_value = Response(203, 'LOGGED OUT')

        c.logout()

        # First item is list of positional arguments
        call_command = c.call.call_args[0][0]

        self.assertEqual(call_command, 'LOGOUT')
        self.assertFalse(c.is_logged_in())
        self.assertIsNone(c._session)
Beispiel #5
0
    def test_encoding(self, *args):
        c = Client()

        c.call.return_value = Response(200, 'sess LOGIN ACCEPTED')
        c.auth('user', 'pass')

        c.call.return_value = Response(219, 'ENCODING CHANGED')
        c.encoding('UTF-8')

        self.assertEqual(c._codec.encoding, 'UTF-8')

        c.call.return_value = Response(203, 'LOGGED OUT')
        c.logout()

        # Encoding should be reset to default after logout
        self.assertEqual(c._codec.encoding, Client.ENCODING)
Beispiel #6
0
    def test_params_converting(self, *args):
        c = Client()
        c._socket.send_recv.return_value = b'200 OK\n'

        with self.subTest(type=bool):
            c.call('PING', {'key': True})
            c._socket.send_recv.assert_called_with(b'PING key=1')

        with self.subTest(type=None):
            c.call('PING', {'key': None})
            c._socket.send_recv.assert_called_with(b'PING key=')
Beispiel #7
0
 def test_send_recv_none(self, *args):
     c = Client(None, None, None)
     c._socket._socket.recv.return_value = b'200 OK'
     c.call('PING')
     c._socket._socket.sendto.assert_called_with(b'PING', Client.SERVER)
Beispiel #8
0
 def test_init_none(self, *args):
     c = Client(None, None, None)
     self.assertEqual(c._socket.server, Client.SERVER)
     c._socket._socket.bind.assert_called_once_with(('0.0.0.0', Client.LOCALPORT))
     c._socket._socket.settimeout.assert_called_once_with(4)
Beispiel #9
0
 def test_unescape(self, *args):
     c = Client()
     c._socket.send_recv.return_value = b'200 OK\nmulti<br />line|pi/pe|`apo`'
     resp = c.call('PING')
     self.assertTupleEqual(resp.data, (('multi\nline', 'pi/pe', "`apo`"), ))
Beispiel #10
0
 def test_escape(self, *args):
     c = Client()
     c._socket.send_recv.return_value = b'200 OK'
     c.call('PING', {'key': 'line\n&'})
     c._socket.send_recv.assert_called_with(b'PING key=line<br />&amp;')