mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-12 01:02:39 +02:00
test(e2e): add shared binary fixture loader for connector fakes
This commit is contained in:
parent
523563b948
commit
fc32ab0cf3
1 changed files with 23 additions and 0 deletions
23
surfsense_backend/tests/e2e/fakes/binary_loader.py
Normal file
23
surfsense_backend/tests/e2e/fakes/binary_loader.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
"""Helpers for serving text and binary fixture file bodies."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
def _resolve_file_bytes(
|
||||
fixture: dict[str, Any], key: str | None, fixtures_dir: Path
|
||||
) -> bytes | None:
|
||||
"""Resolve a fake file body, preferring binary fixture files over text."""
|
||||
if not key:
|
||||
return None
|
||||
|
||||
binary_path = fixture.get("_file_binary_paths", {}).get(key)
|
||||
if binary_path is not None:
|
||||
return (fixtures_dir / binary_path).read_bytes()
|
||||
|
||||
content = fixture.get("_file_contents", {}).get(key)
|
||||
if content is None:
|
||||
return None
|
||||
return content.encode("utf-8")
|
||||
Loading…
Add table
Add a link
Reference in a new issue