Skip to content

Commit

Permalink
chore: add test for unregistered attribute name
Browse files Browse the repository at this point in the history
  • Loading branch information
djs0109 committed Oct 1, 2024
1 parent f930fe3 commit 25c5f09
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions tests/clients/test_mqtt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,34 +154,36 @@ def test_optional_object_id(self):
tmp_attrs = [DeviceAttribute(name="temperature",
type="Number"),
DeviceAttribute(name="temperature",
type="Number",
object_id="temp")]
type="Number",
object_id="temp")]

payloads = [{"temperature":Random().randint(0,50)},
{"t":Random().randint(0,50)}]
{"temp":Random().randint(0,50)}]

for p,attr in zip(payloads,tmp_attrs):
tmp_dev = Device(device_id=tmp_id,
attributes=[attr],
entity_name="tmp_entity",
entity_type="tmp_type",
apikey="tmp_key",
transport=TransportProtocol.MQTT,
protocol=PayloadProtocol.IOTA_JSON)
attributes=[attr],
entity_name="tmp_entity",
entity_type="tmp_type",
apikey="tmp_key",
transport=TransportProtocol.MQTT,
protocol=PayloadProtocol.IOTA_JSON)
tmp_mqttc = IoTAMQTTClient(protocol=MQTTv5 ,devices=[tmp_dev])
tmp_mqttc.publish(device_id=tmp_id,payload=p)
tmp_mqttc.delete_device(device_id=tmp_id)

#checking if raises correctly
with self.assertRaises(KeyError):
tmp_dev = Device(device_id=tmp_id,
attributes=[tmp_attrs[0]],
entity_name="tmp_entity",
entity_type="tmp_type",
apikey="tmp_key",
transport=TransportProtocol.MQTT,
protocol=PayloadProtocol.IOTA_JSON)
tmp_mqttc.publish(device_id=tmp_id,payload={"t":Random().randint(0,50)})
attributes=[tmp_attrs[0]],
entity_name="tmp_entity",
entity_type="tmp_type",
apikey="tmp_key",
transport=TransportProtocol.MQTT,
protocol=PayloadProtocol.IOTA_JSON)
tmp_mqttc = IoTAMQTTClient(protocol=MQTTv5, devices=[tmp_dev])
tmp_mqttc.publish(device_id=tmp_id,
payload={"t": Random().randint(0,50)})
tmp_mqttc.delete_device(device_id=tmp_id)

def test_init(self):
Expand Down

0 comments on commit 25c5f09

Please sign in to comment.