Skip to content

Commit 2416c6c

Browse files
committed
test: verify compression is transparent to API
- Test create/get/edit cycle with compressed content - Verify content matches exactly (no corruption) - Verify API responses unchanged - Ensure compression doesn't affect client behavior
1 parent 18df813 commit 2416c6c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

backend/tests/api/test_paste_routes.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,3 +523,54 @@ async def test_delete_paste_requires_authorization_header(
523523

524524
# Should fail with 401 Unauthorized (missing auth header)
525525
assert response.status_code == 401
526+
527+
528+
@pytest.mark.asyncio
529+
async def test_api_compression_is_transparent(
530+
test_client: AsyncClient, bypass_headers
531+
):
532+
"""Test that compression is completely transparent to API consumers.
533+
534+
Verifies that the create -> get -> edit cycle works seamlessly with
535+
compressed content, with no client-side changes required.
536+
"""
537+
# Create a large paste (will be compressed)
538+
create_data = {
539+
"title": "Compressed Paste",
540+
"content": "Test content for compression. " * 100, # Exceeds 512-byte threshold
541+
"content_language": "plain_text",
542+
}
543+
544+
create_response = await test_client.post("/pastes", json=create_data, headers=bypass_headers)
545+
546+
assert create_response.status_code == 200
547+
create_data_response = create_response.json()
548+
paste_id = create_data_response["id"]
549+
edit_token = create_data_response["edit_token"]
550+
551+
# Retrieve the paste
552+
get_response = await test_client.get(f"/pastes/{paste_id}", headers=bypass_headers)
553+
554+
assert get_response.status_code == 200
555+
get_data = get_response.json()
556+
557+
# Verify content matches exactly (no corruption from compression)
558+
assert get_data["content"] == create_data["content"]
559+
assert get_data["title"] == "Compressed Paste"
560+
561+
# Edit the paste with new large content
562+
edit_data = {
563+
"content": "Updated content. " * 100,
564+
}
565+
566+
edit_response = await test_client.put(
567+
f"/pastes/{paste_id}",
568+
json=edit_data,
569+
headers={"Authorization": edit_token}
570+
)
571+
572+
assert edit_response.status_code == 200
573+
edit_data_response = edit_response.json()
574+
575+
# Verify edit succeeded and content matches new content
576+
assert edit_data_response["content"] == edit_data["content"]

0 commit comments

Comments
 (0)