diff options
| author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2023-12-08 10:20:36 +0100 | 
|---|---|---|
| committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2023-12-29 07:29:15 +0100 | 
| commit | 5973b7ca26e63880e9d74a52fa9e2ec61c811401 (patch) | |
| tree | 818b1d3e0a9daeb9561c8771f2dea06e906bf693 /rrd/tests | |
| parent | 0a56d27c3b0f590e0eef85666bb0d10d36041089 (diff) | |
Management command for the mqtt loop
Diffstat (limited to 'rrd/tests')
| -rw-r--r-- | rrd/tests/__init__.py | 0 | ||||
| -rw-r--r-- | rrd/tests/test_django.py | 5 | ||||
| -rw-r--r-- | rrd/tests/test_mqtt.py | 30 | 
3 files changed, 35 insertions, 0 deletions
diff --git a/rrd/tests/__init__.py b/rrd/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/rrd/tests/__init__.py diff --git a/rrd/tests/test_django.py b/rrd/tests/test_django.py new file mode 100644 index 0000000..e0fbb45 --- /dev/null +++ b/rrd/tests/test_django.py @@ -0,0 +1,5 @@ +from django.test import TestCase + +# Create your tests here. + + diff --git a/rrd/tests/test_mqtt.py b/rrd/tests/test_mqtt.py new file mode 100644 index 0000000..4ea0852 --- /dev/null +++ b/rrd/tests/test_mqtt.py @@ -0,0 +1,30 @@ +import time + +import django.test + +from .. import mqtt + +class TestMQTT(django.test.TestCase): +    def setUp(self): +        self.mqtt = mqtt.MQTTClient() +        self.mqtt.loop_start() +        time.sleep(0.1) +        if not self.mqtt.connected: +            self.skipTest("Could not find an mqtt server") + +    def tearDown(self): +        self.mqtt.loop_stop() + +    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)  | 
