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