def test_recent_filtering(self):
        def _get_recent(data):
            recent = set()
            for link in data['recent_links']:
                recent.add(link['url'])
            return recent

        username = 'none'
        req = get_request_with_user(username)
        user = get_user_model(req)

        u1 = 'http://example.com?q=1'
        u2 = 'http://example.com?q=2'

        v1 = VisitedLinkNew.objects.create(user=user, url=u1)
        self.assertTrue(get_recent_link_by_id(req, v1.pk))

        v2 = VisitedLinkNew.objects.create(user=user, url=u2)

        data = get_quicklink_data(req)
        recent = _get_recent(data)

        self.assertEquals(len(recent), 2)
        self.assertTrue(u1 in recent)
        self.assertTrue(u2 in recent)

        plink = PopularLink.objects.create(url=u2)
        self.assertTrue(get_popular_link_by_id(plink.pk))
        self.assertIsNotNone(plink.json_data())
        self.assertIsNotNone(str(plink))

        data = get_quicklink_data(req)
        recent = _get_recent(data)

        self.assertEquals(len(recent), 1)
        self.assertTrue(u1 in recent)

        CustomLink.objects.create(user=user, url=u1)
        data = get_quicklink_data(req)
        recent = _get_recent(data)

        self.assertEquals(len(recent), 0)

        for i in range(10):
            VisitedLinkNew.objects.create(user=user,
                                          url="http://example.com?q=%s" % i)

        data = get_quicklink_data(req)
        recent = _get_recent(data)

        self.assertEquals(len(recent), 5)