at 23.05-pre 1.4 kB view raw
1import ./make-test-python.nix ({ pkgs, ... }: { 2 name = "grocy"; 3 meta = with pkgs.lib.maintainers; { 4 maintainers = [ ma27 ]; 5 }; 6 7 nodes.machine = { pkgs, ... }: { 8 services.grocy = { 9 enable = true; 10 hostName = "localhost"; 11 nginx.enableSSL = false; 12 }; 13 environment.systemPackages = [ pkgs.jq ]; 14 }; 15 16 testScript = '' 17 machine.start() 18 machine.wait_for_open_port(80) 19 machine.wait_for_unit("multi-user.target") 20 21 machine.succeed("curl -sSf http://localhost") 22 23 machine.succeed( 24 "curl -c cookies -sSf -X POST http://localhost/login -d 'username=admin&password=admin'" 25 ) 26 27 cookie = machine.succeed( 28 "grep -v '^#' cookies | awk '{ print $7 }' | sed -e '/^$/d' | perl -pe 'chomp'" 29 ) 30 31 machine.succeed( 32 f"curl -sSf -X POST http://localhost/api/objects/tasks -b 'grocy_session={cookie}' " 33 + '-d \'{"assigned_to_user_id":1,"name":"Test Task","due_date":"1970-01-01"}\''' 34 + " --header 'Content-Type: application/json'" 35 ) 36 37 task_name = machine.succeed( 38 f"curl -sSf http://localhost/api/tasks -b 'grocy_session={cookie}' --header 'Accept: application/json' | jq '.[].name' | xargs echo | perl -pe 'chomp'" 39 ) 40 41 assert task_name == "Test Task" 42 43 machine.succeed("curl -sSI http://localhost/api/tasks 2>&1 | grep '401 Unauthorized'") 44 45 machine.shutdown() 46 ''; 47})