Spaces:
Sleeping
Sleeping
Download code/tests/test_device_engine.py from acra-thesis/acra-backend: direct link, hf CLI and curl.
- Browser
- Download file 991 Bytes
-
https://huggingface.co/spaces/acra-thesis/acra-backend/resolve/main/code/tests/test_device_engine.py
- Command line
-
hf download hf://spaces/acra-thesis/acra-backend/code/tests/test_device_engine.py
-
curl -L -o test_device_engine.py https://huggingface.co/spaces/acra-thesis/acra-backend/resolve/main/code/tests/test_device_engine.py
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 | |