예제 #1
0
 def test_recv_all_large(self):
     connection = Connection('host', 1)
     connection._sock = mock.MagicMock()
     buf = io.BytesIO((b'foo' * 1500) + b'\r\n')
     connection._sock.recv = lambda buf_size: buf.read(100)
     response = connection._recv_all()
     expected = ('foo' * 1500) + '\r\n'
     self.assertEqual(response, expected)
예제 #2
0
 def test_recv_all_no_newline(self):
     connection = Connection('host', 1)
     connection._sock = mock.MagicMock()
     buf = io.BytesIO(b'foo')
     connection._sock.recv = lambda buf_size: buf.read()
     response = connection._recv_all()
     expected = 'foo'
     self.assertEqual(response, expected)
예제 #3
0
 def _get_connection(self):
     # TODO: Try random trackers, implement retries
     host, port = self._trackers[0]
     connection = Connection(host, port)
     connection._connect()
     return connection
예제 #4
0
 def test_no_socket_on_instantiation(self):
     connection = Connection('host', 1)
     self.assertFalse(hasattr(connection, '_sock'))
예제 #5
0
 def test_connect_settimeout(self):
     connection = Connection('host', 1)
     with mock.patch('socket.socket'):
         connection._connect()
         connection._sock.settimeout.assert_called_with(10)
예제 #6
0
 def test_connect(self):
     connection = Connection('host', 1)
     with mock.patch('socket.socket'):
         connection._connect()
         connection._sock.connect.assert_called_with(('host', 1))
예제 #7
0
 def test_do_request_requires_request_instance(self):
     connection = Connection('host', 1)
     with self.assertRaises(AssertionError):
         connection.do_request('test')
예제 #8
0
 def test_noop(self):
     connection = Connection('host', 1)
     connection._sock = mock.MagicMock()
     buf = io.BytesIO(b'OK\r\n')
     connection._sock.recv = lambda buf_size: buf.read()
     connection.noop()
예제 #9
0
 def test_no_socket_on_instantiation(self):
     connection = Connection('host', 1)
     self.assertEqual(None, connection._sock)
예제 #10
0
파일: backend.py 프로젝트: hrchu/pymogilefs
 def __init__(self, trackers):
     self._trackers = [[Connection(*tracker.split(':')), 0]
                       for tracker in trackers]