at 24.11-pre 3.5 kB view raw
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.settings = { 25 PAPERLESS_DBHOST = "/run/postgresql"; 26 PAPERLESS_OCR_LANGUAGE = "deu"; 27 }; 28 }; 29 }; in self; 30 31 testScript = '' 32 import json 33 34 def test_paperless(node): 35 node.wait_for_unit("paperless-consumer.service") 36 37 with subtest("Add a document via the file system"): 38 node.succeed( 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" 41 ) 42 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") 47 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") 51 52 with subtest("Add a png document via the web interface"): 53 node.succeed( 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" 56 ) 57 node.wait_until_succeeds("curl -u admin:admin -F document=@/tmp/webdoc.png -fs localhost:28981/api/documents/post_document/") 58 59 with subtest("Add a txt document via the web interface"): 60 node.succeed( 61 "echo 'hello web 16-10-2005' > /tmp/webdoc.txt" 62 ) 63 node.wait_until_succeeds("curl -u admin:admin -F document=@/tmp/webdoc.txt -fs localhost:28981/api/documents/post_document/") 64 65 with subtest("Documents are consumed"): 66 node.wait_until_succeeds( 67 "(($(curl -u admin:admin -fs localhost:28981/api/documents/ | jq .count) == 3))" 68 ) 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'] 73 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 78 79 metadata = json.loads(node.succeed("curl -u admin:admin -fs localhost:28981/api/documents/2/metadata/")) 80 assert "original_checksum" in metadata 81 82 metadata = json.loads(node.succeed("curl -u admin:admin -fs localhost:28981/api/documents/3/metadata/")) 83 assert "original_checksum" in metadata 84 85 test_paperless(simple) 86 simple.send_monitor_command("quit") 87 simple.wait_for_shutdown() 88 test_paperless(postgres) 89 ''; 90})