From 40e0ef54a0befc1330ac772ef1d3151001014639 Mon Sep 17 00:00:00 2001 From: Antonio Ojea <6450081+aojea@users.noreply.github.com> Date: Sun, 27 Jan 2019 10:23:26 +0100 Subject: [PATCH] Add unit test for SSLTransport _write function (#251) Reference: https://github.com/celery/py-amqp/issues/249 --- t/unit/test_transport.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/t/unit/test_transport.py b/t/unit/test_transport.py index 85bd3018..eeeedb00 100644 --- a/t/unit/test_transport.py +++ b/t/unit/test_transport.py @@ -622,6 +622,27 @@ def test_read_EOF(self): match=r'.*Server unexpectedly closed connection.*'): self.t._read(64) + def test_write_success(self): + self.t.sock = Mock(name='SSLSocket') + self.t.sock.write.return_value = 2 + self.t._write('foo') + self.t.sock.write.assert_called() + + def test_write_socket_closed(self): + self.t.sock = Mock(name='SSLSocket') + self.t.sock.write.return_value = '' + with pytest.raises(IOError, + match=r'.*Socket closed.*'): + self.t._write('foo') + + def test_write_ValueError(self): + self.t.sock = Mock(name='SSLSocket') + self.t.sock.write.return_value = 2 + self.t.sock.write.side_effect = ValueError("Some error") + with pytest.raises(IOError, + match=r'.*Socket closed.*'): + self.t._write('foo') + class test_TCPTransport: