diff --git a/tests/lib/clients/03-publish-b2c-qos1.py b/tests/lib/clients/03-publish-b2c-qos1.py index 81beef96..71ac9508 100644 --- a/tests/lib/clients/03-publish-b2c-qos1.py +++ b/tests/lib/clients/03-publish-b2c-qos1.py @@ -10,7 +10,7 @@ def on_message(mqttc, obj, msg): assert msg.topic == "pub/qos1/receive", f"Invalid topic: ({msg.topic})" assert msg.payload == expected_payload, f"Invalid payload: ({msg.payload})" assert msg.qos == 1, f"Invalid qos: ({msg.qos})" - assert msg.retain is not False, f"Invalid retain: ({msg.retain})" + assert not msg.retain, f"Invalid retain: ({msg.retain})" def on_connect(mqttc, obj, flags, rc): diff --git a/tests/lib/clients/03-publish-b2c-qos2.py b/tests/lib/clients/03-publish-b2c-qos2.py index 96e01d5e..e3b14926 100644 --- a/tests/lib/clients/03-publish-b2c-qos2.py +++ b/tests/lib/clients/03-publish-b2c-qos2.py @@ -1,6 +1,8 @@ +import logging + import paho.mqtt.client as mqtt -from tests.paho_test import get_test_server_port, wait_for_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt expected_payload = b"message" @@ -10,20 +12,17 @@ def on_message(mqttc, obj, msg): assert msg.topic == "pub/qos2/receive", f"Invalid topic: ({msg.topic})" assert msg.payload == expected_payload, f"Invalid payload: ({msg.payload})" assert msg.qos == 2, f"Invalid qos: ({msg.qos})" - assert msg.retain is not False, f"Invalid retain: ({msg.retain})" + assert not msg.retain, f"Invalid retain: ({msg.retain})" def on_connect(mqttc, obj, flags, rc): assert rc == 0, f"Connect failed ({rc})" - +logging.basicConfig(level=logging.DEBUG) mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, "publish-qos2-test", clean_session=True) +mqttc.enable_logger() mqttc.on_connect = on_connect mqttc.on_message = on_message mqttc.connect("localhost", get_test_server_port()) - -with wait_for_keyboard_interrupt(): - while True: - if mqttc.loop(0.3): - break +loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/test_03_publish_b2c_qos1.py b/tests/lib/test_03_publish_b2c_qos1.py index 16b3275a..32578ddd 100644 --- a/tests/lib/test_03_publish_b2c_qos1.py +++ b/tests/lib/test_03_publish_b2c_qos1.py @@ -8,8 +8,6 @@ # "pub/qos1/receive", payload of "message", QoS=1 and mid=123. The client # should handle this as per the spec by sending a PUBACK message. # The client should then exit with return code==0. -import pytest - import tests.paho_test as paho_test connect_packet = paho_test.gen_connect("publish-qos1-test", keepalive=60) @@ -23,8 +21,6 @@ puback_packet = paho_test.gen_puback(mid) -# msg.retain changed when typing was added -@pytest.mark.xfail def test_03_publish_b2c_qos1(server_socket, start_client): start_client("03-publish-b2c-qos1.py") diff --git a/tests/lib/test_03_publish_b2c_qos2.py b/tests/lib/test_03_publish_b2c_qos2.py new file mode 100644 index 00000000..781938f9 --- /dev/null +++ b/tests/lib/test_03_publish_b2c_qos2.py @@ -0,0 +1,41 @@ +# Test whether a client responds correctly to a PUBLISH with QoS 1. + +# The client should connect with keepalive=60, clean session set, +# and client id publish-qos1-test +# The test will send a CONNACK message to the client with rc=0. Upon receiving +# the CONNACK the client should verify that rc==0. +# The test will send the client a PUBLISH message with topic +# "pub/qos1/receive", payload of "message", QoS=1 and mid=123. The client +# should handle this as per the spec by sending a PUBACK message. +# The client should then exit with return code==0. +import tests.paho_test as paho_test + +connect_packet = paho_test.gen_connect("publish-qos2-test", keepalive=60) +connack_packet = paho_test.gen_connack(rc=0) + +disconnect_packet = paho_test.gen_disconnect() + +mid = 13423 +publish_packet = paho_test.gen_publish( + "pub/qos2/receive", qos=2, mid=mid, payload="message") +pubrec_packet = paho_test.gen_pubrec(mid=mid) +pubrel_packet = paho_test.gen_pubrel(mid=mid) +pubcomp_packet = paho_test.gen_pubcomp(mid) + + +def test_03_publish_b2c_qos2(server_socket, start_client): + start_client("03-publish-b2c-qos2.py") + + (conn, address) = server_socket.accept() + conn.settimeout(10) + + paho_test.expect_packet(conn, "connect", connect_packet) + conn.send(connack_packet) + conn.send(publish_packet) + + paho_test.expect_packet(conn, "pubrec", pubrec_packet) + conn.send(pubrel_packet) + + paho_test.expect_packet(conn, "pubcomp", pubcomp_packet) + + conn.close()