'Test the legacy API for custom columns'

def test_legacy_custom(self):

    ndb = self.init_legacy(self.cloned_library)
    db = self.init_old(self.cloned_library)
    run_funcs(self, db, ndb, ((u'all_custom', u'series'), (u'all_custom', u'tags'), (u'all_custom', u'rating'), (u'all_custom', u'authors'), (u'all_custom', None, 7), (u'get_next_cc_series_num_for', u'My    Series    One', u'series'), (u'get_next_cc_series_num_for', u'My    Series    Two', u'series'), (u'is_item_used_in_multiple', u'My    Tag    One', u'tags'), (u'is_item_used_in_multiple', u'My    Series    One', u'series'), (u'$get_custom_items_with_ids', u'series'), (u'$get_custom_items_with_ids', u'tags'), (u'$get_custom_items_with_ids', u'float'), (u'$get_custom_items_with_ids', u'rating'), (u'$get_custom_items_with_ids', u'authors'), (u'$get_custom_items_with_ids', None, 7)))
    for label in (u'tags', u'series', u'authors', u'comments', u'rating', u'date', u'yesno', u'isbn', u'enum', u'formats', u'float', u'comp_tags'):
        for func in (u'get_custom', u'get_custom_extra', u'get_custom_and_extra'):
            run_funcs(self, db, ndb, [(func, idx, label) for idx in range(3)])
    t = {v: k for (k, v) in ndb.new_api.get_id_map(u'#tags').iteritems()}[u'My    Tag    One']
    t2 = {v: k for (k, v) in ndb.new_api.get_id_map(u'#tags').iteritems()}[u'My    Tag    Two']
    a = {v: k for (k, v) in ndb.new_api.get_id_map(u'#authors').iteritems()}[u'My    Author    Two']
    a2 = {v: k for (k, v) in ndb.new_api.get_id_map(u'#authors').iteritems()}[u'Custom    One']
    s = {v: k for (k, v) in ndb.new_api.get_id_map(u'#series').iteritems()}[u'My    Series    One']
    run_funcs(self, db, ndb, ((u'delete_custom_item_using_id', t, u'tags'), (u'delete_custom_item_using_id', a, u'authors'), (u'rename_custom_item', t2, u't2', u'tags'), (u'rename_custom_item', a2, u'custom    one', u'authors'), (u'rename_custom_item', s, u'My    Series    Two', u'series'), (u'delete_item_from_multiple', u'custom    two', u'authors'), (db.clean,), (db.refresh,), (u'all_custom', u'series'), (u'all_custom', u'tags'), (u'all_custom', u'authors')))
    for label in (u'tags', u'authors', u'series'):
        run_funcs(self, db, ndb, [(u'get_custom_and_extra', idx, label) for idx in range(3)])
    db.close()
    ndb = self.init_legacy(self.cloned_library)
    db = self.init_old(self.cloned_library)
    run_funcs(self, db, ndb, ((u'-set_custom', 1, u't1    &    t2', u'authors'), (u'-set_custom', 1, u't3    &    t4', u'authors', None, True), (u'-set_custom', 3, u'test    one    &    test    Two', u'authors'), (u'-set_custom', 1, u'ijfkghkjdf', u'enum'), (u'-set_custom', 3, u'One', u'enum'), (u'-set_custom', 3, u'xxx', u'formats'), (u'-set_custom', 1, u'my    tag    two', u'tags', None, False, False, None, True, True), (db.clean,), (db.refresh,), (u'all_custom', u'series'), (u'all_custom', u'tags'), (u'all_custom', u'authors')))
    for label in (u'tags', u'series', u'authors', u'comments', u'rating', u'date', u'yesno', u'isbn', u'enum', u'formats', u'float', u'comp_tags'):
        for func in (u'get_custom', u'get_custom_extra', u'get_custom_and_extra'):
            run_funcs(self, db, ndb, [(func, idx, label) for idx in range(3)])
    db.close()
    ndb = self.init_legacy(self.cloned_library)
    db = self.init_old(self.cloned_library)
    run_funcs(self, db, ndb, ((u'set_custom_bulk', (1, 2, 3), u't1    &    t2', u'authors'), (u'set_custom_bulk', (1, 2, 3), u'a    series', u'series', None, False, False, (9, 10, 11)), (u'set_custom_bulk', (1, 2, 3), u't1', u'tags', None, True), (db.clean,), (db.refresh,), (u'all_custom', u'series'), (u'all_custom', u'tags'), (u'all_custom', u'authors')))
    for label in (u'tags', u'series', u'authors', u'comments', u'rating', u'date', u'yesno', u'isbn', u'enum', u'formats', u'float', u'comp_tags'):
        for func in (u'get_custom', u'get_custom_extra', u'get_custom_and_extra'):
            run_funcs(self, db, ndb, [(func, idx, label) for idx in range(3)])
    db.close()
    ndb = self.init_legacy(self.cloned_library)
    db = self.init_old(self.cloned_library)
    run_funcs(self, db, ndb, ((u'set_custom_bulk_multiple', (1, 2, 3), [u't1'], [u'My    Tag    One'], u'tags'), (db.clean,), (db.refresh,), (u'all_custom', u'tags'), (u'get_custom', 0, u'tags'), (u'get_custom', 1, u'tags'), (u'get_custom', 2, u'tags')))
    db.close()
    o = self.cloned_library
    n = self.cloned_library
    (ndb, db) = (self.init_legacy(n), self.init_old(o))
    ndb.create_custom_column(u'created', u'Created', u'text', True, True, {u'moose': u'cat'})
    db.create_custom_column(u'created', u'Created', u'text', True, True, {u'moose': u'cat'})
    db.close()
    (ndb, db) = (self.init_legacy(n), self.init_old(o))
    self.assertEqual(db.custom_column_label_map[u'created'], ndb.backend.custom_field_metadata(u'created'))
    num = db.custom_column_label_map[u'created'][u'num']
    ndb.set_custom_column_metadata(num, is_editable=False, name=u'Crikey', display={})
    db.set_custom_column_metadata(num, is_editable=False, name=u'Crikey', display={})
    db.close()
    (ndb, db) = (self.init_legacy(n), self.init_old(o))
    self.assertEqual(db.custom_column_label_map[u'created'], ndb.backend.custom_field_metadata(u'created'))
    db.close()
    ndb = self.init_legacy(n)
    ndb.delete_custom_column(u'created')
    ndb = self.init_legacy(n)
    self.assertRaises(KeyError, ndb.custom_field_name, num=num)
    ndb = self.init_legacy(self.cloned_library)
    ndb.set_custom(1, u'TS    [9]', label=u'series')
    self.assertEqual(ndb.new_api.field_for(u'#series', 1), u'TS')
    self.assertEqual(ndb.new_api.field_for(u'#series_index', 1), 9)
