mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-08-07 09:13:04 +02:00
Split up community broker fields and reformat MQTT config page
This commit is contained in:
@@ -9,14 +9,12 @@ import pytest
|
||||
from app.community_mqtt import (
|
||||
_CLIENT_ID,
|
||||
_DEFAULT_BROKER,
|
||||
_DEFAULT_PORT,
|
||||
CommunityMqttPublisher,
|
||||
_base64url_encode,
|
||||
_calculate_packet_hash,
|
||||
_ed25519_sign_expanded,
|
||||
_format_raw_packet,
|
||||
_generate_jwt_token,
|
||||
_parse_broker_address,
|
||||
community_mqtt_broadcast,
|
||||
)
|
||||
from app.models import AppSettings
|
||||
@@ -423,33 +421,6 @@ class TestCommunityMqttBroadcast:
|
||||
mock_task.assert_not_called()
|
||||
|
||||
|
||||
class TestParseBrokerAddress:
|
||||
def test_hostname_only_uses_default_port(self):
|
||||
host, port = _parse_broker_address("mqtt-us-v1.letsmesh.net")
|
||||
assert host == "mqtt-us-v1.letsmesh.net"
|
||||
assert port == _DEFAULT_PORT
|
||||
|
||||
def test_hostname_with_port(self):
|
||||
host, port = _parse_broker_address("mqtt-us-v1.letsmesh.net:8883")
|
||||
assert host == "mqtt-us-v1.letsmesh.net"
|
||||
assert port == 8883
|
||||
|
||||
def test_hostname_with_port_443(self):
|
||||
host, port = _parse_broker_address("broker.example.com:443")
|
||||
assert host == "broker.example.com"
|
||||
assert port == 443
|
||||
|
||||
def test_invalid_port_uses_default(self):
|
||||
host, port = _parse_broker_address("broker.example.com:abc")
|
||||
assert host == "broker.example.com:abc"
|
||||
assert port == _DEFAULT_PORT
|
||||
|
||||
def test_empty_string(self):
|
||||
host, port = _parse_broker_address("")
|
||||
assert host == ""
|
||||
assert port == _DEFAULT_PORT
|
||||
|
||||
|
||||
class TestPublishFailureSetsDisconnected:
|
||||
@pytest.mark.asyncio
|
||||
async def test_publish_error_sets_connected_false(self):
|
||||
|
||||
@@ -929,13 +929,15 @@ class TestMigration032:
|
||||
# Verify all columns exist with correct defaults
|
||||
cursor = await conn.execute(
|
||||
"""SELECT community_mqtt_enabled, community_mqtt_iata,
|
||||
community_mqtt_broker, community_mqtt_email
|
||||
community_mqtt_broker_host, community_mqtt_broker_port,
|
||||
community_mqtt_email
|
||||
FROM app_settings WHERE id = 1"""
|
||||
)
|
||||
row = await cursor.fetchone()
|
||||
assert row["community_mqtt_enabled"] == 0
|
||||
assert row["community_mqtt_iata"] == ""
|
||||
assert row["community_mqtt_broker"] == "mqtt-us-v1.letsmesh.net"
|
||||
assert row["community_mqtt_broker_host"] == "mqtt-us-v1.letsmesh.net"
|
||||
assert row["community_mqtt_broker_port"] == 443
|
||||
assert row["community_mqtt_email"] == ""
|
||||
finally:
|
||||
await conn.close()
|
||||
|
||||
@@ -504,7 +504,8 @@ class TestAppSettingsRepository:
|
||||
"mqtt_publish_raw_packets": 0,
|
||||
"community_mqtt_enabled": 0,
|
||||
"community_mqtt_iata": "",
|
||||
"community_mqtt_broker": "mqtt-us-v1.letsmesh.net",
|
||||
"community_mqtt_broker_host": "mqtt-us-v1.letsmesh.net",
|
||||
"community_mqtt_broker_port": 443,
|
||||
"community_mqtt_email": "",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -126,21 +126,24 @@ class TestUpdateSettings:
|
||||
AppSettingsUpdate(
|
||||
community_mqtt_enabled=True,
|
||||
community_mqtt_iata="DEN",
|
||||
community_mqtt_broker="custom-broker.example.com",
|
||||
community_mqtt_broker_host="custom-broker.example.com",
|
||||
community_mqtt_broker_port=8883,
|
||||
community_mqtt_email="test@example.com",
|
||||
)
|
||||
)
|
||||
|
||||
assert result.community_mqtt_enabled is True
|
||||
assert result.community_mqtt_iata == "DEN"
|
||||
assert result.community_mqtt_broker == "custom-broker.example.com"
|
||||
assert result.community_mqtt_broker_host == "custom-broker.example.com"
|
||||
assert result.community_mqtt_broker_port == 8883
|
||||
assert result.community_mqtt_email == "test@example.com"
|
||||
|
||||
# Verify persistence
|
||||
fresh = await AppSettingsRepository.get()
|
||||
assert fresh.community_mqtt_enabled is True
|
||||
assert fresh.community_mqtt_iata == "DEN"
|
||||
assert fresh.community_mqtt_broker == "custom-broker.example.com"
|
||||
assert fresh.community_mqtt_broker_host == "custom-broker.example.com"
|
||||
assert fresh.community_mqtt_broker_port == 8883
|
||||
assert fresh.community_mqtt_email == "test@example.com"
|
||||
|
||||
# Verify restart was called
|
||||
|
||||
Reference in New Issue
Block a user