Permalink
Browse files

Write test for issue #29.

  • Loading branch information...
1 parent cccd100 commit 22b7c8a726899683f0231c9e3b1df0ff5711071e @richardbarran richardbarran committed Sep 12, 2012
Showing with 27 additions and 2 deletions.
  1. BIN photologue/res/test_&quoting.jpg
  2. +1 −0 photologue/tests/helpers.py
  3. +26 −2 photologue/tests/photo.py
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -9,6 +9,7 @@
LANDSCAPE_IMAGE_PATH = os.path.join(RES_DIR, 'test_landscape.jpg')
PORTRAIT_IMAGE_PATH = os.path.join(RES_DIR, 'test_portrait.jpg')
SQUARE_IMAGE_PATH = os.path.join(RES_DIR, 'test_square.jpg')
+QUOTING_IMAGE_PATH = os.path.join(RES_DIR, 'test_&quoting.jpg')
def _create_new_photo(name, slug):
pl = Photo(title=name, title_slug=slug)
View
@@ -1,11 +1,20 @@
import Image
import os
from django.conf import settings
+from django.core.files.base import ContentFile
from photologue.models import Photo, PHOTOLOGUE_DIR
-from photologue.tests.helpers import LANDSCAPE_IMAGE_PATH, PhotologueBaseTest
-
+from photologue.tests.helpers import LANDSCAPE_IMAGE_PATH, PhotologueBaseTest, \
+QUOTING_IMAGE_PATH
class PhotoTest(PhotologueBaseTest):
+ def tearDown(self):
+ """Delete any extra test files (if created)."""
+ super(PhotoTest, self).tearDown()
+ try:
+ self.pl2.delete()
+ except:
+ pass
+
def test_new_photo(self):
self.assertEqual(Photo.objects.count(), 1)
self.assertTrue(os.path.isfile(self.pl.image.path))
@@ -57,6 +66,21 @@ def test_accessor_methods(self):
os.path.join(self.pl.cache_path(),
self.pl._get_filename_for_size(self.s)))
+ def test_quoted_url(self):
+ """Test for issue #29 - filenames of photos are incorrectly quoted when
+ building a URL."""
+
+ # Check that a 'normal' path works ok.
+ self.assertEquals(self.pl.get_display_url(),
+ self.pl.cache_url() + '/test_landscape_display.jpg')
+
+ # Now create a Photo with a name that needs quoting.
+ self.pl2 = Photo(title='test', title_slug='test')
+ self.pl2.image.save(os.path.basename(QUOTING_IMAGE_PATH),
+ ContentFile(open(QUOTING_IMAGE_PATH, 'rb').read()))
+ self.pl2.save()
+ self.assertEquals(self.pl2.get_display_url(),
+ self.pl2.cache_url() + '/test_%26quoting_display.jpg')

0 comments on commit 22b7c8a

Please sign in to comment.