mirror of
https://github.com/smittix/intercept.git
synced 2026-07-01 22:39:00 -07:00
test: repair stale assertions in validation/waterfall/meshtastic/routes
Auth fixture, /listening->/receiver waterfall rename, numeric validator returns, and float timestamp — all matching current code behaviour. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+49
-32
@@ -9,73 +9,90 @@ import pytest
|
||||
def auth_client(client):
|
||||
"""Client with logged-in session."""
|
||||
with client.session_transaction() as sess:
|
||||
sess['logged_in'] = True
|
||||
sess["logged_in"] = True
|
||||
return client
|
||||
|
||||
|
||||
def test_waterfall_start_no_rtl_power(auth_client):
|
||||
"""Start should fail gracefully when rtl_power is not available."""
|
||||
with patch('routes.listening_post.find_rtl_power', return_value=None):
|
||||
resp = auth_client.post('/listening/waterfall/start', json={
|
||||
'start_freq': 88.0,
|
||||
'end_freq': 108.0,
|
||||
})
|
||||
with patch("routes.listening_post.waterfall.find_rtl_power", return_value=None):
|
||||
resp = auth_client.post(
|
||||
"/receiver/waterfall/start",
|
||||
json={
|
||||
"start_freq": 88.0,
|
||||
"end_freq": 108.0,
|
||||
},
|
||||
)
|
||||
assert resp.status_code == 503
|
||||
data = resp.get_json()
|
||||
assert 'rtl_power' in data['message']
|
||||
assert "rtl_power" in data["message"]
|
||||
|
||||
|
||||
def test_waterfall_start_invalid_range(auth_client):
|
||||
"""Start should reject end <= start."""
|
||||
with patch('routes.listening_post.find_rtl_power', return_value='/usr/bin/rtl_power'):
|
||||
resp = auth_client.post('/listening/waterfall/start', json={
|
||||
'start_freq': 108.0,
|
||||
'end_freq': 88.0,
|
||||
})
|
||||
with patch("routes.listening_post.waterfall.find_rtl_power", return_value="/usr/bin/rtl_power"):
|
||||
resp = auth_client.post(
|
||||
"/receiver/waterfall/start",
|
||||
json={
|
||||
"start_freq": 108.0,
|
||||
"end_freq": 88.0,
|
||||
},
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_waterfall_start_success(auth_client):
|
||||
"""Start should succeed with mocked rtl_power and device."""
|
||||
with patch('routes.listening_post.find_rtl_power', return_value='/usr/bin/rtl_power'), \
|
||||
patch('routes.listening_post.app_module') as mock_app:
|
||||
with (
|
||||
patch("routes.listening_post.waterfall.find_rtl_power", return_value="/usr/bin/rtl_power"),
|
||||
patch("routes.listening_post.waterfall.app_module") as mock_app,
|
||||
):
|
||||
mock_app.claim_sdr_device.return_value = None # No error, claim succeeds
|
||||
resp = auth_client.post('/listening/waterfall/start', json={
|
||||
'start_freq': 88.0,
|
||||
'end_freq': 108.0,
|
||||
'gain': 40,
|
||||
'device': 0,
|
||||
})
|
||||
resp = auth_client.post(
|
||||
"/receiver/waterfall/start",
|
||||
json={
|
||||
"start_freq": 88.0,
|
||||
"end_freq": 108.0,
|
||||
"gain": 40,
|
||||
"device": 0,
|
||||
},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
data = resp.get_json()
|
||||
assert data['status'] == 'started'
|
||||
assert data["status"] == "started"
|
||||
|
||||
# Clean up: stop waterfall
|
||||
import routes.listening_post as lp
|
||||
|
||||
lp.waterfall_running = False
|
||||
|
||||
|
||||
def test_waterfall_stop(auth_client):
|
||||
"""Stop should succeed."""
|
||||
resp = auth_client.post('/listening/waterfall/stop')
|
||||
resp = auth_client.post("/receiver/waterfall/stop")
|
||||
assert resp.status_code == 200
|
||||
data = resp.get_json()
|
||||
assert data['status'] == 'stopped'
|
||||
assert data["status"] == "stopped"
|
||||
|
||||
|
||||
def test_waterfall_stream_mimetype(auth_client):
|
||||
"""Stream should return event-stream content type."""
|
||||
resp = auth_client.get('/listening/waterfall/stream')
|
||||
assert resp.content_type.startswith('text/event-stream')
|
||||
resp = auth_client.get("/receiver/waterfall/stream")
|
||||
assert resp.content_type.startswith("text/event-stream")
|
||||
|
||||
|
||||
def test_waterfall_start_device_busy(auth_client):
|
||||
"""Start should fail when device is in use."""
|
||||
with patch('routes.listening_post.find_rtl_power', return_value='/usr/bin/rtl_power'), \
|
||||
patch('routes.listening_post.app_module') as mock_app:
|
||||
mock_app.claim_sdr_device.return_value = 'SDR device 0 is in use by scanner'
|
||||
resp = auth_client.post('/listening/waterfall/start', json={
|
||||
'start_freq': 88.0,
|
||||
'end_freq': 108.0,
|
||||
})
|
||||
with (
|
||||
patch("routes.listening_post.waterfall.find_rtl_power", return_value="/usr/bin/rtl_power"),
|
||||
patch("routes.listening_post.waterfall.app_module") as mock_app,
|
||||
):
|
||||
mock_app.claim_sdr_device.return_value = "SDR device 0 is in use by scanner"
|
||||
resp = auth_client.post(
|
||||
"/receiver/waterfall/start",
|
||||
json={
|
||||
"start_freq": 88.0,
|
||||
"end_freq": 108.0,
|
||||
},
|
||||
)
|
||||
assert resp.status_code == 409
|
||||
|
||||
Reference in New Issue
Block a user