Example #1
0
 def test_column_type_conversion_integer(self):
     self._test_migrations(table_snapshots=[[self.table(column)]
                                            for column in [
                                                Integer(),
                                                BigInt(),
                                                SmallInt(),
                                                BigInt(),
                                                Integer(),
                                            ]])
Example #2
0
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)
Example #3
0
 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"),
                                            ]])
Example #4
0
 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()
Example #6
0
    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)
Example #7
0
 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[]",
         ]),
     )
Example #8
0
 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",
         ]),
     )
Example #9
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
                },
            },
        )
Example #10
0
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()
Example #11
0
    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()
Example #13
0
class Concert(Table):
    order = Integer()
Example #14
0
class Book(Table):
    name = Varchar(length=50)
    writer = ForeignKey(Writer, null=True)
    popularity = Integer(default=0)
Example #15
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)
Example #16
0
class Post(Table):
    name = Varchar(length=100)
    content = Text()
    created = Timestamp()
    rating = Integer()
Example #17
0
 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)
Example #18
0
class MyTable(Table):
    value = Array(base_column=Integer())
Example #19
0
class Movie(Table):
    id = UUID(primary_key=True)
    name = Varchar(length=100, required=True)
    rating = Integer()