示例#1
0
 def test_fill_after_invalid_status(self):
     cache = MongoCache(**self.OPTIONS)
     cache._lock('foo', 'bar', -42)
     with self.assertRaises(Exception) as exc:
         cache.fill('foo', 'bar', 'content')
     self.assertEqual(
         exc.exception.message,
         'Could not set document content: foo/bar'
     )
示例#2
0
 def test_indices(self):
     cache = MongoCache(**self.OPTIONS)
     for op in ['op1', 'op2']:
         for key in ['key1', 'key2']:
             try:
                 cache.lock(op, key)
                 cache.fill(op, key, 'content')
             finally:
                 cache.release(op, key)
示例#3
0
 def test_fill_existing_resource(self):
     cache = MongoCache(**self.OPTIONS)
     self.collection.insert({
         'operation': 'foo',
         'hash': hashlib.sha256('bar'.decode('utf8')).hexdigest(),
         'status': MongoCache.CACHE_STATUS,
         'uri': 'bar',
     })
     with self.assertRaises(ResourceAlreadyExists) as exc:
         cache.fill('foo', 'bar', 'some_content', [])
     self.assertEqual(exc.exception.operation, 'foo')
     self.assertEqual(exc.exception.uri, 'bar')
示例#4
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')
示例#5
0
 def test_fill_with_multiple_match(self):
     """Test fill method when there are 2 matching documents"""
     # indices need to be deactivated...
     cache = MongoCache(**self.OPTIONS)
     cache._collection.drop_indexes()
     uri = 'bar'
     for _ in range(2):
         cache._collection.insert({
             'hash': hashlib.sha256(uri.decode('utf8')).hexdigest(),
             'operation': 'foo',
             'status': MongoCache.CACHE_STATUS
         })
     with self.assertRaises(Exception) as exc:
         cache.fill('foo', 'bar', 'content')
     self.assertEqual(
         exc.exception.message,
         'Unexpected matched results while filling document: ' +
         'foo/bar, matched: 2'
     )
示例#6
0
 def test_fill_unknown_resource(self):
     cache = MongoCache(**self.OPTIONS)
     with self.assertRaises(UnknownResource) as exc:
         cache.fill('foo', 'bar', 'some_content', [])
     self.assertEqual(exc.exception.operation, 'foo')
     self.assertEqual(exc.exception.uri, 'bar')