def test_get_name(self):
     thumbnail = Thumbnail('test.jpg', {
         'size': ['100', '100'],
         'viewport': 'ignored'
     })
     assert thumbnail.get_name(
     ) == '821b6e68771352f0bc53acd8e8144972a56dd0ac/test.jpg'
示例#2
0
class TestThumbnailView:
    def setup(self):
        self.image = ImageModelFactory.create()
        self.thumbnail = Thumbnail(self.image.file.path, {'size': [50, 50]})

    def test_get(self, client, settings):
        settings.ULTIMATETHUMB_USE_X_ACCEL_REDIRECT = False
        response = client.get(self.thumbnail.url)

        assert response.status_code == 200
        assert 'Last-Modified' in response
        assert 'Content-Length' in response
        assert 'Content-Disposition' not in response
        assert 'X-Accel-Redirect' not in response

    def test_get_invalid(self, client):
        response = client.get(
            reverse(
                'thumbnail',
                kwargs={
                    'name':
                    'testtesttesttesttesttesttesttesttesttest/foobar.jpg'
                },
            ))
        assert response.status_code == 404

    def test_get_x_accel_redirect(self, client, settings):
        settings.ULTIMATETHUMB_USE_X_ACCEL_REDIRECT = True
        response = client.get(self.thumbnail.url)

        assert response.status_code == 200
        assert response['X-Accel-Redirect'] == self.thumbnail.get_storage_url()

    def test_get_x_accel_redirect_with_domain(self, client, settings):
        settings.ULTIMATETHUMB_USE_X_ACCEL_REDIRECT = True
        settings.ULTIMATETHUMB_DOMAIN = 'statichost'
        response = client.get(self.thumbnail.url)

        thumbnail_storage._setup()
        assert self.thumbnail.get_storage_url().startswith('//statichost')
        assert response.status_code == 200
        assert response['X-Accel-Redirect'].startswith('/{0}'.format(
            self.thumbnail.get_name()))

        settings.ULTIMATETHUMB_DOMAIN = ''
        thumbnail_storage._setup()

    def test_get_last_modified(self, client, settings):
        settings.ULTIMATETHUMB_USE_X_ACCEL_REDIRECT = True
        response = client.get(self.thumbnail.url)

        assert response.status_code == 200

        response2 = client.get(
            self.thumbnail.url,
            HTTP_IF_MODIFIED_SINCE=response['Last-Modified'])
        assert response2.status_code == 304
    def test_from_name(self):
        thumbnail = Thumbnail('test.jpg', {
            'size': ['100', '100'],
            'viewport': 'ignored'
        })
        thumbnail2 = Thumbnail.from_name(thumbnail.get_name())

        assert thumbnail.source == thumbnail2.source
        thumbnail.options.pop('viewport')
        assert thumbnail.options == thumbnail2.options
class TestThumbnailView:
    def setup(self):
        self.image = ImageModelFactory.create()
        self.thumbnail = Thumbnail(self.image.file.path, {'size': [50, 50]})

    def test_get(self, client, settings):
        settings.ULTIMATETHUMB_USE_X_ACCEL_REDIRECT = False
        response = client.get(self.thumbnail.url)

        assert response.status_code == 200
        assert 'Last-Modified' in response
        assert 'Content-Length' in response
        assert 'Content-Disposition' not in response
        assert 'X-Accel-Redirect' not in response

    def test_get_invalid(self, client):
        response = client.get(reverse('thumbnail', kwargs={
            'name': 'testtesttesttesttesttesttesttesttesttest/foobar.jpg'
        }))
        assert response.status_code == 404

    def test_get_x_accel_redirect(self, client, settings):
        settings.ULTIMATETHUMB_USE_X_ACCEL_REDIRECT = True
        response = client.get(self.thumbnail.url)

        assert response.status_code == 200
        assert response['X-Accel-Redirect'] == self.thumbnail.get_storage_url()

    def test_get_x_accel_redirect_with_domain(self, client, settings):
        settings.ULTIMATETHUMB_USE_X_ACCEL_REDIRECT = True
        settings.ULTIMATETHUMB_DOMAIN = 'statichost'
        response = client.get(self.thumbnail.url)

        thumbnail_storage._setup()
        assert self.thumbnail.get_storage_url().startswith('//statichost')
        assert response.status_code == 200
        assert response['X-Accel-Redirect'].startswith(
            '/{0}'.format(self.thumbnail.get_name()))

        settings.ULTIMATETHUMB_DOMAIN = ''
        thumbnail_storage._setup()

    def test_get_last_modified(self, client, settings):
        settings.ULTIMATETHUMB_USE_X_ACCEL_REDIRECT = True
        response = client.get(self.thumbnail.url)

        assert response.status_code == 200

        response2 = client.get(
            self.thumbnail.url,
            HTTP_IF_MODIFIED_SINCE=response['Last-Modified']
        )
        assert response2.status_code == 304
 def test_storage_name_factored(self):
     thumbnail = Thumbnail('test.jpg', {'size': ['100', '50']})
     assert thumbnail.get_storage_name(2) == os.path.join(
         '2x', thumbnail.get_name())
 def test_storage_name(self):
     thumbnail = Thumbnail('test.jpg', {'size': ['100', '50']})
     assert thumbnail.get_storage_name() == thumbnail.get_name()
 def test_storage_path(self):
     image = ImageModelFactory.create()
     thumbnail = Thumbnail(image.file.path, {'size': ['50', '50']})
     assert thumbnail.get_storage_path() == os.path.join(
         thumbnail_storage.location, thumbnail.get_name())
 def test_storage_url(self):
     thumbnail = Thumbnail('test.jpg', {'size': ['50', '50']})
     assert thumbnail.get_storage_url() == os.path.join(
         thumbnail_storage.base_url, thumbnail.get_name())
 def test_storage_path(self):
     image = ImageModelFactory.create()
     thumbnail = Thumbnail(image.file.path, {'size': ['50', '50']})
     assert thumbnail.get_storage_path() == os.path.join(
         thumbnail_storage.location, thumbnail.get_name())
 def test_storage_url(self):
     thumbnail = Thumbnail('test.jpg', {'size': ['50', '50']})
     assert thumbnail.get_storage_url() == os.path.join(
         thumbnail_storage.base_url, thumbnail.get_name())
    def test_from_name(self):
        thumbnail = Thumbnail('test.jpg', {'size': ['100', '100']})
        thumbnail2 = Thumbnail.from_name(thumbnail.get_name())

        assert thumbnail.source == thumbnail2.source
        assert thumbnail.options == thumbnail2.options
 def test_get_name(self):
     thumbnail = Thumbnail('test.jpg', {'size': ['100', '100']})
     assert thumbnail.get_name() == '48382ea502faf93772a5b07f7d8a590f01d0f15b/test.jpg'
 def test_storage_name_factored(self):
     thumbnail = Thumbnail('test.jpg', {'size': ['100', '50']})
     assert thumbnail.get_storage_name(2) == os.path.join('2x', thumbnail.get_name())
 def test_storage_name(self):
     thumbnail = Thumbnail('test.jpg', {'size': ['100', '50']})
     assert thumbnail.get_storage_name() == thumbnail.get_name()
 def test_get_name(self):
     thumbnail = Thumbnail('test.jpg', {'size': ['100', '100']})
     assert thumbnail.get_name() == '821b6e68771352f0bc53acd8e8144972a56dd0ac/test.jpg'