示例#1
0
    def test_cached_webpage(self):
        """When we readable parse we cache the data in redis."""
        url = 'http://www.google.com/intl/en/about/index.html'
        hashed = generate_hash(url)
        resp = self.app.get(
            '/v',
            params={
                'url': url
            },
            status=302)

        # follow the redirect and we land at the actual page.
        resp = resp.follow()

        from bookie_parser.models import server
        # Make sure the data exists in redis
        self.assertTrue(server.get(hashed), 'The key is found.')

        # Now hit up our redis server and find what data we've stored.
        data = WebPageMgr.get(hash_id=hashed)

        self.assertEqual(
            url, data.url,
            "The url is stored in the root object")
        self.assertEqual(
            hashed, data.hash_id,
            "The hash is stored in the root object")
        self.assertTrue(
            data.request is not None,
            'The request is stored in the cache.')
        self.assertEqual(
            u'Google  - About Google',
            data.title)
        self.assertTrue(data.readable is not None)
示例#2
0
def redis_list(request):
    """List out the items in redis."""
    from bookie_parser.models import server
    urls = {}
    refs = []

    for hash_id in server.keys('*'):
        data = json.loads(server.get(hash_id))
        if 'reference' in data:
            refs.append(data['reference'])
        else:
            urls[data['hash_id']] = data

    return {
        'urls': urls,
        'refs': refs,
    }