コード例 #1
0
    def test_can_create_same_udt_different_keyspaces(self):
        class User(UserType):
            age = columns.Integer()
            name = columns.Text()

        sync_type(self.conn, User)

        create_keyspace_simple(self.conn, "simplex", 1)
        sync_type(self.conn, User)
        drop_keyspace(self.conn, "simplex")
コード例 #2
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
コード例 #3
0
    def test_create_drop_succeeeds(self):
        cluster = self.conn.cluster

        keyspace_ss = "test_ks_ss"
        self.assertNotIn(keyspace_ss, cluster.metadata.keyspaces)
        management.create_keyspace_simple(self.conn, keyspace_ss, 2)
        self.assertIn(keyspace_ss, cluster.metadata.keyspaces)

        management.drop_keyspace(self.conn, keyspace_ss)
        self.assertNotIn(keyspace_ss, cluster.metadata.keyspaces)

        keyspace_nts = "test_ks_nts"
        self.assertNotIn(keyspace_nts, cluster.metadata.keyspaces)
        management.create_keyspace_network_topology(self.conn, keyspace_nts, {"dc1": 1})
        self.assertIn(keyspace_nts, cluster.metadata.keyspaces)

        management.drop_keyspace(self.conn, keyspace_nts)
        self.assertNotIn(keyspace_nts, cluster.metadata.keyspaces)