Ejemplo n.º 1
0
    def test_export_as_string_user_types(self):
        keyspace_name = 'test'
        keyspace = KeyspaceMetadata(keyspace_name, True, 'SimpleStrategy',
                                    dict(replication_factor=3))
        keyspace.user_types['a'] = UserType(keyspace_name, 'a', ['one', 'two'],
                                            ['c', 'int'])
        keyspace.user_types['b'] = UserType(keyspace_name, 'b',
                                            ['one', 'two', 'three'],
                                            ['d', 'int', 'a'])
        keyspace.user_types['c'] = UserType(keyspace_name, 'c', ['one'],
                                            ['int'])
        keyspace.user_types['d'] = UserType(keyspace_name, 'd', ['one'], ['c'])

        self.assertEqual(
            """CREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'}  AND durable_writes = true;

CREATE TYPE test.c (
    one int
);

CREATE TYPE test.a (
    one c,
    two int
);

CREATE TYPE test.d (
    one c
);

CREATE TYPE test.b (
    one d,
    two int,
    three a
);""", keyspace.export_as_string())
Ejemplo n.º 2
0
    def test_as_cql_query(self):
        field_types = ['varint', 'ascii', 'frozen<tuple<varint, ascii>>']
        udt = UserType("ks1", "mytype", ["a", "b", "c"], field_types)
        self.assertEqual(
            "CREATE TYPE ks1.mytype (a varint, b ascii, c frozen<tuple<varint, ascii>>)",
            udt.as_cql_query(formatted=False))

        self.assertEqual(
            """CREATE TYPE ks1.mytype (
    a varint,
    b ascii,
    c frozen<tuple<varint, ascii>>
);""", udt.export_as_string())
Ejemplo n.º 3
0
 def test_user_type(self):
     um = UserType(self.name, self.name, [self.name, self.name],
                   [u'int', u'text'])
     um.export_as_string()
Ejemplo n.º 4
0
 def test_as_cql_query_name_escaping(self):
     udt = UserType("MyKeyspace", "MyType", ["AbA", "keyspace"],
                    ['ascii', 'ascii'])
     self.assertEqual(
         'CREATE TYPE "MyKeyspace"."MyType" ("AbA" ascii, "keyspace" ascii)',
         udt.as_cql_query(formatted=False))