diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-10 12:15:24 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-10 12:15:24 +0100 |
| commit | e77456f9c6804cd55dcdbb9c9bc06085b6ed91c2 (patch) | |
| tree | 1d82e707c803ed6b7d0c97c6cf631d2e4aae0c03 /tests | |
| parent | ea4c6aefebb208e5328f5f17d667a274780fbf64 (diff) | |
| download | deck-it-e77456f9c6804cd55dcdbb9c9bc06085b6ed91c2.tar.gz deck-it-e77456f9c6804cd55dcdbb9c9bc06085b6ed91c2.zip | |
feat(server): upload actions take a raw body up to their own limit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_server.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/test_server.py b/tests/test_server.py index 7f2ee1c..0bec492 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -55,7 +55,9 @@ class Server(unittest.TestCase): srv.REGISTRY = mod.Registry([ mod.Module("demo", "Demo", lambda: {"ok": True}, {"ping": lambda body: {"got": body.get("n")}, - "boom": lambda body: int(body.get("x"))}), + "boom": lambda body: int(body.get("x")), + "put": lambda data: {"len": len(data)}}, + uploads={"put": ("audio/wav", 10)}), ]) cls.server = srv.UnixHTTPServer(cls.sock, srv.Handler) threading.Thread(target=cls.server.serve_forever, daemon=True).start() @@ -74,6 +76,20 @@ class Server(unittest.TestCase): conn.close() return r.status, data + def test_upload_takes_raw_bytes(self): + h = {**HOST, **ORIGIN, "Content-Type": "audio/wav"} + status, body = self.req("POST", "/api/demo/put", h, b"RIFF1234") + self.assertEqual((status, json.loads(body)), (200, {"len": 8})) + + def test_upload_limits(self): + h = {**HOST, **ORIGIN, "Content-Type": "audio/wav"} + self.assertEqual(self.req("POST", "/api/demo/put", h, b"x" * 11)[0], 400) + self.assertEqual(self.req("POST", "/api/demo/put", + {**h, "Content-Type": "application/json"}, b"{}")[0], 400) + self.assertEqual(self.req("POST", "/api/demo/put", + {"Host": "127.0.0.1:8765", **ORIGIN, "Content-Type": "audio/wav"}, + b"RIFF")[0], 401) + def test_assets_and_api(self): self.assertEqual(self.req("GET", "/", HOST)[0], 200) self.assertEqual(self.req("GET", "/theme.css", HOST)[0], 200) |
