Example #1
0
    def test_fill_redirects(self):
        cache = MongoCache(**self.OPTIONS)
        self._insert_foo_bar_doc(cache)
        self.assertEqual(cache.get('foo', 'lol')[1], 'content')

        # Now let's add a redirect
        try:
            cache.lock('foo', 'bar')
            cache.fill('foo', 'bar', None, ['bonjour'])
        finally:
            cache.release('foo', 'bar')
        self.assertEqual(cache.get('foo', 'bonjour')[1], 'content')
        self.assertEqual(cache.get('foo', 'lol')[1], 'content')
Example #2
0
 def test_fill_twice(self):
     cache = MongoCache(**self.OPTIONS)
     self._insert_foo_bar_doc(cache)
     self._insert_foo_bar_doc(cache, 'another_content')
     uri, content = cache.get('foo', 'bar')
     self.assertEqual(uri, 'bar')
     self.assertEqual(content, 'another_content')
Example #3
0
 def test_counters(self):
     cache = MongoCache(**self.OPTIONS)
     self._insert_foo_bar_doc(cache)
     document = self._get_document(cache, 'foo', 'bar')
     self.assertFalse('direct_hits' in document)
     self.assertFalse('redirects_hits' in document)
     self.assertEqual(
         cache.get('foo', 'bar'),
         ('bar', 'content')
     )
     document = self._get_document(cache, 'foo', 'bar')
     self.assertTrue(len(document['direct_hits']), 1)
     self.assertFalse('redirects_hits' in document)
     self.assertEqual(
         cache.get('foo', 'kikoo'),
         ('bar', 'content')
     )
     document = self._get_document(cache, 'foo', 'bar')
     self.assertTrue(len(document['direct_hits']), 1)
     self.assertTrue(len(document['redirect_hits']), 1)