예제 #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())
예제 #2
0
    def test_as_cql_query(self):
        field_types = [IntegerType, AsciiType, TupleType.apply_parameters([IntegerType, AsciiType])]
        udt = UserType("ks1", "mytype", ["a", "b", "c"], field_types)
        self.assertEqual("CREATE TYPE ks1.mytype (a varint, b ascii, c tuple<varint, ascii>);", udt.as_cql_query(formatted=False))

        self.assertEqual("""CREATE TYPE ks1.mytype (
    a varint,
    b ascii,
    c tuple<varint, ascii>
);""", udt.as_cql_query(formatted=True))
예제 #3
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())
예제 #4
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())
예제 #5
0
    def test_as_cql_query(self):
        field_types = [IntegerType, AsciiType, TupleType.apply_parameters([IntegerType, AsciiType])]
        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.as_cql_query(formatted=True))
예제 #6
0
 def test_as_cql_query_name_escaping(self):
     udt = UserType("MyKeyspace", "MyType", ["AbA", "keyspace"], [AsciiType, AsciiType])
     self.assertEqual('CREATE TYPE "MyKeyspace"."MyType" ("AbA" ascii, "keyspace" ascii);', udt.as_cql_query(formatted=False))
예제 #7
0
 def test_user_type(self):
     um = UserType(self.name, self.name, [self.name, self.name], [u'int', u'text'])
     um.export_as_string()
예제 #8
0
 def test_as_cql_query_name_escaping(self):
     udt = UserType("MyKeyspace", "MyType", ["AbA", "keyspace"],
                    [AsciiType, AsciiType])
     self.assertEqual(
         'CREATE TYPE "MyKeyspace"."MyType" ("AbA" ascii, "keyspace" ascii);',
         udt.as_cql_query(formatted=False))
예제 #9
0
 def test_user_type(self):
     um = UserType(self.name, self.name, [self.name, self.name],
                   [u'int', u'text'])
     um.export_as_string()
예제 #10
0
def udt(keyspace, name, field_names, field_types):
    return UserType(keyspace.name, name, field_names, field_types)