Skip to content

Commit

Permalink
test_on_topic ensure connected before sending publish message
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-acmehi authored and Kim Kempf committed Oct 26, 2020
1 parent 403320a commit 39bbec6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/test_integration.py
Expand Up @@ -125,6 +125,7 @@ def test_on_topic(self):
self.mqtt = Mqtt(self.app)
self.handled_message = False
self.handled_topic = False
self.connected = False

@self.mqtt.on_message()
def handle_message(client, userdata, message):
Expand All @@ -136,14 +137,19 @@ def handle_on_topic(*args, **kwargs):

@self.mqtt.on_connect()
def handle_connect(*args, **kwargs):
self.connected = True
self.mqtt.subscribe('home/test')

self.assertFalse(self.connected)
self.mqtt.init_app(self.app)
wait()
self.mqtt.publish('home/test', 'hello world')
wait()

self.assertFalse(self.handled_message)
self.assertTrue(self.handled_topic)
self.assertTrue(self.connected)
self.mqtt._disconnect()

def test_logging(self):
self.mqtt = Mqtt(self.app)
Expand Down

0 comments on commit 39bbec6

Please sign in to comment.