Skip to content

Commit 7c383ed

Browse files
committed
feat: Add integration test for image uploads with captions
- Introduced a new integration test to validate the functionality of adding images with captions to existing documents. - Updated `pyproject.toml` to include a new pytest marker for integration tests. - Enhanced the test suite for better coverage of image handling in documents.
1 parent 687f5b8 commit 7c383ed

3 files changed

Lines changed: 120 additions & 1 deletion

File tree

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ exclude = ["tests*", "examples*"]
4141

4242
[tool.setuptools.package-data]
4343
vaiz = ["py.typed"]
44+
45+
[tool.pytest.ini_options]
46+
markers = [
47+
"integration: marks tests as integration tests (require real API credentials)",
48+
]

tests/test_file_blocks.py

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,114 @@ def test_create_document_with_file_blocks():
272272
pass # Could add cleanup here
273273

274274

275+
@pytest.mark.integration
276+
def test_add_images_with_captions_to_existing_document():
277+
"""Integration test: Add images with captions to existing document."""
278+
client = get_test_client()
279+
280+
# Use existing document ID
281+
document_id = "68fb4d1cd35675279afd63e1"
282+
283+
# Upload test image
284+
image_path = "assets/example.png"
285+
286+
print(f"\n📤 Uploading image: {image_path}")
287+
image_uploaded = client.upload_file(image_path, file_type=UploadFileType.Image)
288+
assert image_uploaded.file.id is not None
289+
print(f"✅ Uploaded: {image_uploaded.file.name} (ID: {image_uploaded.file.id})")
290+
291+
# Build content with images that have captions
292+
content = [
293+
heading(1, "Images with Captions Test"),
294+
295+
paragraph(text("This document demonstrates image blocks with captions.")),
296+
297+
heading(2, "Image 1: With Caption"),
298+
299+
image_block(
300+
file_id=image_uploaded.file.id,
301+
src=image_uploaded.file.url,
302+
file_name=image_uploaded.file.name,
303+
file_size=image_uploaded.file.size,
304+
extension=image_uploaded.file.ext,
305+
file_type=image_uploaded.file.mime or "image/png",
306+
dimensions=image_uploaded.file.dimension if image_uploaded.file.dimension else None,
307+
caption="This is a test image with a caption"
308+
),
309+
310+
paragraph(text("The image above has a caption.", italic=True)),
311+
312+
heading(2, "Image 2: With Different Caption"),
313+
314+
image_block(
315+
file_id=image_uploaded.file.id,
316+
src=image_uploaded.file.url,
317+
file_name=image_uploaded.file.name,
318+
file_size=image_uploaded.file.size,
319+
extension=image_uploaded.file.ext,
320+
file_type=image_uploaded.file.mime or "image/png",
321+
dimensions=image_uploaded.file.dimension if image_uploaded.file.dimension else None,
322+
caption="Another caption example with description",
323+
width_percent=75
324+
),
325+
326+
paragraph(text("The image above has a different caption and 75% width.", italic=True)),
327+
328+
heading(2, "Image 3: Full Width with Long Caption"),
329+
330+
image_block(
331+
file_id=image_uploaded.file.id,
332+
src=image_uploaded.file.url,
333+
file_name=image_uploaded.file.name,
334+
file_size=image_uploaded.file.size,
335+
extension=image_uploaded.file.ext,
336+
file_type=image_uploaded.file.mime or "image/png",
337+
dimensions=image_uploaded.file.dimension if image_uploaded.file.dimension else None,
338+
caption="This is a longer caption that demonstrates how captions work with full-width images. Captions provide context and descriptions for images.",
339+
width_percent=100
340+
),
341+
]
342+
343+
# Replace document content
344+
print(f"\n📝 Updating document: {document_id}")
345+
client.replace_json_document(document_id, content)
346+
347+
# Verify blocks were created with captions
348+
doc_content = client.get_json_document(document_id)
349+
350+
assert doc_content is not None
351+
assert "default" in doc_content
352+
assert "content" in doc_content["default"]
353+
354+
doc_nodes = doc_content["default"]["content"]
355+
356+
# Find image blocks
357+
image_blocks = [n for n in doc_nodes if n.get("type") == "image-block"]
358+
359+
assert len(image_blocks) == 3, f"Expected 3 image blocks, found {len(image_blocks)}"
360+
361+
# Verify all images have captions
362+
captions_found = 0
363+
for idx, image_block_node in enumerate(image_blocks):
364+
assert "content" in image_block_node
365+
image_content = image_block_node["content"][0]["text"]
366+
image_data = json.loads(image_content)
367+
368+
assert image_data["fileId"] == image_uploaded.file.id
369+
370+
# Check caption exists
371+
if "caption" in image_data:
372+
captions_found += 1
373+
print(f" Image {idx + 1} caption: {image_data['caption'][:50]}...")
374+
375+
assert captions_found == 3, f"Expected 3 captions, found {captions_found}"
376+
377+
print(f"\n✅ Successfully created 3 images with captions in document!")
378+
print(f" Document ID: {document_id}")
379+
print(f" View at: https://vaiz.app/document/{document_id}")
380+
381+
275382
if __name__ == "__main__":
276-
test_create_document_with_file_blocks()
383+
# test_create_document_with_file_blocks()
384+
test_add_images_with_captions_to_existing_document()
277385

tests/test_task_list_integration.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
"""
44

55
import pytest
6+
import sys
7+
import os
8+
9+
# Add tests directory to path for test_config import
10+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
11+
612
from test_config import get_test_client, TEST_BOARD_ID, TEST_GROUP_ID
713
from vaiz import (
814
CreateTaskRequest,

0 commit comments

Comments
 (0)