Exemplo n.º 1
0
    def test_table_definition(self):
        """ Tests that creating a table with capitalized column names succeeds """
        sync_table(self.conn, LowercaseKeyModel)
        sync_table(self.conn, CapitalizedKeyModel)

        drop_table(self.conn, LowercaseKeyModel)
        drop_table(self.conn, CapitalizedKeyModel)
Exemplo n.º 2
0
    def test_sync_indexed_set(self):
        """
        Tests that models that have container types with indices can be synced.

        @since 3.2
        @jira_ticket PYTHON-533
        @expected_result table_sync should complete without a server error.

        @test_category object_mapper
        """
        sync_table(self.conn, TestIndexSetModel)
        table_meta = management._get_table_metadata(
            self.conn,
            TestIndexSetModel,
        )
        self.assertIsNotNone(
            management._get_index_name_by_column(table_meta, 'int_set')
        )
        self.assertIsNotNone(
            management._get_index_name_by_column(table_meta, 'int_list')
        )
        self.assertIsNotNone(
            management._get_index_name_by_column(table_meta, 'text_map')
        )
        self.assertIsNotNone(
            management._get_index_name_by_column(table_meta, 'mixed_tuple')
        )
Exemplo n.º 3
0
    def test_can_insert_double_and_float(self):
        """
        Test for inserting single-precision and double-precision values into a Float and Double columns

        @since 2.6.0
        @changed 3.0.0 removed deprecated Float(double_precision) parameter
        @jira_ticket PYTHON-246
        @expected_result Each floating point column type is able to hold their respective precision values.

        @test_category data_types:primitive
        """
        class FloatingPointModel(Model):
            id = columns.Integer(primary_key=True)
            f = columns.Float()
            d = columns.Double()

        sync_table(self.conn, FloatingPointModel)

        FloatingPointModel.create(self.conn, id=0, f=2.39)
        output = FloatingPointModel.objects().first(self.conn)
        self.assertEqual(2.390000104904175, output.f)  # float loses precision

        FloatingPointModel.create(self.conn,
                                  id=0,
                                  f=3.4028234663852886e38,
                                  d=2.39)
        output = FloatingPointModel.objects().first(self.conn)
        self.assertEqual(3.4028234663852886e38, output.f)
        self.assertEqual(2.39, output.d)  # double retains precision

        FloatingPointModel.create(self.conn, id=0, d=3.4028234663852886e38)
        output = FloatingPointModel.objects().first(self.conn)
        self.assertEqual(3.4028234663852886e38, output.d)
Exemplo n.º 4
0
    def test_primary_key_validation(self):
        """
        Test to ensure that changes to primary keys throw CQLEngineExceptions

        @since 3.2
        @jira_ticket PYTHON-532
        @expected_result Attempts to modify primary keys throw an exception

        @test_category object_mapper
        """
        sync_table(self.conn, PrimaryKeysOnlyModel)
        self.assertRaises(
            CQLEngineException,
            sync_table,
            self.conn,
            PrimaryKeysModelChanged,
        )
        self.assertRaises(
            CQLEngineException,
            sync_table,
            self.conn,
            PrimaryKeysAddedClusteringKey,
        )
        self.assertRaises(
            CQLEngineException,
            sync_table,
            self.conn,
            PrimaryKeysRemovedPk,
        )
Exemplo n.º 5
0
    def test_sync_index_case_sensitive(self):
        """
        Tests the default table creation, and ensures the table_name is
        created correctly and surfaced correctly in table metadata

        @since 3.1
        @jira_ticket PYTHON-337
        @expected_result table_name is lower case

        @test_category object_mapper
        """
        sync_table(self.conn, IndexCaseSensitiveModel)
        table_meta = management._get_table_metadata(
            self.conn,
            IndexCaseSensitiveModel,
        )
        self.assertIsNotNone(
            management._get_index_name_by_column(table_meta, 'second_key')
        )

        # index already exists
        sync_table(self.conn, IndexCaseSensitiveModel)
        table_meta = management._get_table_metadata(
            self.conn,
            IndexCaseSensitiveModel,
        )
        self.assertIsNotNone(
            management._get_index_name_by_column(table_meta, 'second_key')
        )
