Skip to content

Commit

Permalink
Merge pull request #239 from RWTH-EBC/238-Adding-a-second-Test-config…
Browse files Browse the repository at this point in the history
…uration-when-using-FIWARE-components-inside-Docker

feat: add mqtt internal url in tests
  • Loading branch information
djs0109 authored Feb 14, 2024
2 parents 5a97e4f + c3635f6 commit 3acda05
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
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
16 changes: 9 additions & 7 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 @@ -532,7 +533,8 @@ 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",
"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_url.host,
port=mqtt_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

0 comments on commit 3acda05

Please sign in to comment.