@@ -49,8 +49,10 @@ def test_create_client(self):
4949 # Verify not connected by default.
5050 self .assertFalse (client .is_connected ())
5151
52- def test_connect (self ):
53- # Create MQTT test client.
52+ def test_secure_connect (self ):
53+ """Test a secure (port 8883, TLS enabled) AIO connection
54+ """
55+ # Create MQTT-Secure test client.
5456 client = MQTTClient (self .get_test_username (), self .get_test_key ())
5557 # Verify on_connect handler is called and expected client is provided.
5658 def on_connect (mqtt_client ):
@@ -61,6 +63,25 @@ def on_connect(mqtt_client):
6163 self .wait_until_connected (client )
6264 # Verify connected.
6365 self .assertTrue (client .is_connected ())
66+ self .assertTrue (client ._secure )
67+
68+ def test_insecure_connect (self ):
69+ """Test an insecure (port 1883, TLS disabled) AIO connection
70+ """
71+ # Create MQTT-Insecure (non-SSL) test client.
72+ client = MQTTClient (self .get_test_username (), self .get_test_key (), secure = False )
73+ # Verify on_connect handler is called and expected client is provided.
74+ def on_connect (mqtt_client ):
75+ self .assertEqual (mqtt_client , client )
76+ client .on_connect = on_connect
77+ # Connect and wait until on_connect event is fired.
78+ client .connect ()
79+ self .wait_until_connected (client )
80+ # Verify connected.
81+ self .assertTrue (client .is_connected ())
82+ # Verify insecure connection established
83+ self .assertFalse (client ._secure )
84+
6485
6586 def test_disconnect (self ):
6687 # Create MQTT test client.
@@ -100,4 +121,4 @@ def on_message(mqtt_client, feed, payload):
100121 client .loop ()
101122 time .sleep (0 )
102123 # Verify one update message with payload is received.
103- self .assertListEqual (messages , [('TestFeed' , '42' )])
124+ self .assertListEqual (messages , [('TestFeed' , '42' )])
0 commit comments