Exemplo n.º 6
0
    def test_all_size_tiered_options(self):
        class AllSizeTieredOptionsModel(Model):
            __options__ = {
                "compaction": {
                    "class": ("org.apache.cassandra.db.compaction."
                              "SizeTieredCompactionStrategy"),
                    "bucket_low":
                    ".3",
                    "bucket_high":
                    "2",
                    "min_threshold":
                    "2",
                    "max_threshold":
                    "64",
                    "tombstone_compaction_interval":
                    "86400",
                }
            }

            cid = columns.UUID(primary_key=True)
            name = columns.Text()

        drop_table(self.conn, AllSizeTieredOptionsModel)
        sync_table(self.conn, AllSizeTieredOptionsModel)

        table_meta = _get_table_metadata(self.conn, AllSizeTieredOptionsModel)
        self._verify_options(table_meta, AllSizeTieredOptionsModel.__options__)
Exemplo n.º 7
0
    def test_can_insert_udts_withh_nones(self):
        """
        Test for inserting all column types as empty into a UserType as None's

        test_can_insert_udts_with_nones tests that each cqlengine column type can be inserted into a UserType as None's.
        It first creates a UserType that has each cqlengine column type, and a corresponding table/Model. It then creates
        a UserType instance where all the fields are None's and inserts the UserType as an instance of the Model. Finally,
        it verifies that each column read from the UserType from Cassandra is None.

        @since 2.5.0
        @jira_ticket PYTHON-251
        @expected_result The UserType is inserted with each column type, and the resulting read yields None's for each column.

        @test_category data_types:udt
        """

        class AllDatatypes(UserType):
            a = columns.Ascii()
            b = columns.BigInt()
            c = columns.Blob()
            d = columns.Boolean()
            e = columns.DateTime()
            f = columns.Decimal()
            g = columns.Double()
            h = columns.Float()
            i = columns.Inet()
            j = columns.Integer()
            k = columns.Text()
            l = columns.TimeUUID()
            m = columns.UUID()
            n = columns.VarInt()

        class AllDatatypesModel(Model):
            id = columns.Integer(primary_key=True)
            data = columns.UserDefinedType(AllDatatypes)

        sync_table(self.conn, AllDatatypesModel)

        input = AllDatatypes(
            a=None,
            b=None,
            c=None,
            d=None,
            e=None,
            f=None,
            g=None,
            h=None,
            i=None,
            j=None,
            k=None,
            l=None,
            m=None,
            n=None,
        )
        AllDatatypesModel.create(self.conn, id=0, data=input)

        self.assertEqual(1, AllDatatypesModel.objects.count(self.conn))

        output = AllDatatypesModel.objects().first(self.conn).data
        self.assertEqual(input, output)
    def test_compaction_not_altered_without_changes_sizetiered(self):
        class SizeTieredCompactionChangesDetectionTest(Model):

            __options__ = {
                'compaction': {
                    'class': ('org.apache.cassandra.db.compaction.'
                              'SizeTieredCompactionStrategy'),
                    'bucket_high':
                    '20',
                    'bucket_low':
                    '10',
                    'max_threshold':
                    '200',
                    'min_threshold':
                    '100',
                    'min_sstable_size':
                    '1000',
                    'tombstone_threshold':
                    '0.125',
                    'tombstone_compaction_interval':
                    '3600',
                },
            }
            pk = columns.Integer(primary_key=True)

        drop_table(self.conn, SizeTieredCompactionChangesDetectionTest)
        sync_table(self.conn, SizeTieredCompactionChangesDetectionTest)

        self.assertFalse(
            _update_options(
                self.conn,
                SizeTieredCompactionChangesDetectionTest,
            ))
