This repository has been archived on 2026-04-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
server-config/tests/jellyfin-set-defaults.nix
Simon Gardling 735603deb8
All checks were successful
Build and Deploy / deploy (push) Successful in 2m41s
jellyfin: Prefer fMP4-HLS Media Container for all users
2026-04-16 01:11:59 -04:00

96 lines
3.2 KiB
Nix

{
lib,
pkgs,
...
}:
let
jfLib = import ./jellyfin-test-lib.nix { inherit pkgs lib; };
in
pkgs.testers.runNixOSTest {
name = "jellyfin-set-defaults";
nodes.machine =
{ ... }:
{
imports = [ jfLib.jellyfinTestConfig ];
};
testScript = ''
import json
import importlib.util
_spec = importlib.util.spec_from_file_location("jf_helpers", "${jfLib.helpers}")
assert _spec and _spec.loader
_jf = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(_jf)
setup_jellyfin = _jf.setup_jellyfin
jellyfin_api = _jf.jellyfin_api
auth_header = 'MediaBrowser Client="NixOS Test", DeviceId="test-1337", Device="TestDevice", Version="1.0"'
script = "${../services/jellyfin/jellyfin-set-defaults.py}"
start_all()
token, user_id, movie_id, media_source_id = setup_jellyfin(
machine, retry, auth_header,
"${jfLib.payloads.auth}", "${jfLib.payloads.empty}",
)
with subtest("Preference is not set initially"):
raw = jellyfin_api(
machine, "GET",
f"/DisplayPreferences/usersettings?userId={user_id}&client=emby",
auth_header, token=token,
)
prefs = json.loads(raw)
custom = prefs.get("CustomPrefs", {})
assert custom.get("preferFmp4HlsContainer") != "true", \
f"Expected preference to be unset, got: {custom}"
with subtest("Script sets preference for all users"):
CREDS_DIR = "/run/jf-defaults-creds"
machine.succeed(f"mkdir -p {CREDS_DIR}")
machine.succeed(f"echo 'dummy-api-key' > {CREDS_DIR}/jellyfin-api-key")
# The script uses api_key query param which requires a real Jellyfin API key.
# In the test, we use the auth token via a patched approach: call the script
# by providing the token as the API key. Jellyfin accepts api_key= with either
# an API key or an access token.
machine.succeed(f"echo '{token}' > {CREDS_DIR}/jellyfin-api-key")
machine.succeed(
f"CREDENTIALS_DIRECTORY={CREDS_DIR} "
f"JELLYFIN_URL=http://127.0.0.1:8096 "
f"${pkgs.python3}/bin/python {script}"
)
with subtest("Preference is now enabled"):
raw = jellyfin_api(
machine, "GET",
f"/DisplayPreferences/usersettings?userId={user_id}&client=emby",
auth_header, token=token,
)
prefs = json.loads(raw)
custom = prefs.get("CustomPrefs", {})
assert custom.get("preferFmp4HlsContainer") == "true", \
f"Expected preferFmp4HlsContainer=true, got: {custom}"
with subtest("Script is idempotent"):
machine.succeed(
f"CREDENTIALS_DIRECTORY={CREDS_DIR} "
f"JELLYFIN_URL=http://127.0.0.1:8096 "
f"${pkgs.python3}/bin/python {script}"
)
raw = jellyfin_api(
machine, "GET",
f"/DisplayPreferences/usersettings?userId={user_id}&client=emby",
auth_header, token=token,
)
prefs = json.loads(raw)
custom = prefs.get("CustomPrefs", {})
assert custom.get("preferFmp4HlsContainer") == "true", \
f"Expected preference to remain true after re-run, got: {custom}"
'';
}