summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndy Chun @noneucat <andy@lolc.at>2022-11-30 22:18:05 -0800
committerAndy Chun @noneucat <andy@lolc.at>2022-11-30 22:18:05 -0800
commitf8f19f84c6b3d0b2e34c7ba78f46698f9334de50 (patch)
treeb3a86f2b2f229e450bf2cbc9b9330317a5efe571
parent8fef1cc76639301df728271ba057cc14435998c7 (diff)
downloadnixpkgs-f8f19f84c6b3d0b2e34c7ba78f46698f9334de50.tar
nixpkgs-f8f19f84c6b3d0b2e34c7ba78f46698f9334de50.tar.gz
nixpkgs-f8f19f84c6b3d0b2e34c7ba78f46698f9334de50.tar.bz2
nixpkgs-f8f19f84c6b3d0b2e34c7ba78f46698f9334de50.tar.lz
nixpkgs-f8f19f84c6b3d0b2e34c7ba78f46698f9334de50.tar.xz
nixpkgs-f8f19f84c6b3d0b2e34c7ba78f46698f9334de50.tar.zst
nixpkgs-f8f19f84c6b3d0b2e34c7ba78f46698f9334de50.zip
nixos/grocy: add a basic smoke test for file uploads
-rw-r--r--nixos/tests/grocy.nix26
1 files changed, 26 insertions, 0 deletions
diff --git a/nixos/tests/grocy.nix b/nixos/tests/grocy.nix
index fe0ddd34148..48bbc9f7d3f 100644
--- a/nixos/tests/grocy.nix
+++ b/nixos/tests/grocy.nix
@@ -14,6 +14,9 @@ import ./make-test-python.nix ({ pkgs, ... }: {
   };
 
   testScript = ''
+    from base64 import b64encode
+    from urllib.parse import quote
+
     machine.start()
     machine.wait_for_open_port(80)
     machine.wait_for_unit("multi-user.target")
@@ -42,6 +45,29 @@ import ./make-test-python.nix ({ pkgs, ... }: {
 
     machine.succeed("curl -sSI http://localhost/api/tasks 2>&1 | grep '401 Unauthorized'")
 
+    file_name = "test.txt"
+    file_name_base64 = b64encode(file_name.encode('ascii')).decode('ascii')
+    file_name_base64_urlencode = quote(file_name_base64)
+
+    machine.succeed(
+        f"echo Sample equipment manual > /tmp/{file_name}"
+    )
+
+    machine.succeed(
+        f"curl -sSf -X 'PUT' -b 'grocy_session={cookie}' "
+        + f" 'http://localhost/api/files/equipmentmanuals/{file_name_base64_urlencode}' "
+        + "  --header 'Accept: */*' "
+        + "  --header 'Content-Type: application/octet-stream' "
+        + f" --data-binary '@/tmp/{file_name}' "
+    )
+
+    machine.succeed(
+        f"curl -sSf -X 'GET' -b 'grocy_session={cookie}' "
+        + f" 'http://localhost/api/files/equipmentmanuals/{file_name_base64_urlencode}' "
+        + "  --header 'Accept: application/octet-stream' "
+        + f" | cmp /tmp/{file_name}"
+    )
+
     machine.shutdown()
   '';
 })