acra-backend / code /tests /test_device_engine.py
Zeref8425's picture
feat(offline): authenticate device engine downloads
24cb476
Raw History Blame Contribute Delete
991 Bytes
from pathlib import Path
import pytest
from fastapi import HTTPException
from device_engine import engine_response
def test_device_engine_missing_file():
with pytest.raises(HTTPException) as error:
engine_response(None)
assert error.value.status_code == 503
def test_device_engine_is_private_file_response(tmp_path):
model = tmp_path / 'engine.bin'
model.write_bytes(b'actual installed bytes')
response = engine_response(model)
assert Path(response.path) == model
assert response.headers['cache-control'] == 'private, no-store'
assert response.media_type == 'application/octet-stream'
def test_device_engine_endpoint_requires_authentication(monkeypatch):
import main
from starlette.requests import Request
monkeypatch.setattr(main, 'SKIP_AUTH', False)
request = Request({'type': 'http', 'headers': []})
with pytest.raises(HTTPException) as error:
main.device_engine(request)
assert error.value.status_code == 401