From 7227b752639ef2238627b3857e80f4446e76290a Mon Sep 17 00:00:00 2001 From: Lewis Chambers Date: Thu, 20 Jun 2024 08:51:45 +0100 Subject: [PATCH] Updated tests --- src/iotswarm/devices.py | 2 +- src/tests/test_devices.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/iotswarm/devices.py b/src/iotswarm/devices.py index 0e2fe0d..2b2cd1d 100644 --- a/src/iotswarm/devices.py +++ b/src/iotswarm/devices.py @@ -200,7 +200,7 @@ def __repr__(self): mqtt_topic_arg = ( f', mqtt_topic="{self.mqtt_base_topic}"' if hasattr(self, "mqtt_base_topic") - and self.mqtt_base_topic != f"{self.device_type}/{self.device_id}" + and self.mqtt_base_topic != self.device_id else "" ) diff --git a/src/tests/test_devices.py b/src/tests/test_devices.py index ec5f881..efb61d3 100644 --- a/src/tests/test_devices.py +++ b/src/tests/test_devices.py @@ -221,7 +221,7 @@ def test_mqtt_prefix_set(self, topic): inst = BaseDevice("site", self.db, self.conn, mqtt_prefix=topic) self.assertEqual(inst.mqtt_prefix, topic) - self.assertEqual(inst.mqtt_topic, f"{topic}/base-device/site") + self.assertEqual(inst.mqtt_topic, f"{topic}/site") @parameterized.expand(["this/topic", "1/1/1", "TOPICO!"]) @config_exists @@ -231,7 +231,7 @@ def test_mqtt_suffix_set(self, topic): inst = BaseDevice("site", self.db, self.conn, mqtt_suffix=topic) self.assertEqual(inst.mqtt_suffix, topic) - self.assertEqual(inst.mqtt_topic, f"base-device/site/{topic}") + self.assertEqual(inst.mqtt_topic, f"site/{topic}") @parameterized.expand([["this/prefix", "this/suffix"], ["1/1/1", "2/2/2"], ["TOPICO!", "FOUR"]]) @config_exists @@ -242,7 +242,7 @@ def test_mqtt_prefix_and_suffix_set(self, prefix, suffix): self.assertEqual(inst.mqtt_suffix, suffix) self.assertEqual(inst.mqtt_prefix, prefix) - self.assertEqual(inst.mqtt_topic, f"{prefix}/base-device/site/{suffix}") + self.assertEqual(inst.mqtt_topic, f"{prefix}/site/{suffix}") @config_exists def test_default_mqtt_topic_set(self): @@ -250,7 +250,7 @@ def test_default_mqtt_topic_set(self): inst = BaseDevice("site-12", self.db, self.conn) - self.assertEqual(inst.mqtt_topic, "base-device/site-12") + self.assertEqual(inst.mqtt_topic, "site-12") @parameterized.expand([ [None, None, None, ""], @@ -268,6 +268,7 @@ def test__repr__mqtt_opts_mqtt_connection(self, topic, prefix, suffix,expected_a class TestBaseDeviceOracleUsed(unittest.IsolatedAsyncioTestCase): + async def asyncSetUp(self): cred_path = str(CONFIG_PATH) creds = config.Config(cred_path)["oracle"] @@ -284,6 +285,7 @@ async def asyncTearDown(self) -> None: @parameterized.expand([-1, -423.78, CosmosQuery.ORACLE_LATEST_DATA, "Four", MockDB(), {"a": 1}]) @config_exists + @pytest.mark.oracle def test_table_value_check(self, table): with self.assertRaises(TypeError):