nixos/tests/papra: init (#553492)

This commit is contained in:
dram
2026-08-17 23:25:14 +00:00
committed by GitHub
3 changed files with 82 additions and 1 deletions

View File

@@ -1338,6 +1338,7 @@ in
pantalaimon = runTest ./matrix/pantalaimon.nix;
pantheon = runTest ./pantheon.nix;
paperless = runTest ./paperless.nix;
papra = runTest ./papra.nix;
paretosecurity = runTest ./paretosecurity.nix;
parsedmarc = handleTest ./parsedmarc { };
part-db = runTest ./web-apps/part-db.nix;

76
nixos/tests/papra.nix Normal file
View File

@@ -0,0 +1,76 @@
{ lib, ... }:
{
name = "papra";
meta.maintainers = with lib.maintainers; [ h7x4 ];
containers.machine = {
services.papra = {
enable = true;
environment = {
AUTH_IS_EMAIL_VERIFICATION_REQUIRED = false;
AUTH_FIRST_USER_AS_ADMIN = true;
};
};
};
testScript =
let
serverBaseUrl = "http://localhost:1221";
cookieJar = "/tmp/papra-cookies";
jsonArg = value: "'${lib.escape [ "\"" "'" ] (builtins.toJSON value)}'";
in
''
import json
machine.wait_for_unit("papra.service")
machine.wait_for_open_port(1221)
with subtest("Health endpoint responds"):
machine.succeed("curl --fail --silent ${serverBaseUrl}/api/health")
with subtest("Register a user"):
machine.succeed(
"curl --fail --silent"
+ " --cookie-jar ${cookieJar}"
+ " --json ${
jsonArg {
email = "admin@example.com";
password = "correct horse battery staple";
name = "Admin";
}
}"
+ " ${serverBaseUrl}/api/auth/sign-up/email"
)
with subtest("Create an organization"):
organization = json.loads(machine.succeed(
"curl --fail --silent"
+ " --cookie ${cookieJar}"
+ " --json ${jsonArg { name = "Test Org"; }}"
+ " ${serverBaseUrl}/api/organizations"
))
org_id = organization["organization"]["id"]
assert org_id, f"Expected an organization id, got: {json.dumps(organization)}"
with subtest("Import a document"):
machine.succeed("echo 'hello from the nixos test' > /tmp/document.txt")
document = json.loads(machine.succeed(
"curl --fail --silent"
+ " --cookie ${cookieJar}"
+ " --form file=@/tmp/document.txt"
+ f" ${serverBaseUrl}/api/organizations/{org_id}/documents"
))
document_id = document["document"]["id"]
assert document_id, f"Expected a document id, got: {json.dumps(document)}"
with subtest("Retrieve the imported document"):
machine.succeed(
"curl --fail --silent"
+ " --cookie ${cookieJar}"
+ f" ${serverBaseUrl}/api/organizations/{org_id}/documents/{document_id}/file"
+ " --output /tmp/retrieved-document.txt"
)
machine.succeed("diff /tmp/document.txt /tmp/retrieved-document.txt")
'';
}

View File

@@ -14,6 +14,7 @@
python3,
nix-update-script,
tsx,
nixosTests,
}:
let
pnpm = pnpm_11.override { nodejs-slim = nodejs-slim_26; };
@@ -95,7 +96,10 @@ stdenv.mkDerivation (finalAttrs: {
runHook postInstall
'';
passthru.updateScript = nix-update-script { };
passthru = {
updateScript = nix-update-script { };
tests.nixos = nixosTests.papra;
};
meta = {
description = "Open-source document management platform designed to help you organize, secure, and archive your files effortlessly.";