File size: 991 Bytes
24cb476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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