Exemplo n.º 9
0
 def test_extra_field(self):
     drop_table(self.conn, self.TestModel)
     sync_table(self.conn, self.TestModel)
     self.TestModel.create(self.conn)
     self.conn.execute("ALTER TABLE {0} add blah int".format(
         self.TestModel.column_family_name()))
     self.TestModel.objects().find_all(self.conn)
Exemplo n.º 10
0
    def test_alter_options(self):
        class AlterTable(Model):

            __options__ = {
                'compaction': {
                    'class': ('org.apache.cassandra.db.compaction.'
                              'LeveledCompactionStrategy'),
                    'sstable_size_in_mb':
                    '64',
                },
            }
            user_id = columns.UUID(primary_key=True)
            name = columns.Text()

        drop_table(self.conn, AlterTable)
        sync_table(self.conn, AlterTable)
        table_meta = _get_table_metadata(self.conn, AlterTable)
        self.assertRegexpMatches(
            table_meta.export_as_string(),
            ".*'sstable_size_in_mb': '64'.*",
        )
        AlterTable.__options__['compaction']['sstable_size_in_mb'] = '128'
        sync_table(self.conn, AlterTable)
        table_meta = _get_table_metadata(self.conn, AlterTable)
        self.assertRegexpMatches(
            table_meta.export_as_string(),
            ".*'sstable_size_in_mb': '128'.*",
        )
Exemplo n.º 11
0
    def test_all_size_tiered_options(self):
        class AllSizeTieredOptionsModel(Model):
            __options__ = {
                'compaction': {
                    'class': ('org.apache.cassandra.db.compaction.'
                              'SizeTieredCompactionStrategy'),
                    'bucket_low':
                    '.3',
                    'bucket_high':
                    '2',
                    'min_threshold':
                    '2',
                    'max_threshold':
                    '64',
                    'tombstone_compaction_interval':
                    '86400',
                },
            }

            cid = columns.UUID(primary_key=True)
            name = columns.Text()

        drop_table(self.conn, AllSizeTieredOptionsModel)
        sync_table(self.conn, AllSizeTieredOptionsModel)

        table_meta = _get_table_metadata(self.conn, AllSizeTieredOptionsModel)
        self._verify_options(
            table_meta,
            AllSizeTieredOptionsModel.__options__,
        )
Exemplo n.º 12
0
    def test_compaction_not_altered_without_changes_leveled(self):

        class LeveledCompactionChangesDetectionTest(Model):

            __options__ = {
                'compaction': {
                    'class': (
                        'org.apache.cassandra.db.compaction.'
                        'LeveledCompactionStrategy'
                    ),
                    'sstable_size_in_mb': '160',
                    'tombstone_threshold': '0.125',
                    'tombstone_compaction_interval': '3600',
                },
            }
            pk = columns.Integer(primary_key=True)

        drop_table(self.conn, LeveledCompactionChangesDetectionTest)
        sync_table(self.conn, LeveledCompactionChangesDetectionTest)

        self.assertFalse(
            _update_options(
                self.conn,
                LeveledCompactionChangesDetectionTest
            )
        )
Exemplo n.º 13
0
    def test_compaction_not_altered_without_changes_sizetiered(self):
        class SizeTieredCompactionChangesDetectionTest(Model):

            __options__ = {
                "compaction": {
                    "class": ("org.apache.cassandra.db.compaction."
                              "SizeTieredCompactionStrategy"),
                    "bucket_high":
                    "20",
                    "bucket_low":
                    "10",
                    "max_threshold":
                    "200",
                    "min_threshold":
                    "100",
                    "min_sstable_size":
                    "1000",
                    "tombstone_threshold":
                    "0.125",
                    "tombstone_compaction_interval":
                    "3600",
                }
            }
            pk = columns.Integer(primary_key=True)

        drop_table(self.conn, SizeTieredCompactionChangesDetectionTest)
        sync_table(self.conn, SizeTieredCompactionChangesDetectionTest)

        self.assertFalse(
            _update_options(self.conn,
                            SizeTieredCompactionChangesDetectionTest))
