1 import ./make-test-python.nix ({ pkgs, ... }: {
3 meta = with pkgs.lib.maintainers; {
4 maintainers = [ ma27 ];
7 nodes.machine = { pkgs, ... }: {
10 hostName = "localhost";
11 nginx.enableSSL = false;
13 environment.systemPackages = [ pkgs.jq ];
17 from base64 import b64encode
18 from urllib.parse import quote
21 machine.wait_for_open_port(80)
22 machine.wait_for_unit("multi-user.target")
24 machine.succeed("curl -sSf http://localhost")
27 "curl -c cookies -sSf -X POST http://localhost/login -d 'username=admin&password=admin'"
30 cookie = machine.succeed(
31 "grep -v '^#' cookies | awk '{ print $7 }' | sed -e '/^$/d' | perl -pe 'chomp'"
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'"
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'"
44 assert task_name == "Test Task"
46 machine.succeed("curl -sSI http://localhost/api/tasks 2>&1 | grep '401 Unauthorized'")
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)
53 f"echo Sample equipment manual > /tmp/{file_name}"
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}' "
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}"