|
@@ -82,6 +82,24 @@ def test__run_authentication_missing_username(mqtt_host, mqtt_port, mqtt_passwor
|
|
|
)
|
|
|
|
|
|
|
|
|
+def test__mqtt_on_message_retained(caplog):
|
|
|
+ message = MQTTMessage(topic=b"intertechno-cc1101/12345678/0/set")
|
|
|
+ message.payload = b"ON"
|
|
|
+ message.retain = True
|
|
|
+ with unittest.mock.patch("intertechno_cc1101.RemoteControl") as remote_control_mock:
|
|
|
+ with caplog.at_level(logging.DEBUG):
|
|
|
+ intertechno_cc1101_mqtt._mqtt_on_message("dummy", None, message)
|
|
|
+ remote_control_mock.assert_not_called()
|
|
|
+ assert caplog.record_tuples == [
|
|
|
+ (
|
|
|
+ "intertechno_cc1101_mqtt",
|
|
|
+ logging.DEBUG,
|
|
|
+ "received topic=intertechno-cc1101/12345678/0/set payload=b'ON'",
|
|
|
+ ),
|
|
|
+ ("intertechno_cc1101_mqtt", logging.WARNING, "ignoring retained message"),
|
|
|
+ ]
|
|
|
+
|
|
|
+
|
|
|
@pytest.mark.parametrize(
|
|
|
("topic", "address"),
|
|
|
(
|
|
@@ -200,3 +218,20 @@ def test__mqtt_on_message_transmission_failed(caplog):
|
|
|
assert caplog.records[0].levelno == logging.ERROR
|
|
|
assert caplog.records[0].message == "failed to send signal"
|
|
|
assert isinstance(caplog.records[0].exc_info[1], FileNotFoundError)
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.parametrize("payload", (b"EIN", b"aus", b""))
|
|
|
+def test__mqtt_on_message_invalid_payload(caplog, payload):
|
|
|
+ message = MQTTMessage(topic=b"intertechno-cc1101/1234/7/set")
|
|
|
+ message.payload = payload
|
|
|
+ with unittest.mock.patch("intertechno_cc1101.RemoteControl") as remote_control_mock:
|
|
|
+ intertechno_cc1101_mqtt._mqtt_on_message("dummy", None, message)
|
|
|
+ remote_control_mock().turn_off.assert_not_called()
|
|
|
+ remote_control_mock().turn_on.assert_not_called()
|
|
|
+ assert caplog.record_tuples == [
|
|
|
+ (
|
|
|
+ "intertechno_cc1101_mqtt",
|
|
|
+ 30,
|
|
|
+ "unexpected payload {!r}; expected 'ON' or 'OFF'".format(payload),
|
|
|
+ )
|
|
|
+ ]
|