def test_MC_column_index_multiple(engine_with_schema): engine, schema = engine_with_schema mc_1 = columns.MathesarColumn('testable_col', String) mc_2 = columns.MathesarColumn('testable_col2', String) mc_1.add_engine(engine) mc_2.add_engine(engine) metadata = MetaData(bind=engine, schema=schema) Table('asupertable', metadata, mc_1, mc_2).create() assert mc_1.column_index == 0 assert mc_2.column_index == 1
def test_MC_column_index_single(engine_with_schema): engine, schema = engine_with_schema mc = columns.MathesarColumn('testable_col', String) mc.add_engine(engine) metadata = MetaData(bind=engine, schema=schema) Table('asupertable', metadata, mc).create() assert mc.column_index == 0
def from_column_column(*args, **kwargs): """ This creates a condition to check that the MathesarColumn.from_column class method returns the same value of the original __init__ for a given input. """ col = columns.MathesarColumn(*args, **kwargs) return columns.MathesarColumn.from_column(col)
def test_MC_is_default_when_false_for_name(): for default_col in columns.DEFAULT_COLUMNS: dc_definition = columns.DEFAULT_COLUMNS[default_col] col = columns.MathesarColumn( "definitely_not_a_default", dc_definition["type"], primary_key=dc_definition.get("primary_key", False), nullable=dc_definition.get("nullable", True), ) assert not col.is_default
def test_MC_is_default_when_false_for_pk(): for default_col in columns.DEFAULT_COLUMNS: dc_definition = columns.DEFAULT_COLUMNS[default_col] not_pk = not dc_definition.get("primary_key", False), col = columns.MathesarColumn( default_col, dc_definition["type"], primary_key=not_pk, nullable=dc_definition.get("nullable", True), ) assert not col.is_default
def test_MC_is_default_when_false_for_type(): for default_col in columns.DEFAULT_COLUMNS: dc_definition = columns.DEFAULT_COLUMNS[default_col] changed_type = Integer if dc_definition["type"] == String else String col = columns.MathesarColumn( default_col, changed_type, primary_key=dc_definition.get("primary_key", False), nullable=dc_definition.get("nullable", True), ) assert not col.is_default
def test_MC_column_index_when_no_db_table(engine): mc = columns.MathesarColumn('testable_col', String) mc.add_engine(engine) table = Table('atable', MetaData(), mc) assert mc.table == table and mc.column_index is None
def test_MC_column_index_when_no_table(engine): mc = columns.MathesarColumn('testable_col', String) mc.add_engine(engine) assert mc.column_index is None
def test_MC_valid_target_types_custom_engine(engine_with_types): mc = columns.MathesarColumn('testable_col', String) mc.add_engine(engine_with_types) assert "mathesar_types.email" in mc.valid_target_types
def test_MC_valid_target_types_default_engine(engine): mc = columns.MathesarColumn('testable_col', String) mc.add_engine(engine) assert "VARCHAR" in mc.valid_target_types
def test_MC_valid_target_types_no_engine(): mc = columns.MathesarColumn('testable_col', String) assert mc.valid_target_types is None
def init_column(*args, **kwargs): return columns.MathesarColumn(*args, **kwargs)