Commits

Anonymous committed 0532762

More connection unit tests.

Comments (0)

Files changed (1)

stompclient/tests/test_connection.py

 import stompclient.connection
 from stompclient.connection import (ThreadLocalConnectionPool, ConnectionPool, Connection, 
                                     ConnectionError, ConnectionTimeoutError, NotConnectedError)
+from stompclient import frame
+
 from stompclient.tests.mockutil import MockingSocketModule
 
 __authors__ = ['"Hans Lellelid" <hans@xmpl.org>']
         
         self.assertRaises(ConnectionTimeoutError, conn.connect)
     
+    def test_auto_connect(self):
+        """ Test the fact that send and read automatically attempt to connect. """
+        conn = Connection('1.2.3.4', 61613)
+        conn.send("MESSAGE")
+        self.assertTrue(self.mocksocket.connect.called)
+        conn.disconnect()
+        
+        f = frame.ConnectedFrame('my-session-id')
+        self.mocksocket.reset_mock()
+        self.mocksocket.recv.side_effect = lambda len: str(f)
+        
+        result = conn.read()
+        self.assertEquals(str(f), str(result))
+        self.assertTrue(self.mocksocket.connect.called)
+        
     def test_disconnect_notconnected(self):
         conn = Connection('1.2.3.4', 61613)
         self.assertRaises(NotConnectedError, conn.disconnect)
         conn.disconnect()
         
         self.assertFalse(conn.connected)
-        class F(object):
-            def __str__(self):
-                return "FRAME_STR"
             
-        conn.send(F())
+        conn.send("MESSAGE")
         
         self.assertTrue(self.mocksocket.connect.called)
         self.assertTrue(self.mocksocket.sendall.called)