lol

nixos/grocy: add a basic smoke test for file uploads

+26
+26
nixos/tests/grocy.nix
··· 14 14 }; 15 15 16 16 testScript = '' 17 + from base64 import b64encode 18 + from urllib.parse import quote 19 + 17 20 machine.start() 18 21 machine.wait_for_open_port(80) 19 22 machine.wait_for_unit("multi-user.target") ··· 41 44 assert task_name == "Test Task" 42 45 43 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 + ) 44 70 45 71 machine.shutdown() 46 72 '';