Exemplo n.º 14
0
    def test_model_over_write(self):
        """
        Test to ensure overwriting of primary keys in model inheritance is
        allowed

        This is currently only an issue in PyPy. When PYTHON-504 is
        introduced this should be updated error out and warn the user

        @since 3.6.0
        @jira_ticket PYTHON-576
        @expected_result primary keys can be overwritten via inheritance

        @test_category object_mapper
        """
        class TimeModelBase(Model):
            uuid = columns.TimeUUID(primary_key=True)

        class DerivedTimeModel(TimeModelBase):
            __table_name__ = "derived_time"
            uuid = columns.TimeUUID(primary_key=True, partition_key=True)
            value = columns.Text(required=False)

        # In case the table already exists in keyspace
        drop_table(self.conn, DerivedTimeModel)

        sync_table(self.conn, DerivedTimeModel)
        uuid_value = uuid1()
        uuid_value2 = uuid1()
        DerivedTimeModel.create(self.conn, uuid=uuid_value, value="first")
        DerivedTimeModel.create(self.conn, uuid=uuid_value2, value="second")
        DerivedTimeModel.objects.filter(uuid=uuid_value)
Exemplo n.º 15
0
    def test_default_values(self):
        """
        Test that default types are set on object creation for UDTs

        @since 3.7.0
        @jira_ticket PYTHON-606
        @expected_result Default values should be set.

        @test_category data_types:udt
        """

        class NestedUdt(UserType):

            test_id = columns.UUID(default=uuid4)
            something = columns.Text()
            default_text = columns.Text(default="default text")

        class OuterModel(Model):

            name = columns.Text(primary_key=True)
            first_name = columns.Text()
            nested = columns.List(columns.UserDefinedType(NestedUdt))
            simple = columns.UserDefinedType(NestedUdt)

        sync_table(self.conn, OuterModel)

        t = OuterModel.create(self.conn, name="test1")
        t.nested = [NestedUdt(something="test")]
        t.simple = NestedUdt(something="")
        t.save(self.conn)
        self.assertIsNotNone(t.nested[0].test_id)
        self.assertEqual(t.nested[0].default_text, "default text")
        self.assertIsNotNone(t.simple.test_id)
        self.assertEqual(t.simple.default_text, "default text")
Exemplo n.º 16
0
    def test_sync_table_works_with_primary_keys_only_tables(self):

        sync_table(self.conn, PrimaryKeysOnlyModel)
        # blows up with DoesNotExist if table does not exist
        table_meta = management._get_table_metadata(
            self.conn,
            PrimaryKeysOnlyModel,
        )

        self.assertIn('LeveledCompactionStrategy', table_meta.as_cql_query())

        PrimaryKeysOnlyModel.__options__['compaction']['class'] = (
            'SizeTieredCompactionStrategy'
        )

        sync_table(self.conn, PrimaryKeysOnlyModel)

        table_meta = management._get_table_metadata(
            self.conn,
            PrimaryKeysOnlyModel,
        )
        self.assertIn(
            'SizeTieredCompactionStrategy',
            table_meta.as_cql_query(),
        )
Exemplo n.º 17
0
    def test_can_insert_nested_udts(self):
        class Depth_0(UserType):
            age = columns.Integer()
            name = columns.Text()

        class Depth_1(UserType):
            value = columns.UserDefinedType(Depth_0)

        class Depth_2(UserType):
            value = columns.UserDefinedType(Depth_1)

        class Depth_3(UserType):
            value = columns.UserDefinedType(Depth_2)

        class DepthModel(Model):
            id = columns.Integer(primary_key=True)
            v_0 = columns.UserDefinedType(Depth_0)
            v_1 = columns.UserDefinedType(Depth_1)
            v_2 = columns.UserDefinedType(Depth_2)
            v_3 = columns.UserDefinedType(Depth_3)

        sync_table(self.conn, DepthModel)

        udts = [Depth_0(age=42, name="John")]
        udts.append(Depth_1(value=udts[0]))
        udts.append(Depth_2(value=udts[1]))
        udts.append(Depth_3(value=udts[2]))

        DepthModel.create(self.conn, id=0, v_0=udts[0], v_1=udts[1], v_2=udts[2], v_3=udts[3])
        output = DepthModel.objects().first(self.conn)

        self.assertEqual(udts[0], output.v_0)
        self.assertEqual(udts[1], output.v_1)
        self.assertEqual(udts[2], output.v_2)
        self.assertEqual(udts[3], output.v_3)
