Skip to content

Commit e1c14fa

Browse files
Add test_file to async code (from #2177)
1 parent 7cec2d3 commit e1c14fa

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/integ/aio/test_cursor_async.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,45 @@ async def test_vector(conn_cnx, is_public_test):
746746
assert len(data) == 0
747747

748748

749+
async def test_file(conn_cnx):
750+
"""Variant including JSON object."""
751+
name_file = random_string(5, "test_file_")
752+
async with conn_cnx(
753+
session_parameters={
754+
"ENABLE_FILE_DATA_TYPE": True,
755+
},
756+
) as cnx:
757+
async with cnx.cursor() as cur:
758+
await cur.execute(
759+
f"create temporary table {name_file} as select "
760+
f"TO_FILE(OBJECT_CONSTRUCT('RELATIVE_PATH', 'some_new_file.jpeg', 'STAGE', '@myStage', "
761+
f"'STAGE_FILE_URL', 'some_new_file.jpeg', 'SIZE', 123, 'ETAG', 'xxx', 'CONTENT_TYPE', 'image/jpeg', "
762+
f"'LAST_MODIFIED', '2025-01-01')) as file_col"
763+
)
764+
765+
expected_data = [
766+
{
767+
"RELATIVE_PATH": "some_new_file.jpeg",
768+
"STAGE": "@myStage",
769+
"STAGE_FILE_URL": "some_new_file.jpeg",
770+
"SIZE": 123,
771+
"ETAG": "xxx",
772+
"CONTENT_TYPE": "image/jpeg",
773+
"LAST_MODIFIED": "2025-01-01",
774+
}
775+
]
776+
777+
async with cnx.cursor() as cur:
778+
# Test with FILE return type
779+
result = await cur.execute(f"select * from {name_file}")
780+
for metadata in [cur.description, cur._description_internal]:
781+
assert FIELD_ID_TO_NAME[metadata[0].type_code] == "FILE"
782+
data = await result.fetchall()
783+
for raw_data in data:
784+
row = json.loads(raw_data[0])
785+
assert row in expected_data
786+
787+
749788
async def test_invalid_bind_data_type(conn_cnx):
750789
"""Invalid bind data type."""
751790
async with conn_cnx() as cnx:

0 commit comments

Comments
 (0)