Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jvasquezrojas committed Sep 4, 2024
1 parent cd1a213 commit 5928f59
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
15 changes: 7 additions & 8 deletions tests/test_custom_types.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
#
import json

import pytest
from sqlalchemy import Column, MetaData, Table, text
from sqlalchemy import Column, Integer, MetaData, Table, text

from snowflake.sqlalchemy import TEXT, custom_types

Expand Down Expand Up @@ -47,7 +46,8 @@ def test_create_table_with_text_type(engine_testaccount):
test_max_lob_size = Table(
table_name,
metadata,
Column("name", TEXT(), primary_key=True),
Column("id", Integer, primary_key=True),
Column("full_name", TEXT(), server_default=text("id::varchar")),
)

metadata.create_all(engine_testaccount)
Expand All @@ -56,13 +56,12 @@ def test_create_table_with_text_type(engine_testaccount):

with engine_testaccount.connect() as conn:
with conn.begin():
query = text(f"SHOW COLUMNS IN {table_name}")
query = text(f"SELECT GET_DDL('TABLE', '{table_name}')")
result = conn.execute(query)
row = result.mappings().fetchone()["data_type"]
type_length = json.loads(row)["length"]
row = str(result.mappings().fetchone())
assert (
type_length >= 134217728
), f"Expected length to be greater than or equal to 134217728, got {type_length}"
"VARCHAR(134217728)" in row
), f"Expected VARCHAR(134217728) in {row}"

finally:
test_max_lob_size.drop(engine_testaccount)
17 changes: 13 additions & 4 deletions tests/test_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,22 +417,31 @@ class Employee(Base):


@pytest.mark.feature_max_lob_size
def test_basic_orm_metadata(engine_testaccount):
def test_basic_table_with_large_lob_size_in_memory(engine_testaccount, sql_compiler):
Base = declarative_base()

class User(Base):
__tablename__ = "user"

name = Column(String, primary_key=True)
fullname = Column(TEXT(134217728))
id = Column(Integer, primary_key=True)
full_name = Column(TEXT(), server_default=text("id::varchar"))

def __repr__(self):
return f"<User({self.name!r}, {self.fullname!r})>"

Base.metadata.create_all(engine_testaccount)

try:
assert User.__table__.columns["fullname"].type.length == 134217728
assert User.__table__ is not None

with engine_testaccount.connect() as conn:
with conn.begin():
query = text(f"SELECT GET_DDL('TABLE', '{User.__tablename__}')")
result = conn.execute(query)
row = str(result.mappings().fetchone())
assert (
"VARCHAR(134217728)" in row
), f"Expected VARCHAR(134217728) in {row}"

finally:
Base.metadata.drop_all(engine_testaccount)

0 comments on commit 5928f59

Please sign in to comment.