From 05acabc8ad774f7a2f281df0e0798f86ca8208c3 Mon Sep 17 00:00:00 2001 From: JunsongDu Date: Tue, 6 Feb 2024 11:24:46 +0100 Subject: [PATCH 1/3] feat: add mqtt internal url in tests --- tests/clients/test_ngsi_v2_cb.py | 14 ++++++++------ tests/config.py | 12 +++++++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tests/clients/test_ngsi_v2_cb.py b/tests/clients/test_ngsi_v2_cb.py index 5179dcd7..d5036fb3 100644 --- a/tests/clients/test_ngsi_v2_cb.py +++ b/tests/clients/test_ngsi_v2_cb.py @@ -453,10 +453,11 @@ def test_subscription_set_status(self): iota_url=settings.IOTA_JSON_URL) def test_mqtt_subscriptions(self): mqtt_url = settings.MQTT_BROKER_URL + mqtt_url_internal = settings.MQTT_BROKER_URL_INTERNAL mqtt_topic = ''.join([settings.FIWARE_SERVICE, settings.FIWARE_SERVICEPATH]) notification = self.subscription.notification.model_copy( - update={'http': None, 'mqtt': Mqtt(url=mqtt_url, + update={'http': None, 'mqtt': Mqtt(url=mqtt_url_internal, topic=mqtt_topic)}) subscription = self.subscription.model_copy( update={'notification': notification, @@ -533,6 +534,7 @@ def on_disconnect(client, userdata, reasonCode, properties=None): cb_url=settings.CB_URL) def test_notification(self): mqtt_sub_url = settings.MQTT_BROKER_URL + mqtt_url_internal = settings.MQTT_BROKER_URL_INTERNAL entity = ContextEntity.model_validate({ "id": "Test:001", "type": "Test", @@ -562,7 +564,7 @@ def test_notification(self): }, "notification": { "mqtt": { - "url": mqtt_sub_url, + "url": mqtt_url_internal, "topic": mqtt_topic }, "attrs": [] # empty attrs list @@ -582,7 +584,7 @@ def test_notification(self): }, "notification": { "mqtt": { - "url": mqtt_sub_url, + "url": mqtt_url_internal, "topic": mqtt_topic }, "attrs": None # attrs = None @@ -602,7 +604,7 @@ def test_notification(self): }, "notification": { "mqtt": { - "url": mqtt_sub_url, + "url": mqtt_url_internal, "topic": mqtt_topic }, "attrs": ["temperature"] @@ -649,8 +651,8 @@ def on_disconnect(client, userdata, reasonCode, properties=None): mqtt_client.on_message = on_message mqtt_client.on_disconnect = on_disconnect # connect to the server - mqtt_client.connect(host=settings.MQTT_BROKER_URL.host, - port=settings.MQTT_BROKER_URL.port, + mqtt_client.connect(host=mqtt_sub_url.host, + port=mqtt_sub_url.port, keepalive=60, bind_address="", bind_port=0, diff --git a/tests/config.py b/tests/config.py index f06249b3..097e0c24 100644 --- a/tests/config.py +++ b/tests/config.py @@ -44,9 +44,15 @@ class TestSettings(BaseSettings): 'QL_URL')) MQTT_BROKER_URL: AnyUrl = Field(default="mqtt://127.0.0.1:1883", - validation_alias=AliasChoices('MQTT_BROKER_URL', - 'MQTT_URL', - 'MQTT_BROKER')) + validation_alias=AliasChoices( + 'MQTT_BROKER_URL', + 'MQTT_URL', + 'MQTT_BROKER')) + + MQTT_BROKER_URL_INTERNAL: AnyUrl = Field(default="mqtt://mosquitto:1883", + validation_alias=AliasChoices( + 'MQTT_BROKER_URL_INTERNAL', + 'MQTT_URL_INTERNAL')) # IF CI_JOB_ID is present it will always overwrite the service path CI_JOB_ID: Optional[str] = Field(default=None, From a559c26fdc97a1835540f01afda66a9ddc6fb464 Mon Sep 17 00:00:00 2001 From: JunsongDu Date: Tue, 6 Feb 2024 11:28:21 +0100 Subject: [PATCH 2/3] chore: update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index de0d0a48..9e7de6c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ #### v0.3.1 - add tutorial for protected endpoint with bearer authentication ([#208](https://github.com/RWTH-EBC/FiLiP/issues/208)) +- add internal mqtt url for unittests @djs0109 ([#239](https://github.com/RWTH-EBC/FiLiP/pull/239)) - fix: compare subscriptions to prevent duplicated notifications @FWuellhorst, @RCX112 ([#138](https://github.com/RWTH-EBC/FiLiP/pull/138)) - update pandas version to `~=2.1.4` for `python>=3.9` ([#231](https://github.com/RWTH-EBC/FiLiP/pull/231)) - fix: wrong msg in iotac post device ([#214](https://github.com/RWTH-EBC/FiLiP/pull/214)) From c3635f60c0690958b9df8b5318979327177fda44 Mon Sep 17 00:00:00 2001 From: JunsongDu Date: Wed, 14 Feb 2024 11:45:53 +0100 Subject: [PATCH 3/3] chore: consistent naming convention --- tests/clients/test_ngsi_v2_cb.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/clients/test_ngsi_v2_cb.py b/tests/clients/test_ngsi_v2_cb.py index d5036fb3..1c7faa4e 100644 --- a/tests/clients/test_ngsi_v2_cb.py +++ b/tests/clients/test_ngsi_v2_cb.py @@ -533,7 +533,7 @@ def on_disconnect(client, userdata, reasonCode, properties=None): fiware_servicepath=settings.FIWARE_SERVICEPATH, cb_url=settings.CB_URL) def test_notification(self): - mqtt_sub_url = settings.MQTT_BROKER_URL + mqtt_url = settings.MQTT_BROKER_URL mqtt_url_internal = settings.MQTT_BROKER_URL_INTERNAL entity = ContextEntity.model_validate({ "id": "Test:001", @@ -651,8 +651,8 @@ def on_disconnect(client, userdata, reasonCode, properties=None): mqtt_client.on_message = on_message mqtt_client.on_disconnect = on_disconnect # connect to the server - mqtt_client.connect(host=mqtt_sub_url.host, - port=mqtt_sub_url.port, + mqtt_client.connect(host=mqtt_url.host, + port=mqtt_url.port, keepalive=60, bind_address="", bind_port=0,