Exemplo n.º 18
0
 def setUpClass(cls):
     super(TestUpdating, cls).setUpClass()
     conn = cls.connection()
     drop_table(conn, TestModelSave)
     drop_table(conn, TestMultiKeyModel)
     sync_table(conn, TestModelSave)
     sync_table(conn, TestMultiKeyModel)
Exemplo n.º 19
0
    def test_udts_with_unicode(self):
        """
        Test for inserting models with unicode and udt columns.

        test_udts_with_unicode constructs a model with a user defined type. It then attempts to insert that model with
        a unicode primary key. It will also attempt to upsert a udt that contains unicode text.

        @since 3.0.0
        @jira_ticket PYTHON-353
        @expected_result No exceptions thrown

        @test_category data_types:udt
        """
        ascii_name = "normal name"
        unicode_name = "Fran\u00E7ois"

        class User(UserType):
            age = columns.Integer()
            name = columns.Text()

        class UserModelText(Model):
            id = columns.Text(primary_key=True)
            info = columns.UserDefinedType(User)

        sync_table(self.conn, UserModelText)
        # Two udt instances one with a unicode one with ascii
        user_template_ascii = User(age=25, name=ascii_name)
        user_template_unicode = User(age=25, name=unicode_name)

        UserModelText.create(self.conn, id=ascii_name, info=user_template_unicode)
        UserModelText.create(self.conn, id=unicode_name, info=user_template_ascii)
        UserModelText.create(self.conn, id=unicode_name, info=user_template_unicode)
Exemplo n.º 20
0
    def test_can_insert_partial_udts(self):
        class User(UserType):
            age = columns.Integer()
            name = columns.Text()
            gender = columns.Text()

        class UserModel(Model):
            id = columns.Integer(primary_key=True)
            info = columns.UserDefinedType(User)

        sync_table(self.conn, UserModel)

        user = User(age=42, name="John")
        UserModel.create(self.conn, id=0, info=user)

        john_info = UserModel.objects().first(self.conn).info
        self.assertEqual(42, john_info.age)
        self.assertEqual("John", john_info.name)
        self.assertIsNone(john_info.gender)

        user = User(age=42)
        UserModel.create(self.conn, id=0, info=user)

        john_info = UserModel.objects().first(self.conn).info
        self.assertEqual(42, john_info.age)
        self.assertIsNone(john_info.name)
        self.assertIsNone(john_info.gender)
Exemplo n.º 21
0
    def setUpClass(cls):
        if PROTOCOL_VERSION < 4:
            return

        super(TestQuerying, cls).setUpClass()
        conn = cls.connection()
        drop_table(conn, TestQueryModel)
        sync_table(conn, TestQueryModel)
 def setUpClass(cls):
     # Skip annotations don't seem to skip class level teradown and setup
     # methods
     super(TestNestedType, cls).setUpClass()
     if CASSANDRA_VERSION >= "2.1":
         conn = cls.connection()
         drop_table(conn, TestNestedModel)
         sync_table(conn, TestNestedModel)
