def test_column_type_conversion_integer(self): self._test_migrations(table_snapshots=[[self.table(column)] for column in [ Integer(), BigInt(), SmallInt(), BigInt(), Integer(), ]])
class MegaTable(Table): """ A table containing all of the column types, and different column kwargs. """ bigint_col = BigInt() boolean_col = Boolean() bytea_col = Bytea() date_col = Date() foreignkey_col = ForeignKey(SmallTable) integer_col = Integer() interval_col = Interval() json_col = JSON() jsonb_col = JSONB() numeric_col = Numeric(digits=(5, 2)) real_col = Real() double_precision_col = DoublePrecision() smallint_col = SmallInt() text_col = Text() timestamp_col = Timestamp() timestamptz_col = Timestamptz() uuid_col = UUID() varchar_col = Varchar() unique_col = Varchar(unique=True) null_col = Varchar(null=True) not_null_col = Varchar(null=False)
def test_column_type_conversion_string_to_integer(self): self._test_migrations(table_snapshots=[[self.table(column)] for column in [ Varchar(default="1"), Integer(default=1), Varchar(default="1"), ]])
def test_other(self): """ Make sure simple Python values are returned correctly. """ self.assertEqual( convert_to_sql_value(value=1, column=Integer()), 1, )
class Concert(Table): """ ``order`` is a problematic name, as it clashes with a reserved SQL keyword: https://www.postgresql.org/docs/current/sql-keywords-appendix.html """ name = Varchar() order = Integer()
def test_choices(self): """ Test adding choices to a column. """ class Title(Enum): mr = 1 mrs = 2 column = Integer(choices=Title) self.assertEqual(column._meta.choices, Title)
def test_array_column_integer(self): self._test_migrations( table_snapshots=[[self.table(column)] for column in [ Array(base_column=Integer()), Array(base_column=Integer(), default=[1, 2, 3]), Array(base_column=Integer(), default=array_default_integer), Array(base_column=Integer(), null=True, default=None), Array(base_column=Integer(), null=False), Array(base_column=Integer(), index=True), Array(base_column=Integer(), index=False), ]], test_function=lambda x: all([ x.data_type == "ARRAY", x.is_nullable == "NO", x.column_default == "'{}'::integer[]", ]), )
def test_integer_column(self): self._test_migrations( table_snapshots=[[self.table(column)] for column in [ Integer(), Integer(default=1), Integer(default=integer_default), Integer(null=True), Integer(null=False), Integer(index=True), Integer(index=False), ]], test_function=lambda x: all([ x.data_type == "integer", x.is_nullable == "NO", x.column_default == "0", ]), )
def test_get_choices_dict_with_custom_names(self): """ Test ``get_choices_dict``, when ``Choice`` is used. """ class Title(Enum): mr = Choice(value=1, display_name="Mr.") mrs = Choice(value=2, display_name="Mrs.") column = Integer(choices=Title) self.assertEqual( column._meta.get_choices_dict(), { "mr": { "display_name": "Mr.", "value": 1 }, "mrs": { "display_name": "Mrs.", "value": 2 }, }, )
class MegaTable(Table): """ A table containing all of the column types, and different column kwargs. """ array_col = Array(Varchar()) bigint_col = BigInt() boolean_col = Boolean() bytea_col = Bytea() date_col = Date() double_precision_col = DoublePrecision() integer_col = Integer() interval_col = Interval() json_col = JSON() jsonb_col = JSONB() numeric_col = Numeric(digits=(5, 2)) real_col = Real() smallint_col = SmallInt() text_col = Text() timestamp_col = Timestamp() timestamptz_col = Timestamptz() uuid_col = UUID() varchar_col = Varchar()
def test_get_choices_dict(self): """ Test ``get_choices_dict``. """ class Title(Enum): mr = 1 mrs = 2 column = Integer(choices=Title) self.assertEqual( column._meta.get_choices_dict(), { "mr": { "display_name": "Mr", "value": 1 }, "mrs": { "display_name": "Mrs", "value": 2 }, }, )
class Band(Table): name = Varchar(db_column_name="regrettable_column_name") popularity = Integer()
class Concert(Table): order = Integer()
class Book(Table): name = Varchar(length=50) writer = ForeignKey(Writer, null=True) popularity = Integer(default=0)
class Concert(Table): name = Varchar(index=True, index_method=IndexMethod.hash) time = Timestamp( index=True ) # Testing a column with the same name as a Postgres data type. capacity = Integer(index=False)
class Post(Table): name = Varchar(length=100) content = Text() created = Timestamp() rating = Integer()
def test_get_choices_dict_without_choices(self): """ Test ``get_choices_dict``, with no choices set. """ column = Integer() self.assertEqual(column._meta.get_choices_dict(), None)
class MyTable(Table): value = Array(base_column=Integer())
class Movie(Table): id = UUID(primary_key=True) name = Varchar(length=100, required=True) rating = Integer()