1 import ./make-test-python.nix ({ lib, ... }: {
3 meta.maintainers = with lib.maintainers; [ leona SuperSandro2000 erikarvstedt ];
6 simple = { pkgs, ... }: {
7 environment.systemPackages = with pkgs; [ imagemagick jq ];
10 passwordFile = builtins.toFile "password" "admin";
13 postgres = { config, pkgs, ... }: {
14 imports = [ self.simple ];
15 services.postgresql = {
17 ensureDatabases = [ "paperless" ];
19 { name = config.services.paperless.user;
20 ensureDBOwnership = true;
24 services.paperless.settings = {
25 PAPERLESS_DBHOST = "/run/postgresql";
26 PAPERLESS_OCR_LANGUAGE = "deu";
34 def test_paperless(node):
35 node.wait_for_unit("paperless-consumer.service")
37 with subtest("Add a document via the file system"):
39 "convert -size 400x40 xc:white -font 'DejaVu-Sans' -pointsize 20 -fill black "
40 "-annotate +5+20 'hello world 16-10-2005' /var/lib/paperless/consume/doc.png"
43 with subtest("Web interface gets ready"):
44 node.wait_for_unit("paperless-web.service")
45 # Wait until server accepts connections
46 node.wait_until_succeeds("curl -fs localhost:28981")
48 # Required for consuming documents via the web interface
49 with subtest("Task-queue gets ready"):
50 node.wait_for_unit("paperless-task-queue.service")
52 with subtest("Add a png document via the web interface"):
54 "convert -size 400x40 xc:white -font 'DejaVu-Sans' -pointsize 20 -fill black "
55 "-annotate +5+20 'hello web 16-10-2005' /tmp/webdoc.png"
57 node.wait_until_succeeds("curl -u admin:admin -F document=@/tmp/webdoc.png -fs localhost:28981/api/documents/post_document/")
59 with subtest("Add a txt document via the web interface"):
61 "echo 'hello web 16-10-2005' > /tmp/webdoc.txt"
63 node.wait_until_succeeds("curl -u admin:admin -F document=@/tmp/webdoc.txt -fs localhost:28981/api/documents/post_document/")
65 with subtest("Documents are consumed"):
66 node.wait_until_succeeds(
67 "(($(curl -u admin:admin -fs localhost:28981/api/documents/ | jq .count) == 3))"
69 docs = json.loads(node.succeed("curl -u admin:admin -fs localhost:28981/api/documents/"))['results']
70 assert "2005-10-16" in docs[0]['created']
71 assert "2005-10-16" in docs[1]['created']
72 assert "2005-10-16" in docs[2]['created']
74 # Detects gunicorn issues, see PR #190888
75 with subtest("Document metadata can be accessed"):
76 metadata = json.loads(node.succeed("curl -u admin:admin -fs localhost:28981/api/documents/1/metadata/"))
77 assert "original_checksum" in metadata
79 metadata = json.loads(node.succeed("curl -u admin:admin -fs localhost:28981/api/documents/2/metadata/"))
80 assert "original_checksum" in metadata
82 metadata = json.loads(node.succeed("curl -u admin:admin -fs localhost:28981/api/documents/3/metadata/"))
83 assert "original_checksum" in metadata
85 test_paperless(simple)
86 simple.send_monitor_command("quit")
87 simple.wait_for_shutdown()
88 test_paperless(postgres)