예제 #1
0
 def test_deleting_cache_entries(self):
     # Because this operation is a no-op, we just check we can call the
     # __del__ method without an error.
     cache = img.ImageCache(cache_root='/tmp')
     request = img.ImageRequest('id1', 'full', 'full', '0', 'default',
                                'jpg')
     del cache[request]
예제 #2
0
    def test_missing_entry_is_keyerror(self):
        cache = img.ImageCache(cache_root='/tmp')
        request = img.ImageRequest('id1', 'full', 'full', '0', 'default',
                                   'jpg')

        with self.assertRaises(KeyError):
            cache[request]
예제 #3
0
    def __init__(self, app_configs={}):
        '''The WSGI Application.
        Args:
            app_configs ({}):
                A dictionary of dictionaries that represents the loris.conf
                file.
        '''
        self.app_configs = app_configs
        self.logger = configure_logging(app_configs['logging'])
        self.logger.debug('Loris initialized with these settings:')
        [self.logger.debug('%s.%s=%s', key, sub_key, self.app_configs[key][sub_key])
            for key in self.app_configs for sub_key in self.app_configs[key]]

        # make the loris.Loris configs attrs for easier access
        _loris_config = self.app_configs['loris.Loris']
        self.tmp_dp = _loris_config['tmp_dp']
        self.www_dp = _loris_config['www_dp']
        self.enable_caching = _loris_config['enable_caching']
        self.redirect_canonical_image_request = _loris_config['redirect_canonical_image_request']
        self.redirect_id_slash_to_info = _loris_config['redirect_id_slash_to_info']
        self.proxy_path = _loris_config.get('proxy_path', None)
        self.cors_regex = _loris_config.get('cors_regex', None)
        if self.cors_regex:
            self.cors_regex = re.compile(self.cors_regex)

        self.transformers = self._load_transformers()
        self.resolver = self._load_resolver()
        self.authorizer = self._load_authorizer()
        self.max_size_above_full = _loris_config.get('max_size_above_full', 200)

        if self.enable_caching:
            self.info_cache = InfoCache(self.app_configs['img_info.InfoCache']['cache_dp'])
            cache_dp = self.app_configs['img.ImageCache']['cache_dp']
            self.img_cache = img.ImageCache(cache_dp)
예제 #4
0
    def test_missing_entry_gets_none(self):
        with tempfile.TemporaryDirectory() as tmp:
            cache = img.ImageCache(cache_root=tmp)
            request = img.ImageRequest('id1', 'full', 'full', '0', 'default',
                                       'jpg')

            self.assertIsNone(cache.get(request))
예제 #5
0
 def test_deleting_cache_entries(self):
     # Because this operation is a no-op, we just check we can call the
     # __del__ method without an error.
     with tempfile.TemporaryDirectory() as tmp:
         cache = img.ImageCache(cache_root=tmp)
         request = img.ImageRequest('id1', 'full', 'full', '0', 'default',
                                    'jpg')
         del cache[request]
예제 #6
0
    def test_missing_entry_is_keyerror(self):
        with tempfile.TemporaryDirectory() as tmp:
            cache = img.ImageCache(cache_root=tmp)
            request = img.ImageRequest('id1', 'full', 'full', '0', 'default',
                                       'jpg')

            with self.assertRaises(KeyError):
                cache[request]
예제 #7
0
    def test_getitem_with_unexpected_error_is_raised(self):
        cache = img.ImageCache(cache_root='/tmp')
        request = img.ImageRequest('id', 'full', 'full', '0', 'default', 'jpg')

        message = "Exception thrown in img_t.py for Test_ImageCache"
        m = mock.Mock(side_effect=OSError(-1, message))
        with mock.patch('loris.img.path.getmtime', m):
            with pytest.raises(OSError) as err:
                cache[request]
예제 #8
0
	def test_missing_entry_is_keyerror(self):
		cache = img.ImageCache(cache_root='/tmp')
		request = img.ImageRequest(
			ident='V1234.jpg',
			region='100,100,100,100',
			size='100,100',
			rotation='0',
			quality='color',
			target_format='jpeg'
		)

		with self.assertRaises(KeyError):
			cache[request]
예제 #9
0
    def test_missing_entry_gets_none(self):
        cache = img.ImageCache(cache_root='/tmp')
        request = img.ImageRequest('id1', 'full', 'full', '0', 'default',
                                   'jpg')

        self.assertIsNone(cache.get(request))