'Basic test of tuple functionality'

def test_can_insert_tuples(self):

    if (self.cass_version < (2, 1, 0)):
        raise unittest.SkipTest('The    tuple    type    was    introduced    in    Cassandra    2.1')
    c = Cluster(protocol_version=PROTOCOL_VERSION)
    s = c.connect(self.keyspace_name)
    s.encoder.mapping[tuple] = s.encoder.cql_encode_tuple
    s.execute('CREATE    TABLE    tuple_type        (a    int    PRIMARY    KEY,    b    frozen<tuple<ascii,    int,    boolean>>)')
    complete = ('foo', 123, True)
    s.execute('INSERT    INTO    tuple_type    (a,    b)    VALUES    (0,    %s)', parameters=(complete,))
    result = s.execute('SELECT    b    FROM    tuple_type    WHERE    a=0')[0]
    self.assertEqual(complete, result.b)
    partial = ('bar', 456)
    partial_result = (partial + (None,))
    s.execute('INSERT    INTO    tuple_type    (a,    b)    VALUES    (1,    %s)', parameters=(partial,))
    result = s.execute('SELECT    b    FROM    tuple_type    WHERE    a=1')[0]
    self.assertEqual(partial_result, result.b)
    subpartial = ('zoo',)
    subpartial_result = (subpartial + (None, None))
    s.execute('INSERT    INTO    tuple_type    (a,    b)    VALUES    (2,    %s)', parameters=(subpartial,))
    result = s.execute('SELECT    b    FROM    tuple_type    WHERE    a=2')[0]
    self.assertEqual(subpartial_result, result.b)
    prepared = s.prepare('INSERT    INTO    tuple_type    (a,    b)    VALUES    (?,    ?)')
    s.execute(prepared, parameters=(3, complete))
    s.execute(prepared, parameters=(4, partial))
    s.execute(prepared, parameters=(5, subpartial))
    self.assertRaises(ValueError, s.execute, prepared, parameters=(0, (1, 2, 3, 4, 5, 6)))
    prepared = s.prepare('SELECT    b    FROM    tuple_type    WHERE    a=?')
    self.assertEqual(complete, s.execute(prepared, (3,))[0].b)
    self.assertEqual(partial_result, s.execute(prepared, (4,))[0].b)
    self.assertEqual(subpartial_result, s.execute(prepared, (5,))[0].b)
    c.shutdown()
