'Test the reading of data from the database'

def test_read(self):

    cache = self.init_cache(self.library_path)
    tests = {3: {u'title': u'Unknown', u'sort': u'Unknown', u'authors': (u'Unknown',), u'author_sort': u'Unknown', u'series': None, u'series_index': 1.0, u'rating': None, u'tags': (), u'formats': (), u'identifiers': {}, u'timestamp': datetime.datetime(2011, 9, 7, 19, 54, 41, tzinfo=utc_tz), u'pubdate': datetime.datetime(2011, 9, 7, 19, 54, 41, tzinfo=utc_tz), u'last_modified': datetime.datetime(2011, 9, 7, 19, 54, 41, tzinfo=utc_tz), u'publisher': None, u'languages': (), u'comments': None, u'#enum': None, u'#authors': (), u'#date': None, u'#rating': None, u'#series': None, u'#series_index': None, u'#tags': (), u'#yesno': None, u'#comments': None, u'size': None}, 2: {u'title': u'Title    One', u'sort': u'One', u'authors': (u'Author    One',), u'author_sort': u'One,    Author', u'series': u'A    Series    One', u'series_index': 1.0, u'tags': (u'Tag    One', u'Tag    Two'), u'formats': (u'FMT1',), u'rating': 4.0, u'identifiers': {u'test': u'one'}, u'timestamp': datetime.datetime(2011, 9, 5, 21, 6, tzinfo=utc_tz), u'pubdate': datetime.datetime(2011, 9, 5, 21, 6, tzinfo=utc_tz), u'publisher': u'Publisher    One', u'languages': (u'eng',), u'comments': u'<p>Comments    One</p>', u'#enum': u'One', u'#authors': (u'Custom    One', u'Custom    Two'), u'#date': datetime.datetime(2011, 9, 5, 6, 0, tzinfo=utc_tz), u'#rating': 2.0, u'#series': u'My    Series    One', u'#series_index': 1.0, u'#tags': (u'My    Tag    One', u'My    Tag    Two'), u'#yesno': True, u'#comments': u'<div>My    Comments    One<p></p></div>', u'size': 9}, 1: {u'title': u'Title    Two', u'sort': u'Title    Two', u'authors': (u'Author    Two', u'Author    One'), u'author_sort': u'Two,    Author    &    One,    Author', u'series': u'A    Series    One', u'series_index': 2.0, u'rating': 6.0, u'tags': (u'Tag    One', u'News'), u'formats': (u'FMT1', u'FMT2'), u'identifiers': {u'test': u'two'}, u'timestamp': datetime.datetime(2011, 9, 6, 6, 0, tzinfo=utc_tz), u'pubdate': datetime.datetime(2011, 8, 5, 6, 0, tzinfo=utc_tz), u'publisher': u'Publisher    Two', u'languages': (u'deu',), u'comments': u'<p>Comments    Two</p>', u'#enum': u'Two', u'#authors': (u'My    Author    Two',), u'#date': datetime.datetime(2011, 9, 1, 6, 0, tzinfo=utc_tz), u'#rating': 4.0, u'#series': u'My    Series    Two', u'#series_index': 3.0, u'#tags': (u'My    Tag    Two',), u'#yesno': False, u'#comments': u'<div>My    Comments    Two<p></p></div>', u'size': 9}}
    for (book_id, test) in tests.iteritems():
        for (field, expected_val) in test.iteritems():
            val = cache.field_for(field, book_id)
            if (isinstance(val, tuple) and (u'authors' not in field) and (u'languages' not in field)):
                (val, expected_val) = (set(val), set(expected_val))
            self.assertEqual(expected_val, val, (u'Book    id:    %d    Field:    %s    failed:    %r    !=    %r' % (book_id, field, expected_val, val)))
