Skip to content

Commit fc6cc51

Browse files
Add test_file to async code (from #2177)
1 parent 5d104b9 commit fc6cc51

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
@@ -744,6 +744,45 @@ async def test_vector(conn_cnx, is_public_test):
744744
assert len(data) == 0
745745

746746

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

0 commit comments

Comments
 (0)