|
21 | 21 | from filer.models.filemodels import File |
22 | 22 | from filer.models.foldermodels import Folder, FolderPermission |
23 | 23 | from filer.models.virtualitems import FolderRoot |
24 | | -from filer.settings import FILER_IMAGE_MODEL |
| 24 | +from filer.settings import DEFERRED_THUMBNAIL_SIZES, FILER_IMAGE_MODEL |
25 | 25 | from filer.templatetags.filer_admin_tags import file_icon_url |
26 | 26 | from filer.thumbnail_processors import normalize_subject_location |
27 | 27 | from filer.utils.loader import load_model |
@@ -254,9 +254,49 @@ class FilerImageAdminUrlsTests(TestCase): |
254 | 254 | def setUp(self): |
255 | 255 | self.superuser = create_superuser() |
256 | 256 | self.client.login(username='admin', password='secret') |
| 257 | + self.img = create_image() |
| 258 | + self.image_name = 'test_file.jpg' |
| 259 | + self.filename = os.path.join(settings.FILE_UPLOAD_TEMP_DIR, self.image_name) |
| 260 | + self.img.save(self.filename, 'JPEG') |
| 261 | + with open(self.filename, 'rb') as upload: |
| 262 | + self.file_object = Image.objects.create(file=django.core.files.File(upload, name=self.image_name)) |
257 | 263 |
|
258 | 264 | def tearDown(self): |
259 | 265 | self.client.logout() |
| 266 | + os.remove(self.filename) |
| 267 | + |
| 268 | + def test_icon_view_sizes(self): |
| 269 | + """Tests if redirects are issued for accepted thumbnail sizes and 404 otherwise""" |
| 270 | + test_set = tuple((size, 302) for size in DEFERRED_THUMBNAIL_SIZES) |
| 271 | + test_set += (50, 404), (90, 404), (320, 404) |
| 272 | + for size, expected_status in test_set: |
| 273 | + url = reverse('admin:filer_file_fileicon', kwargs={ |
| 274 | + 'file_id': self.file_object.pk, |
| 275 | + 'size': size, |
| 276 | + }) |
| 277 | + response = self.client.get(url) |
| 278 | + self.assertEqual(response.status_code, expected_status) |
| 279 | + if response.status_code == 302: # redirect |
| 280 | + # Redirects to a media file |
| 281 | + self.assertIn("/media/", response["Location"]) |
| 282 | + # Does not redirect to a static file |
| 283 | + self.assertNotIn("/static/", response["Location"]) |
| 284 | + |
| 285 | + def test_missing_file(self): |
| 286 | + image = Image.objects.create( |
| 287 | + owner=self.superuser, |
| 288 | + original_filename="some-image.jpg", |
| 289 | + ) |
| 290 | + url = reverse('admin:filer_file_fileicon', kwargs={ |
| 291 | + 'file_id': image.pk, |
| 292 | + 'size': 80, |
| 293 | + }) |
| 294 | + # Make file unaccessible |
| 295 | + |
| 296 | + response = self.client.get(url) |
| 297 | + |
| 298 | + self.assertEqual(response.status_code, 302) |
| 299 | + self.assertIn("icons/file-missing.svg", response["Location"]) |
260 | 300 |
|
261 | 301 |
|
262 | 302 | class FilerClipboardAdminUrlsTests(TestCase): |
|
0 commit comments