Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mqtt internal url in tests #239

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
14 changes: 8 additions & 6 deletions tests/clients/test_ngsi_v2_cb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would rename mqtt_sub_url to mqtt_url because only the internal URL is the subscription URL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been changed now

mqtt_url_internal = settings.MQTT_BROKER_URL_INTERNAL
entity = ContextEntity.model_validate({
"id": "Test:001",
"type": "Test",
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -602,7 +604,7 @@ def test_notification(self):
},
"notification": {
"mqtt": {
"url": mqtt_sub_url,
"url": mqtt_url_internal,
"topic": mqtt_topic
},
"attrs": ["temperature"]
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down