at 23.11-pre 2.3 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 from base64 import b64encode 18 from urllib.parse import quote 19 20 machine.start() 21 machine.wait_for_open_port(80) 22 machine.wait_for_unit("multi-user.target") 23 24 machine.succeed("curl -sSf http://localhost") 25 26 machine.succeed( 27 "curl -c cookies -sSf -X POST http://localhost/login -d 'username=admin&password=admin'" 28 ) 29 30 cookie = machine.succeed( 31 "grep -v '^#' cookies | awk '{ print $7 }' | sed -e '/^$/d' | perl -pe 'chomp'" 32 ) 33 34 machine.succeed( 35 f"curl -sSf -X POST http://localhost/api/objects/tasks -b 'grocy_session={cookie}' " 36 + '-d \'{"assigned_to_user_id":1,"name":"Test Task","due_date":"1970-01-01"}\''' 37 + " --header 'Content-Type: application/json'" 38 ) 39 40 task_name = machine.succeed( 41 f"curl -sSf http://localhost/api/tasks -b 'grocy_session={cookie}' --header 'Accept: application/json' | jq '.[].name' | xargs echo | perl -pe 'chomp'" 42 ) 43 44 assert task_name == "Test Task" 45 46 machine.succeed("curl -sSI http://localhost/api/tasks 2>&1 | grep '401 Unauthorized'") 47 48 file_name = "test.txt" 49 file_name_base64 = b64encode(file_name.encode('ascii')).decode('ascii') 50 file_name_base64_urlencode = quote(file_name_base64) 51 52 machine.succeed( 53 f"echo Sample equipment manual > /tmp/{file_name}" 54 ) 55 56 machine.succeed( 57 f"curl -sSf -X 'PUT' -b 'grocy_session={cookie}' " 58 + f" 'http://localhost/api/files/equipmentmanuals/{file_name_base64_urlencode}' " 59 + " --header 'Accept: */*' " 60 + " --header 'Content-Type: application/octet-stream' " 61 + f" --data-binary '@/tmp/{file_name}' " 62 ) 63 64 machine.succeed( 65 f"curl -sSf -X 'GET' -b 'grocy_session={cookie}' " 66 + f" 'http://localhost/api/files/equipmentmanuals/{file_name_base64_urlencode}' " 67 + " --header 'Accept: application/octet-stream' " 68 + f" | cmp /tmp/{file_name}" 69 ) 70 71 machine.shutdown() 72 ''; 73})