Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis-chambers committed Jun 20, 2024
1 parent 0d27357 commit 7227b75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/iotswarm/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
)

Expand Down
10 changes: 6 additions & 4 deletions src/tests/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -242,15 +242,15 @@ 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):
"""Tests that default topic gets set"""

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, ""],
Expand All @@ -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"]
Expand All @@ -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):
Expand Down

0 comments on commit 7227b75

Please sign in to comment.