'Test that the composite field cache is properly invalidated on writes'

def test_composite_cache(self):

    cache = self.init_cache()
    cache.create_custom_column(u'tc', u'TC', u'composite', False, display={u'composite_template': u'{title}    {author_sort}    {title_sort}    {formats}    {tags}    {series}    {series_index}'})
    cache = self.init_cache()
    def test_invalidate():
        c = self.init_cache()
        for bid in cache.all_book_ids():
            self.assertEqual(cache.field_for(u'#tc', bid), c.field_for(u'#tc', bid))
    cache.set_field(u'title', {1: u'xx', 3: u'yy'})
    test_invalidate()
    cache.set_field(u'series_index', {1: 9, 3: 11})
    test_invalidate()
    cache.rename_items(u'tags', {cache.get_item_id(u'tags', u'Tag    One'): u'xxx', cache.get_item_id(u'tags', u'News'): u'news'})
    test_invalidate()
    cache.remove_items(u'tags', (cache.get_item_id(u'tags', u'news'),))
    test_invalidate()
    cache.set_sort_for_authors({cache.get_item_id(u'authors', u'Author    One'): u'meow'})
    test_invalidate()
    cache.remove_formats({1: {u'FMT1'}})
    test_invalidate()
    cache.add_format(1, u'ADD', BytesIO('xxxx'))
    test_invalidate()
