def test_remove_items(self): # {{{ ' Test removal of many-(many,one) items ' cache = self.init_cache() tmap = cache.get_id_map('tags') self.assertEqual(cache.remove_items('tags', tmap), {1, 2}) tmap = cache.get_id_map('#tags') t = {v:k for k, v in iteritems(tmap)}['My Tag Two'] self.assertEqual(cache.remove_items('#tags', (t,)), {1, 2}) smap = cache.get_id_map('series') self.assertEqual(cache.remove_items('series', smap), {1, 2}) smap = cache.get_id_map('#series') s = {v:k for k, v in iteritems(smap)}['My Series Two'] self.assertEqual(cache.remove_items('#series', (s,)), {1}) for c in (cache, self.init_cache()): self.assertFalse(c.get_id_map('tags')) self.assertFalse(c.all_field_names('tags')) for bid in c.all_book_ids(): self.assertFalse(c.field_for('tags', bid)) self.assertEqual(len(c.get_id_map('#tags')), 1) self.assertEqual(c.all_field_names('#tags'), {'My Tag One'}) for bid in c.all_book_ids(): self.assertIn(c.field_for('#tags', bid), ((), ('My Tag One',))) for bid in (1, 2): self.assertEqual(c.field_for('series_index', bid), 1.0) self.assertFalse(c.get_id_map('series')) self.assertFalse(c.all_field_names('series')) for bid in c.all_book_ids(): self.assertFalse(c.field_for('series', bid)) self.assertEqual(c.field_for('series_index', 1), 1.0) self.assertEqual(c.all_field_names('#series'), {'My Series One'}) for bid in c.all_book_ids(): self.assertIn(c.field_for('#series', bid), (None, 'My Series One')) # Now test with restriction cache = self.init_cache() cache.set_field('tags', {1:'a,b,c', 2:'b,a', 3:'x,y,z'}) cache.set_field('series', {1:'a', 2:'a', 3:'b'}) cache.set_field('series_index', {1:8, 2:9, 3:3}) tmap, smap = cache.get_id_map('tags'), cache.get_id_map('series') self.assertEqual(cache.remove_items('tags', tmap, restrict_to_book_ids=()), set()) self.assertEqual(cache.remove_items('tags', tmap, restrict_to_book_ids={1}), {1}) self.assertEqual(cache.remove_items('series', smap, restrict_to_book_ids=()), set()) self.assertEqual(cache.remove_items('series', smap, restrict_to_book_ids=(1,)), {1}) c2 = self.init_cache() for c in (cache, c2): self.assertEqual(c.field_for('tags', 1), ()) self.assertEqual(c.field_for('tags', 2), ('b', 'a')) self.assertNotIn('c', set(itervalues(c.get_id_map('tags')))) self.assertEqual(c.field_for('series', 1), None) self.assertEqual(c.field_for('series', 2), 'a') self.assertEqual(c.field_for('series_index', 1), 1.0) self.assertEqual(c.field_for('series_index', 2), 9)
def test_remove_items(self): # {{{ ' Test removal of many-(many,one) items ' cache = self.init_cache() tmap = cache.get_id_map('tags') self.assertEqual(cache.remove_items('tags', tmap), {1, 2}) tmap = cache.get_id_map('#tags') t = {v:k for k, v in tmap.iteritems()}['My Tag Two'] self.assertEqual(cache.remove_items('#tags', (t,)), {1, 2}) smap = cache.get_id_map('series') self.assertEqual(cache.remove_items('series', smap), {1, 2}) smap = cache.get_id_map('#series') s = {v:k for k, v in smap.iteritems()}['My Series Two'] self.assertEqual(cache.remove_items('#series', (s,)), {1}) for c in (cache, self.init_cache()): self.assertFalse(c.get_id_map('tags')) self.assertFalse(c.all_field_names('tags')) for bid in c.all_book_ids(): self.assertFalse(c.field_for('tags', bid)) self.assertEqual(len(c.get_id_map('#tags')), 1) self.assertEqual(c.all_field_names('#tags'), {'My Tag One'}) for bid in c.all_book_ids(): self.assertIn(c.field_for('#tags', bid), ((), ('My Tag One',))) for bid in (1, 2): self.assertEqual(c.field_for('series_index', bid), 1.0) self.assertFalse(c.get_id_map('series')) self.assertFalse(c.all_field_names('series')) for bid in c.all_book_ids(): self.assertFalse(c.field_for('series', bid)) self.assertEqual(c.field_for('series_index', 1), 1.0) self.assertEqual(c.all_field_names('#series'), {'My Series One'}) for bid in c.all_book_ids(): self.assertIn(c.field_for('#series', bid), (None, 'My Series One')) # Now test with restriction cache = self.init_cache() cache.set_field('tags', {1:'a,b,c', 2:'b,a', 3:'x,y,z'}) cache.set_field('series', {1:'a', 2:'a', 3:'b'}) cache.set_field('series_index', {1:8, 2:9, 3:3}) tmap, smap = cache.get_id_map('tags'), cache.get_id_map('series') self.assertEqual(cache.remove_items('tags', tmap, restrict_to_book_ids=()), set()) self.assertEqual(cache.remove_items('tags', tmap, restrict_to_book_ids={1}), {1}) self.assertEqual(cache.remove_items('series', smap, restrict_to_book_ids=()), set()) self.assertEqual(cache.remove_items('series', smap, restrict_to_book_ids=(1,)), {1}) c2 = self.init_cache() for c in (cache, c2): self.assertEqual(c.field_for('tags', 1), ()) self.assertEqual(c.field_for('tags', 2), ('b', 'a')) self.assertNotIn('c', set(c.get_id_map('tags').itervalues())) self.assertEqual(c.field_for('series', 1), None) self.assertEqual(c.field_for('series', 2), 'a') self.assertEqual(c.field_for('series_index', 1), 1.0) self.assertEqual(c.field_for('series_index', 2), 9)
def test_remove_items(self): # {{{ ' Test removal of many-(many,one) items ' cache = self.init_cache() tmap = cache.get_id_map('tags') self.assertEqual(cache.remove_items('tags', tmap), {1, 2}) tmap = cache.get_id_map('#tags') t = {v: k for k, v in tmap.iteritems()}['My Tag Two'] self.assertEqual(cache.remove_items('#tags', (t, )), {1, 2}) smap = cache.get_id_map('series') self.assertEqual(cache.remove_items('series', smap), {1, 2}) smap = cache.get_id_map('#series') s = {v: k for k, v in smap.iteritems()}['My Series Two'] self.assertEqual(cache.remove_items('#series', (s, )), {1}) for c in (cache, self.init_cache()): self.assertFalse(c.get_id_map('tags')) self.assertFalse(c.all_field_names('tags')) for bid in c.all_book_ids(): self.assertFalse(c.field_for('tags', bid)) self.assertEqual(len(c.get_id_map('#tags')), 1) self.assertEqual(c.all_field_names('#tags'), {'My Tag One'}) for bid in c.all_book_ids(): self.assertIn(c.field_for('#tags', bid), ((), ('My Tag One', ))) for bid in (1, 2): self.assertEqual(c.field_for('series_index', bid), 1.0) self.assertFalse(c.get_id_map('series')) self.assertFalse(c.all_field_names('series')) for bid in c.all_book_ids(): self.assertFalse(c.field_for('series', bid)) self.assertEqual(c.field_for('series_index', 1), 1.0) self.assertEqual(c.all_field_names('#series'), {'My Series One'}) for bid in c.all_book_ids(): self.assertIn(c.field_for('#series', bid), (None, 'My Series One'))
def test_remove_items(self): # {{{ ' Test removal of many-(many,one) items ' cache = self.init_cache() tmap = cache.get_id_map('tags') self.assertEqual(cache.remove_items('tags', tmap), {1, 2}) tmap = cache.get_id_map('#tags') t = {v:k for k, v in tmap.iteritems()}['My Tag Two'] self.assertEqual(cache.remove_items('#tags', (t,)), {1, 2}) smap = cache.get_id_map('series') self.assertEqual(cache.remove_items('series', smap), {1, 2}) smap = cache.get_id_map('#series') s = {v:k for k, v in smap.iteritems()}['My Series Two'] self.assertEqual(cache.remove_items('#series', (s,)), {1}) for c in (cache, self.init_cache()): self.assertFalse(c.get_id_map('tags')) self.assertFalse(c.all_field_names('tags')) for bid in c.all_book_ids(): self.assertFalse(c.field_for('tags', bid)) self.assertEqual(len(c.get_id_map('#tags')), 1) self.assertEqual(c.all_field_names('#tags'), {'My Tag One'}) for bid in c.all_book_ids(): self.assertIn(c.field_for('#tags', bid), ((), ('My Tag One',))) for bid in (1, 2): self.assertEqual(c.field_for('series_index', bid), 1.0) self.assertFalse(c.get_id_map('series')) self.assertFalse(c.all_field_names('series')) for bid in c.all_book_ids(): self.assertFalse(c.field_for('series', bid)) self.assertEqual(c.field_for('series_index', 1), 1.0) self.assertEqual(c.all_field_names('#series'), {'My Series One'}) for bid in c.all_book_ids(): self.assertIn(c.field_for('#series', bid), (None, 'My Series One'))
def test_rename_items(self): # {{{ ' Test renaming of many-(many,one) items ' cl = self.cloned_library cache = self.init_cache(cl) # Check that renaming authors updates author sort and path a = {v:k for k, v in cache.get_id_map('authors').iteritems()}['Unknown'] self.assertEqual(cache.rename_items('authors', {a:'New Author'})[0], {3}) a = {v:k for k, v in cache.get_id_map('authors').iteritems()}['Author One'] self.assertEqual(cache.rename_items('authors', {a:'Author Two'})[0], {1, 2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('authors'), {'New Author', 'Author Two'}) self.assertEqual(c.field_for('author_sort', 3), 'Author, New') self.assertIn('New Author/', c.field_for('path', 3)) self.assertEqual(c.field_for('authors', 1), ('Author Two',)) self.assertEqual(c.field_for('author_sort', 1), 'Two, Author') t = {v:k for k, v in cache.get_id_map('tags').iteritems()}['Tag One'] # Test case change self.assertEqual(cache.rename_items('tags', {t:'tag one'}), ({1, 2}, {t:t})) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('tags'), {'tag one', 'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 1)), {'tag one', 'News'}) self.assertEqual(set(c.field_for('tags', 2)), {'tag one', 'Tag Two'}) # Test new name self.assertEqual(cache.rename_items('tags', {t:'t1'})[0], {1,2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('tags'), {'t1', 'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 1)), {'t1', 'News'}) self.assertEqual(set(c.field_for('tags', 2)), {'t1', 'Tag Two'}) # Test rename to existing self.assertEqual(cache.rename_items('tags', {t:'Tag Two'})[0], {1,2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('tags'), {'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 1)), {'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 2)), {'Tag Two'}) # Test on a custom column t = {v:k for k, v in cache.get_id_map('#tags').iteritems()}['My Tag One'] self.assertEqual(cache.rename_items('#tags', {t:'My Tag Two'})[0], {2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('#tags'), {'My Tag Two'}) self.assertEqual(set(c.field_for('#tags', 2)), {'My Tag Two'}) # Test a Many-one field s = {v:k for k, v in cache.get_id_map('series').iteritems()}['A Series One'] # Test case change self.assertEqual(cache.rename_items('series', {s:'a series one'}), ({1, 2}, {s:s})) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('series'), {'a series one'}) self.assertEqual(c.field_for('series', 1), 'a series one') self.assertEqual(c.field_for('series_index', 1), 2.0) # Test new name self.assertEqual(cache.rename_items('series', {s:'series'})[0], {1, 2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('series'), {'series'}) self.assertEqual(c.field_for('series', 1), 'series') self.assertEqual(c.field_for('series', 2), 'series') self.assertEqual(c.field_for('series_index', 1), 2.0) s = {v:k for k, v in cache.get_id_map('#series').iteritems()}['My Series One'] # Test custom column with rename to existing self.assertEqual(cache.rename_items('#series', {s:'My Series Two'})[0], {2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('#series'), {'My Series Two'}) self.assertEqual(c.field_for('#series', 2), 'My Series Two') self.assertEqual(c.field_for('#series_index', 1), 3.0) self.assertEqual(c.field_for('#series_index', 2), 4.0) # Test renaming many-many items to multiple items cache = self.init_cache(self.cloned_library) t = {v:k for k, v in cache.get_id_map('tags').iteritems()}['Tag One'] affected_books, id_map = cache.rename_items('tags', {t:'Something, Else, Entirely'}) self.assertEqual({1, 2}, affected_books) tmap = cache.get_id_map('tags') self.assertEqual('Something', tmap[id_map[t]]) self.assertEqual(1, len(id_map)) f1, f2 = cache.field_for('tags', 1), cache.field_for('tags', 2) for f in (f1, f2): for t in 'Something,Else,Entirely'.split(','): self.assertIn(t, f) self.assertNotIn('Tag One', f)
def test_rename_items(self): # {{{ ' Test renaming of many-(many,one) items ' cl = self.cloned_library cache = self.init_cache(cl) # Check that renaming authors updates author sort and path a = {v:k for k, v in iteritems(cache.get_id_map('authors'))}['Unknown'] self.assertEqual(cache.rename_items('authors', {a:'New Author'})[0], {3}) a = {v:k for k, v in iteritems(cache.get_id_map('authors'))}['Author One'] self.assertEqual(cache.rename_items('authors', {a:'Author Two'})[0], {1, 2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('authors'), {'New Author', 'Author Two'}) self.assertEqual(c.field_for('author_sort', 3), 'Author, New') self.assertIn('New Author/', c.field_for('path', 3)) self.assertEqual(c.field_for('authors', 1), ('Author Two',)) self.assertEqual(c.field_for('author_sort', 1), 'Two, Author') t = {v:k for k, v in iteritems(cache.get_id_map('tags'))}['Tag One'] # Test case change self.assertEqual(cache.rename_items('tags', {t:'tag one'}), ({1, 2}, {t:t})) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('tags'), {'tag one', 'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 1)), {'tag one', 'News'}) self.assertEqual(set(c.field_for('tags', 2)), {'tag one', 'Tag Two'}) # Test new name self.assertEqual(cache.rename_items('tags', {t:'t1'})[0], {1,2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('tags'), {'t1', 'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 1)), {'t1', 'News'}) self.assertEqual(set(c.field_for('tags', 2)), {'t1', 'Tag Two'}) # Test rename to existing self.assertEqual(cache.rename_items('tags', {t:'Tag Two'})[0], {1,2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('tags'), {'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 1)), {'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 2)), {'Tag Two'}) # Test on a custom column t = {v:k for k, v in iteritems(cache.get_id_map('#tags'))}['My Tag One'] self.assertEqual(cache.rename_items('#tags', {t:'My Tag Two'})[0], {2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('#tags'), {'My Tag Two'}) self.assertEqual(set(c.field_for('#tags', 2)), {'My Tag Two'}) # Test a Many-one field s = {v:k for k, v in iteritems(cache.get_id_map('series'))}['A Series One'] # Test case change self.assertEqual(cache.rename_items('series', {s:'a series one'}), ({1, 2}, {s:s})) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('series'), {'a series one'}) self.assertEqual(c.field_for('series', 1), 'a series one') self.assertEqual(c.field_for('series_index', 1), 2.0) # Test new name self.assertEqual(cache.rename_items('series', {s:'series'})[0], {1, 2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('series'), {'series'}) self.assertEqual(c.field_for('series', 1), 'series') self.assertEqual(c.field_for('series', 2), 'series') self.assertEqual(c.field_for('series_index', 1), 2.0) s = {v:k for k, v in iteritems(cache.get_id_map('#series'))}['My Series One'] # Test custom column with rename to existing self.assertEqual(cache.rename_items('#series', {s:'My Series Two'})[0], {2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('#series'), {'My Series Two'}) self.assertEqual(c.field_for('#series', 2), 'My Series Two') self.assertEqual(c.field_for('#series_index', 1), 3.0) self.assertEqual(c.field_for('#series_index', 2), 4.0) # Test renaming many-many items to multiple items cache = self.init_cache(self.cloned_library) t = {v:k for k, v in iteritems(cache.get_id_map('tags'))}['Tag One'] affected_books, id_map = cache.rename_items('tags', {t:'Something, Else, Entirely'}) self.assertEqual({1, 2}, affected_books) tmap = cache.get_id_map('tags') self.assertEqual('Something', tmap[id_map[t]]) self.assertEqual(1, len(id_map)) f1, f2 = cache.field_for('tags', 1), cache.field_for('tags', 2) for f in (f1, f2): for t in 'Something,Else,Entirely'.split(','): self.assertIn(t, f) self.assertNotIn('Tag One', f) # Test with restriction cache = self.init_cache() cache.set_field('tags', {1:'a,b,c', 2:'x,y,z', 3:'a,x,z'}) tmap = {v:k for k, v in iteritems(cache.get_id_map('tags'))} self.assertEqual(cache.rename_items('tags', {tmap['a']:'r'}, restrict_to_book_ids=()), (set(), {})) self.assertEqual(cache.rename_items('tags', {tmap['a']:'r', tmap['b']:'q'}, restrict_to_book_ids=(1,))[0], {1}) self.assertEqual(cache.rename_items('tags', {tmap['x']:'X'}, restrict_to_book_ids=(2,))[0], {2}) c2 = self.init_cache() for c in (cache, c2): self.assertEqual(c.field_for('tags', 1), ('r', 'q', 'c')) self.assertEqual(c.field_for('tags', 2), ('X', 'y', 'z')) self.assertEqual(c.field_for('tags', 3), ('a', 'X', 'z'))
def test_rename_items(self): # {{{ ' Test renaming of many-(many,one) items ' cl = self.cloned_library cache = self.init_cache(cl) # Check that renaming authors updates author sort and path a = {v:k for k, v in cache.get_id_map('authors').iteritems()}['Unknown'] self.assertEqual(cache.rename_items('authors', {a:'New Author'})[0], {3}) a = {v:k for k, v in cache.get_id_map('authors').iteritems()}['Author One'] self.assertEqual(cache.rename_items('authors', {a:'Author Two'})[0], {1, 2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('authors'), {'New Author', 'Author Two'}) self.assertEqual(c.field_for('author_sort', 3), 'Author, New') self.assertIn('New Author/', c.field_for('path', 3)) self.assertEqual(c.field_for('authors', 1), ('Author Two',)) self.assertEqual(c.field_for('author_sort', 1), 'Two, Author') t = {v:k for k, v in cache.get_id_map('tags').iteritems()}['Tag One'] # Test case change self.assertEqual(cache.rename_items('tags', {t:'tag one'}), ({1, 2}, {t:t})) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('tags'), {'tag one', 'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 1)), {'tag one', 'News'}) self.assertEqual(set(c.field_for('tags', 2)), {'tag one', 'Tag Two'}) # Test new name self.assertEqual(cache.rename_items('tags', {t:'t1'})[0], {1,2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('tags'), {'t1', 'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 1)), {'t1', 'News'}) self.assertEqual(set(c.field_for('tags', 2)), {'t1', 'Tag Two'}) # Test rename to existing self.assertEqual(cache.rename_items('tags', {t:'Tag Two'})[0], {1,2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('tags'), {'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 1)), {'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 2)), {'Tag Two'}) # Test on a custom column t = {v:k for k, v in cache.get_id_map('#tags').iteritems()}['My Tag One'] self.assertEqual(cache.rename_items('#tags', {t:'My Tag Two'})[0], {2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('#tags'), {'My Tag Two'}) self.assertEqual(set(c.field_for('#tags', 2)), {'My Tag Two'}) # Test a Many-one field s = {v:k for k, v in cache.get_id_map('series').iteritems()}['A Series One'] # Test case change self.assertEqual(cache.rename_items('series', {s:'a series one'}), ({1, 2}, {s:s})) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('series'), {'a series one'}) self.assertEqual(c.field_for('series', 1), 'a series one') self.assertEqual(c.field_for('series_index', 1), 2.0) # Test new name self.assertEqual(cache.rename_items('series', {s:'series'})[0], {1, 2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('series'), {'series'}) self.assertEqual(c.field_for('series', 1), 'series') self.assertEqual(c.field_for('series', 2), 'series') self.assertEqual(c.field_for('series_index', 1), 2.0) s = {v:k for k, v in cache.get_id_map('#series').iteritems()}['My Series One'] # Test custom column with rename to existing self.assertEqual(cache.rename_items('#series', {s:'My Series Two'})[0], {2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('#series'), {'My Series Two'}) self.assertEqual(c.field_for('#series', 2), 'My Series Two') self.assertEqual(c.field_for('#series_index', 1), 3.0) self.assertEqual(c.field_for('#series_index', 2), 4.0)
def test_rename_items(self): # {{{ ' Test renaming of many-(many,one) items ' cl = self.cloned_library cache = self.init_cache(cl) # Check that renaming authors updates author sort and path a = {v: k for k, v in cache.get_id_map('authors').iteritems()}['Unknown'] self.assertEqual( cache.rename_items('authors', {a: 'New Author'})[0], {3}) a = {v: k for k, v in cache.get_id_map('authors').iteritems()}['Author One'] self.assertEqual( cache.rename_items('authors', {a: 'Author Two'})[0], {1, 2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('authors'), {'New Author', 'Author Two'}) self.assertEqual(c.field_for('author_sort', 3), 'Author, New') self.assertIn('New Author/', c.field_for('path', 3)) self.assertEqual(c.field_for('authors', 1), ('Author Two', )) self.assertEqual(c.field_for('author_sort', 1), 'Two, Author') t = {v: k for k, v in cache.get_id_map('tags').iteritems()}['Tag One'] # Test case change self.assertEqual(cache.rename_items('tags', {t: 'tag one'}), ({1, 2}, { t: t })) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('tags'), {'tag one', 'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 1)), {'tag one', 'News'}) self.assertEqual(set(c.field_for('tags', 2)), {'tag one', 'Tag Two'}) # Test new name self.assertEqual(cache.rename_items('tags', {t: 't1'})[0], {1, 2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('tags'), {'t1', 'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 1)), {'t1', 'News'}) self.assertEqual(set(c.field_for('tags', 2)), {'t1', 'Tag Two'}) # Test rename to existing self.assertEqual(cache.rename_items('tags', {t: 'Tag Two'})[0], {1, 2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('tags'), {'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 1)), {'Tag Two', 'News'}) self.assertEqual(set(c.field_for('tags', 2)), {'Tag Two'}) # Test on a custom column t = {v: k for k, v in cache.get_id_map('#tags').iteritems()}['My Tag One'] self.assertEqual( cache.rename_items('#tags', {t: 'My Tag Two'})[0], {2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('#tags'), {'My Tag Two'}) self.assertEqual(set(c.field_for('#tags', 2)), {'My Tag Two'}) # Test a Many-one field s = {v: k for k, v in cache.get_id_map('series').iteritems() }['A Series One'] # Test case change self.assertEqual(cache.rename_items('series', {s: 'a series one'}), ({1, 2}, { s: s })) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('series'), {'a series one'}) self.assertEqual(c.field_for('series', 1), 'a series one') self.assertEqual(c.field_for('series_index', 1), 2.0) # Test new name self.assertEqual( cache.rename_items('series', {s: 'series'})[0], {1, 2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('series'), {'series'}) self.assertEqual(c.field_for('series', 1), 'series') self.assertEqual(c.field_for('series', 2), 'series') self.assertEqual(c.field_for('series_index', 1), 2.0) s = {v: k for k, v in cache.get_id_map('#series').iteritems() }['My Series One'] # Test custom column with rename to existing self.assertEqual( cache.rename_items('#series', {s: 'My Series Two'})[0], {2}) for c in (cache, self.init_cache(cl)): self.assertEqual(c.all_field_names('#series'), {'My Series Two'}) self.assertEqual(c.field_for('#series', 2), 'My Series Two') self.assertEqual(c.field_for('#series_index', 1), 3.0) self.assertEqual(c.field_for('#series_index', 2), 4.0)