Skip to content

Commit 0d93a9f

Browse files
committed
add integration test
1 parent 7bb43a2 commit 0d93a9f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
7070
xfail_strict = true
7171
filterwarnings = [
7272
"error",
73+
"module:datetime.datetime.utcnow:DeprecationWarning", # from boto3
7374
"module:builtin type Swig:DeprecationWarning", # from pymupdf
7475
"module:builtin type swig:DeprecationWarning", # from pymupdf
7576
]

tests/test_client_integration.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import os
2+
import urllib.request
23
from collections.abc import Generator
34

45
import numpy as np
56
import pytest
7+
from bson import ObjectId
68

79
from pymongo_voyageai import PyMongoVoyageAI
810

911
if "VOYAGEAI_API_KEY" not in os.environ:
1012
pytest.skip("Requires VoyageAI API Key.", allow_module_level=True)
1113

1214
if "S3_BUCKET_NAME" not in os.environ:
13-
pytest.skip("Requires VoyageAI API Key.", allow_module_level=True)
15+
pytest.skip("Requires S3 Bucket name.", allow_module_level=True)
1416

1517
# mypy: disable_error_code="no-untyped-def"
1618

@@ -75,6 +77,24 @@ def test_pdf_pages(client: PyMongoVoyageAI):
7577
client.delete_by_ids([d["_id"] for d in resp])
7678

7779

80+
def test_pdf_pages_storage(client: PyMongoVoyageAI):
81+
query = "The consequences of a dictator's peace"
82+
url = "https://www.fdrlibrary.org/documents/356632/390886/readingcopy.pdf"
83+
storage = client._storage
84+
object_name = f"{ObjectId()}.pdf"
85+
with urllib.request.urlopen(url) as response:
86+
storage.client.upload_fileobj(response, storage.root_location, object_name)
87+
url = f"s3://{storage.root_location}/{object_name}"
88+
images = client.url_to_images(url)
89+
resp = client.add_documents(images)
90+
client.wait_for_indexing()
91+
data = client.similarity_search(query, extract_images=True)
92+
assert len(data[0]["inputs"][0].image.tobytes()) > 0
93+
assert len(client.get_by_ids([d["_id"] for d in resp])) == len(resp)
94+
client.delete_by_ids([d["_id"] for d in resp])
95+
storage.client.delete_object(Bucket=storage.root_location, Key=object_name)
96+
97+
7898
@pytest.mark.asyncio
7999
async def test_image_set_async(client: PyMongoVoyageAI):
80100
url = "hf://datasets/princeton-nlp/CharXiv/val.parquet"

0 commit comments

Comments
 (0)