Ejemplo n.º 1
0
 def test_user_fd(self):
     """
     Test that user's own file descriptor can be passed to init
     """
     user_fd = StringIO()
     receiver = StreamingBodyReceiver(user_fd)
     self.assertIdentical(receiver._fd, user_fd)
Ejemplo n.º 2
0
    def test_readback_mode_off(self):
        """
        Test that when readback mode is off connectionLost() will simply
        callback finished with the fd.
        """

        receiver = StreamingBodyReceiver(readback=False)
        d = Deferred()
        receiver.finished = d
        receiver.content_length = 5
        fd = receiver._fd
        receiver.dataReceived('hello')
        why = Failure(ResponseDone('done'))
        receiver.connectionLost(why)
        self.assertIdentical(d.result, fd)
        self.assertIdentical(receiver._fd, fd)
        self.failIf(fd.closed)
Ejemplo n.º 3
0
    def test_readback_mode_on(self):
        """
        Test that when readback mode is on inside connectionLost() data will
        be read back from the start of the file we're streaming and results
        passed to finished callback.
        """

        receiver = StreamingBodyReceiver()
        d = Deferred()
        receiver.finished = d
        receiver.content_length = 5
        fd = receiver._fd
        receiver.dataReceived('hello')
        why = Failure(ResponseDone('done'))
        receiver.connectionLost(why)
        self.assertEqual(d.result, 'hello')
        self.assert_(fd.closed)
Ejemplo n.º 4
0
    def test_readback_mode_off(self):
        """
        Test that when readback mode is off connectionLost() will simply
        callback finished with the fd.
        """

        receiver = StreamingBodyReceiver(readback=False)
        d = Deferred()
        receiver.finished = d
        receiver.content_length = 5
        fd = receiver._fd
        receiver.dataReceived('hello')
        why = Failure(ResponseDone('done'))
        receiver.connectionLost(why)
        self.assertIdentical(d.result, fd)
        self.assertIdentical(receiver._fd, fd)
        self.failIf(fd.closed)
Ejemplo n.º 5
0
    def test_readback_mode_on(self):
        """
        Test that when readback mode is on inside connectionLost() data will
        be read back from the start of the file we're streaming and results
        passed to finished callback.
        """

        receiver = StreamingBodyReceiver()
        d = Deferred()
        receiver.finished = d
        receiver.content_length = 5
        fd = receiver._fd
        receiver.dataReceived('hello')
        why = Failure(ResponseDone('done'))
        receiver.connectionLost(why)
        self.assertEqual(d.result, 'hello')
        self.assert_(fd.closed)
Ejemplo n.º 6
0
 def __init__(self):
     StreamingBodyReceiver.__init__(self)
     TestReceiverProtocol.used = True
Ejemplo n.º 7
0
 def __init__(self):
     StreamingBodyReceiver.__init__(self)
     TestReceiverProtocol.used = True