From a449ca862033577cdb3d2f4984b66f6cf1811f06 Mon Sep 17 00:00:00 2001 From: Andreas Heinrich Date: Fri, 16 Feb 2024 09:53:02 +0100 Subject: [PATCH 1/2] Add connected-mqtt-client fixture Signed-off-by: Andreas Heinrich --- .../src/everest/testing/core_utils/fixtures.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/everest-testing/src/everest/testing/core_utils/fixtures.py b/everest-testing/src/everest/testing/core_utils/fixtures.py index dc65c808..ae93f3da 100644 --- a/everest-testing/src/everest/testing/core_utils/fixtures.py +++ b/everest-testing/src/everest/testing/core_utils/fixtures.py @@ -4,6 +4,8 @@ from typing import Optional import pytest +import os +import paho.mqtt.client as mqtt from ._configuration.everest_configuration_strategies.everest_configuration_strategy import \ EverestConfigAdjustmentStrategy @@ -116,3 +118,13 @@ def test_controller(request, tmp_path, everest_core) -> EverestTestController: # FIXME (aw): proper life time management, shouldn't the fixure start and stop? test_controller.stop() + +@pytest.fixture +def connected_mqtt_client(everest_core: EverestCore) -> mqtt.Client: + mqtt_server_uri = os.environ.get("MQTT_SERVER_ADDRESS", "127.0.0.1") + mqtt_server_port = int(os.environ.get("MQTT_SERVER_PORT", "1883")) + client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, everest_core.everest_uuid) + client.connect(mqtt_server_uri, mqtt_server_port) + client.loop_start() + + return client From a95e641d110cf40dc54fa0f293347a36b218b18f Mon Sep 17 00:00:00 2001 From: Jan <154529400+djchhp@users.noreply.github.com> Date: Thu, 7 Mar 2024 12:49:13 +0100 Subject: [PATCH 2/2] MQTT fixed * Fixing paho-mqtt version * livetime management mqtt client in fixture Signed-off-by: Jan <154529400+djchhp@users.noreply.github.com> --- everest-testing/setup.cfg | 2 +- everest-testing/src/everest/testing/core_utils/fixtures.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/everest-testing/setup.cfg b/everest-testing/setup.cfg index 779fb14b..99a3bbc5 100644 --- a/everest-testing/setup.cfg +++ b/everest-testing/setup.cfg @@ -17,7 +17,7 @@ install_requires = pytest pytest-asyncio python-dateutil - paho-mqtt + paho-mqtt ==1.6.1 pyftpdlib ocpp websockets diff --git a/everest-testing/src/everest/testing/core_utils/fixtures.py b/everest-testing/src/everest/testing/core_utils/fixtures.py index ae93f3da..c2271552 100644 --- a/everest-testing/src/everest/testing/core_utils/fixtures.py +++ b/everest-testing/src/everest/testing/core_utils/fixtures.py @@ -123,8 +123,10 @@ def test_controller(request, tmp_path, everest_core) -> EverestTestController: def connected_mqtt_client(everest_core: EverestCore) -> mqtt.Client: mqtt_server_uri = os.environ.get("MQTT_SERVER_ADDRESS", "127.0.0.1") mqtt_server_port = int(os.environ.get("MQTT_SERVER_PORT", "1883")) - client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, everest_core.everest_uuid) + client = mqtt.Client(everest_core.everest_uuid) client.connect(mqtt_server_uri, mqtt_server_port) client.loop_start() - return client + yield client + + client.loop_stop()