Exemplo n.º 23
0
    def test_can_insert_udts_with_all_datatypes(self):
        """
        Test for inserting all column types into a UserType

        test_can_insert_udts_with_all_datatypes tests that each cqlengine column type can be inserted into a UserType.
        It first creates a UserType that has each cqlengine column type, and a corresponding table/Model. It then creates
        a UserType instance where all the fields have corresponding data, and inserts the UserType as an instance of the Model.
        Finally, it verifies that each column read from the UserType from Cassandra is the same as the input parameters.

        @since 2.5.0
        @jira_ticket PYTHON-251
        @expected_result The UserType is inserted with each column type, and the resulting read yields proper data for each column.

        @test_category data_types:udt
        """
        class AllDatatypes(UserType):
            a = columns.Ascii()
            b = columns.BigInt()
            c = columns.Blob()
            d = columns.Boolean()
            e = columns.DateTime()
            f = columns.Decimal()
            g = columns.Double()
            h = columns.Float()
            i = columns.Inet()
            j = columns.Integer()
            k = columns.Text()
            l = columns.TimeUUID()
            m = columns.UUID()
            n = columns.VarInt()

        class AllDatatypesModel(Model):
            id = columns.Integer(primary_key=True)
            data = columns.UserDefinedType(AllDatatypes)

        sync_table(self.conn, AllDatatypesModel)

        input = AllDatatypes(a='ascii',
                             b=2**63 - 1,
                             c=bytearray(b'hello world'),
                             d=True,
                             e=datetime.utcfromtimestamp(872835240),
                             f=Decimal('12.3E+7'),
                             g=2.39,
                             h=3.4028234663852886e+38,
                             i='123.123.123.123',
                             j=2147483647,
                             k='text',
                             l=UUID('FE2B4360-28C6-11E2-81C1-0800200C9A66'),
                             m=UUID('067e6162-3b6f-4ae2-a171-2470b63dff00'),
                             n=int(str(2147483647) + '000'))
        AllDatatypesModel.create(self.conn, id=0, data=input)

        self.assertEqual(1, AllDatatypesModel.objects.count(self.conn))
        output = AllDatatypesModel.objects().first(self.conn).data

        for i in range(ord('a'), ord('a') + 14):
            self.assertEqual(input[chr(i)], output[chr(i)])
Exemplo n.º 24
0
 def setUpClass(cls):
     super(BaseIfNotExistsTest, cls).setUpClass()
     """
     when receiving an insert statement with 'if not exist', cassandra would
     perform a read with QUORUM level. Unittest would be failed if
     replica_factor is 3 and one node only. Therefore I have create a new
     keyspace with replica_factor:1.
     """
     sync_table(cls.connection(), TestIfNotExistsModel)
Exemplo n.º 25
0
    def test_keywords_as_names(self):
        """
        Test for CQL keywords as names

        test_keywords_as_names tests that CQL keywords are properly and
        automatically quoted in cqlengine. It creates a keyspace, keyspace,
        which should be automatically quoted to "keyspace" in CQL. It then
        creates a table, table, which should also be automatically quoted to
        "table". It then verfies that operations can be done on the
        "keyspace"."table" which has been created. It also verifies that table
        alternations work and operations can be performed on the altered table.

        @since 2.6.0
        @jira_ticket PYTHON-244
        @expected_result Cqlengine should quote CQL keywords properly when
        creating keyspaces and tables.

        @test_category schema:generation
        """

        # If the keyspace exists, it will not be re-created
        create_keyspace_simple(self.conn, "keyspace", 1)
        k_conn = self.connection("keyspace")

        class table(Model):
            select = columns.Integer(primary_key=True)
            table = columns.Text()

        # In case the table already exists in keyspace
        drop_table(k_conn, table)

        # Create should work
        sync_table(k_conn, table)

        created = table.create(k_conn, select=0, table="table")
        selected = table.objects(select=0).first(k_conn)
        self.assertEqual(created.select, selected.select)
        self.assertEqual(created.table, selected.table)

        # Alter should work
        class table(Model):
            select = columns.Integer(primary_key=True)
            table = columns.Text()
            where = columns.Text()

        sync_table(k_conn, table)

        created = table.create(k_conn, select=1, table="table")
        selected = table.objects(select=1).first(k_conn)
        self.assertEqual(created.select, selected.select)
        self.assertEqual(created.table, selected.table)
        self.assertEqual(created.where, selected.where)

        drop_keyspace(self.conn, "keyspace")
        del k_conn
