aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2023-07-23 11:25:05 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2023-07-23 11:25:05 +0200
commitef6bd01d5dddc184ca27462648713925839030fe (patch)
tree908866d01b20446607cc330d21106da471a8e67b /tests
parent126259b4c418c763ddc8a450ef17148cf4c018ad (diff)
Test connecting and disconnecting from MQTT
Diffstat (limited to 'tests')
-rw-r--r--tests/test_mqtt.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/test_mqtt.py b/tests/test_mqtt.py
new file mode 100644
index 0000000..20c1cf2
--- /dev/null
+++ b/tests/test_mqtt.py
@@ -0,0 +1,32 @@
+import time
+import unittest
+
+from kerbana import config, create_app, mqtt
+
+
+class TestMQTT(unittest.TestCase):
+ def setUp(self):
+ test_config = config.TestConfig()
+ self.app = create_app(test_config)
+ self.mqtt = mqtt.MQTTClient(self.app)
+ self.mqtt.connect()
+ time.sleep(0.1)
+ if not self.mqtt.connected:
+ self.skipTest("Could not find an mqtt server")
+
+ def tearDown(self):
+ self.mqtt.disconnect(reconnect=False)
+
+ def test_disconnect(self):
+ # after disconnecting from the mqtt server, we should
+ # automatically reconnect
+ self.mqtt.disconnect()
+ time.sleep(2)
+ self.assertTrue(self.mqtt.connected)
+
+ def test_disconnect_and_stay(self):
+ # unless we really want to force a disconnection
+ self.mqtt.disconnect(reconnect=False)
+ time.sleep(2)
+ self.assertFalse(self.mqtt.connected)
+ self.assertFalse(self.mqtt.reconnect)