def test_annotations(self):
        # find annotations associated with a volume, optionally filtered
        # by user

        User = get_user_model()
        testuser = User.objects.create(username='tester')
        testadmin = User.objects.create(username='super', is_superuser=True)

        mockapi = Mock()
        vol = Volume(mockapi, 'vol:1')

        # create annotations to test finding
        p1 = Annotation.objects.create(user=testuser, text='testuser p1',
            uri=reverse('books:page', kwargs={'vol_pid': vol.pid, 'pid': 'p:1'}),
            volume_uri=vol.absolute_url)
        p2 = Annotation.objects.create(user=testuser, text='testuser p2',
            uri=reverse('books:page', kwargs={'vol_pid': vol.pid, 'pid': 'p:2'}),
            volume_uri=vol.absolute_url)
        p3 = Annotation.objects.create(user=testuser, text='testuser p3',
            uri=reverse('books:page', kwargs={'vol_pid': vol.pid, 'pid': 'p:3'}),
            volume_uri=vol.absolute_url)
        v2p1 = Annotation.objects.create(user=testuser, text='testuser vol2 p1',
            uri=reverse('books:page', kwargs={'vol_pid': 'vol:2', 'pid': 'p:1'}),
            volume_uri='http://example.com/books/vol:2/')
        sup2 = Annotation.objects.create(user=testadmin, text='testsuper p2',
            uri=reverse('books:page', kwargs={'vol_pid': vol.pid, 'pid': 'p:2'}),
            volume_uri=vol.absolute_url)
        annotations = vol.annotations()
        self.assertEqual(4, annotations.count())
        self.assert_(v2p1 not in annotations)

        # filter by user
        annotations = vol.annotations().visible_to(testuser)
        self.assertEqual(3, annotations.count())
        self.assert_(sup2 not in annotations)

        annotations = vol.annotations().visible_to(testadmin)
        self.assertEqual(4, annotations.count())
        self.assert_(sup2 in annotations)

        # annotation counts per page
        annotation_count = vol.page_annotation_count()
        self.assertEqual(1, annotation_count[p1.uri])
        self.assertEqual(2, annotation_count[p2.uri])
        self.assertEqual(1, annotation_count[p3.uri])
        # by user
        annotation_count = vol.page_annotation_count(testuser)
        self.assertEqual(1, annotation_count[p2.uri])
        annotation_count = vol.page_annotation_count(testadmin)
        self.assertEqual(2, annotation_count[p2.uri])

        # total for a volume
        self.assertEqual(4, vol.annotation_count())
        self.assertEqual(3, vol.annotation_count(testuser))
        self.assertEqual(4, vol.annotation_count(testadmin))

        # total for all volumes
        totals = Volume.volume_annotation_count()
        self.assertEqual(1, totals['http://example.com/books/vol:2/'])
        self.assertEqual(4, totals[vol.absolute_url])
        totals = Volume.volume_annotation_count(testuser)
        self.assertEqual(3, totals[vol.absolute_url])