Exemplo n.º 26
0
    def test_can_insert_model_with_all_protocol_v4_column_types(self):
        """
        Test for inserting all protocol v4 column types into a Model

        test_can_insert_model_with_all_protocol_v4_column_types tests that
        each cqlengine protocol v4 column type can be inserted into a Model.
        It first creates a Model that has each cqlengine protocol v4 column
        type. It then creates a Model instance where all the fields have
        corresponding data, which performs the insert into the Cassandra table.
        Finally, it verifies that each column read from the Model from
        Cassandra is the same as the input parameters.

        @since 2.6.0
        @jira_ticket PYTHON-245
        @expected_result The Model is inserted with each protocol v4 column
        type, and the resulting read yields proper data for each column.

        @test_category data_types:primitive
        """

        if PROTOCOL_VERSION < 4:
            raise unittest.SkipTest(
                "Protocol v4 datatypes require native protocol 4+, "
                "currently using: {0}".format(PROTOCOL_VERSION))

        class v4DatatypesModel(Model):
            id = columns.Integer(primary_key=True)
            a = columns.Date()
            b = columns.SmallInt()
            c = columns.Time()
            d = columns.TinyInt()

        sync_table(self.conn, v4DatatypesModel)

        input = [
            Date(date(1970, 1, 1)),
            32523,
            Time(time(16, 47, 25, 7)),
            123,
        ]

        v4DatatypesModel.create(
            self.conn,
            id=0,
            a=date(1970, 1, 1),
            b=32523,
            c=time(16, 47, 25, 7),
            d=123,
        )

        self.assertEqual(1, v4DatatypesModel.objects.count(self.conn))
        output = v4DatatypesModel.objects().first(self.conn)

        for i, i_char in enumerate(range(ord('a'), ord('a') + 3)):
            self.assertEqual(input[i], output[chr(i_char)])
Exemplo n.º 27
0
    def setUpClass(cls):
        super(TestDateTimeQueries, cls).setUpClass()
        conn = cls.connection()
        sync_table(conn, DateTimeQueryTestModel)

        cls.base_date = datetime.now() - timedelta(days=10)
        for x in range(7):
            for y in range(10):
                DateTimeQueryTestModel.create(
                    conn, user=x, day=(cls.base_date + timedelta(days=y)), data=str(uuid4())
                )
Exemplo n.º 28
0
 def setUpClass(cls):
     super(TestLoadMany, cls).setUpClass()
     conn = cls.connection()
     sync_table(conn, SimpleModel)
     sync_table(conn, ComplexModel)
     SimpleModel.create(conn, key="alpha", value="omega")
     SimpleModel.create(conn, key="foo", value="bar")
     SimpleModel.create(conn, key="zip", value="zap")
     ComplexModel.create(conn, pk="fizz", ck=0, value="buzz")
     ComplexModel.create(conn, pk="fizz", ck=1, value="hunter2")
     ComplexModel.create(conn, pk="key", ck=0, value="value")
Exemplo n.º 29
0
    def test_reserved_cql_words_can_be_used_as_column_names(self):
        """
        """
        sync_table(self.conn, ReservedWordModel)

        model1 = ReservedWordModel.create(self.conn, token="1", insert=5)

        model2 = ReservedWordModel.filter(token="1")

        self.assertTrue(len(model2.find_all(self.conn)) == 1)
        self.assertTrue(model1.token == model2.first(self.conn).token)
        self.assertTrue(model1.insert == model2.first(self.conn).insert)
Exemplo n.º 30
0
    def test_default_ttl_modify(self):
        default_ttl = self.get_default_ttl("test_default_ttlmodel")
        self.assertEqual(default_ttl, 20)

        TestDefaultTTLModel.__options__ = {"default_time_to_live": 10}
        sync_table(self.conn, TestDefaultTTLModel)

        default_ttl = self.get_default_ttl("test_default_ttlmodel")
        self.assertEqual(default_ttl, 10)

        # Restore default TTL
        TestDefaultTTLModel.__options__ = {"default_time_to_live": 20}
        sync_table(self.conn, TestDefaultTTLModel)