'Test removal of many-(many,one) items'

def test_remove_items(self):

    cache = self.init_cache()
    tmap = cache.get_id_map(u'tags')
    self.assertEqual(cache.remove_items(u'tags', tmap), {1, 2})
    tmap = cache.get_id_map(u'#tags')
    t = {v: k for (k, v) in tmap.iteritems()}[u'My    Tag    Two']
    self.assertEqual(cache.remove_items(u'#tags', (t,)), {1, 2})
    smap = cache.get_id_map(u'series')
    self.assertEqual(cache.remove_items(u'series', smap), {1, 2})
    smap = cache.get_id_map(u'#series')
    s = {v: k for (k, v) in smap.iteritems()}[u'My    Series    Two']
    self.assertEqual(cache.remove_items(u'#series', (s,)), {1})
    for c in (cache, self.init_cache()):
        self.assertFalse(c.get_id_map(u'tags'))
        self.assertFalse(c.all_field_names(u'tags'))
        for bid in c.all_book_ids():
            self.assertFalse(c.field_for(u'tags', bid))
        self.assertEqual(len(c.get_id_map(u'#tags')), 1)
        self.assertEqual(c.all_field_names(u'#tags'), {u'My    Tag    One'})
        for bid in c.all_book_ids():
            self.assertIn(c.field_for(u'#tags', bid), ((), (u'My    Tag    One',)))
        for bid in (1, 2):
            self.assertEqual(c.field_for(u'series_index', bid), 1.0)
        self.assertFalse(c.get_id_map(u'series'))
        self.assertFalse(c.all_field_names(u'series'))
        for bid in c.all_book_ids():
            self.assertFalse(c.field_for(u'series', bid))
        self.assertEqual(c.field_for(u'series_index', 1), 1.0)
        self.assertEqual(c.all_field_names(u'#series'), {u'My    Series    One'})
        for bid in c.all_book_ids():
            self.assertIn(c.field_for(u'#series', bid), (None, u'My    Series    One'))
    cache = self.init_cache()
    cache.set_field(u'tags', {1: u'a,b,c', 2: u'b,a', 3: u'x,y,z'})
    cache.set_field(u'series', {1: u'a', 2: u'a', 3: u'b'})
    cache.set_field(u'series_index', {1: 8, 2: 9, 3: 3})
    (tmap, smap) = (cache.get_id_map(u'tags'), cache.get_id_map(u'series'))
    self.assertEqual(cache.remove_items(u'tags', tmap, restrict_to_book_ids=()), set())
    self.assertEqual(cache.remove_items(u'tags', tmap, restrict_to_book_ids={1}), {1})
    self.assertEqual(cache.remove_items(u'series', smap, restrict_to_book_ids=()), set())
    self.assertEqual(cache.remove_items(u'series', smap, restrict_to_book_ids=(1,)), {1})
    c2 = self.init_cache()
    for c in (cache, c2):
        self.assertEqual(c.field_for(u'tags', 1), ())
        self.assertEqual(c.field_for(u'tags', 2), (u'b', u'a'))
        self.assertNotIn(u'c', set(c.get_id_map(u'tags').itervalues()))
        self.assertEqual(c.field_for(u'series', 1), None)
        self.assertEqual(c.field_for(u'series', 2), u'a')
        self.assertEqual(c.field_for(u'series_index', 1), 1.0)
        self.assertEqual(c.field_for(u'series_index', 2), 9)
