mirror of
https://github.com/smittix/intercept.git
synced 2026-06-16 09:29:45 -07:00
Fix observer location persistence and APRS defaults
This commit is contained in:
+64
-13
@@ -1,9 +1,9 @@
|
||||
"""Tests for Flask routes and API endpoints."""
|
||||
|
||||
import json
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
"""Tests for Flask routes and API endpoints."""
|
||||
|
||||
import json
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
@@ -103,8 +103,8 @@ class TestDependenciesEndpoint:
|
||||
assert 'modes' in data
|
||||
|
||||
|
||||
class TestSettingsEndpoints:
|
||||
"""Tests for settings API endpoints."""
|
||||
class TestSettingsEndpoints:
|
||||
"""Tests for settings API endpoints."""
|
||||
|
||||
def test_get_settings(self, client):
|
||||
"""Test getting all settings."""
|
||||
@@ -172,8 +172,8 @@ class TestSettingsEndpoints:
|
||||
assert data['status'] == 'success'
|
||||
assert data['value'] == 'updated_value'
|
||||
|
||||
def test_delete_setting(self, client):
|
||||
"""Test deleting a setting."""
|
||||
def test_delete_setting(self, client):
|
||||
"""Test deleting a setting."""
|
||||
# First create a setting
|
||||
client.post(
|
||||
'/settings',
|
||||
@@ -185,9 +185,60 @@ class TestSettingsEndpoints:
|
||||
response = client.delete('/settings/delete_me')
|
||||
assert response.status_code == 200
|
||||
|
||||
data = json.loads(response.data)
|
||||
assert data['status'] == 'success'
|
||||
assert data['deleted'] is True
|
||||
data = json.loads(response.data)
|
||||
assert data['status'] == 'success'
|
||||
assert data['deleted'] is True
|
||||
|
||||
def test_save_observer_location_updates_env_and_runtime_defaults(self, client, monkeypatch, tmp_path):
|
||||
"""Saving observer location should persist to .env and update in-memory defaults."""
|
||||
import app as app_module
|
||||
import config
|
||||
from routes import adsb as adsb_routes
|
||||
from routes import ais as ais_routes
|
||||
from routes import settings as settings_routes
|
||||
|
||||
with client.session_transaction() as sess:
|
||||
sess['logged_in'] = True
|
||||
|
||||
env_path = tmp_path / '.env'
|
||||
monkeypatch.setattr(settings_routes, '_get_env_file_path', lambda: env_path)
|
||||
|
||||
response = client.post(
|
||||
'/settings/observer-location',
|
||||
data=json.dumps({'lat': 48.0, 'lon': 16.16}),
|
||||
content_type='application/json'
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
data = json.loads(response.data)
|
||||
assert data['status'] == 'success'
|
||||
assert data['lat'] == 48.0
|
||||
assert data['lon'] == 16.16
|
||||
|
||||
env_text = env_path.read_text()
|
||||
assert 'INTERCEPT_DEFAULT_LAT=48.0' in env_text
|
||||
assert 'INTERCEPT_DEFAULT_LON=16.16' in env_text
|
||||
|
||||
assert config.DEFAULT_LATITUDE == 48.0
|
||||
assert config.DEFAULT_LONGITUDE == 16.16
|
||||
assert app_module.DEFAULT_LATITUDE == 48.0
|
||||
assert app_module.DEFAULT_LONGITUDE == 16.16
|
||||
assert adsb_routes.DEFAULT_LATITUDE == 48.0
|
||||
assert adsb_routes.DEFAULT_LONGITUDE == 16.16
|
||||
assert ais_routes.DEFAULT_LATITUDE == 48.0
|
||||
assert ais_routes.DEFAULT_LONGITUDE == 16.16
|
||||
|
||||
def test_save_observer_location_rejects_invalid_values(self, client):
|
||||
"""Observer location save should validate coordinates."""
|
||||
with client.session_transaction() as sess:
|
||||
sess['logged_in'] = True
|
||||
|
||||
response = client.post(
|
||||
'/settings/observer-location',
|
||||
data=json.dumps({'lat': 200, 'lon': 16.16}),
|
||||
content_type='application/json'
|
||||
)
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
class TestCorrelationEndpoints:
|
||||
|
||||
Reference in New Issue
Block a user