From fe4a9a390a93aed8b2380f4864c25f05d7f317ff Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 18 Feb 2011 12:36:28 +0100 Subject: [PATCH 1/1] bookmedia tests, long file name fix --- apps/catalogue/models.py | 2 +- apps/catalogue/tests/bookmedia.py | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index 00baa287e..f2be7d1b9 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -168,7 +168,7 @@ def book_upload_path(ext=None, maxlen=100): name = slughifi(filename.split(".")[0]) else: name = slughifi(media.name) - return 'lektura/%s.%s' % (name[:(maxlen-len('lektura/.%s' % ext))], ext) + return 'lektura/%s.%s' % (name[:maxlen-len('lektura/.%s' % ext)-4], ext) return get_dynamic_path diff --git a/apps/catalogue/tests/bookmedia.py b/apps/catalogue/tests/bookmedia.py index a9f76e941..72fb03067 100644 --- a/apps/catalogue/tests/bookmedia.py +++ b/apps/catalogue/tests/bookmedia.py @@ -7,11 +7,24 @@ from catalogue import models class BookMediaTests(WLTestCase): + def setUp(self): + WLTestCase.setUp(self) + self.file = ContentFile('X') + + def test_diacritics(self): + bm = models.BookMedia.objects.create(type="ogg", + name="Zażółć gęślą jaźń") + bm.file.save(bm.name, self.file) + self.assertEqual(bm.file.name.rsplit('/', 1)[-1], 'zazolc-gesla-jazn.ogg') + + def test_long_name(self): - file = ContentFile('X') bm = models.BookMedia.objects.create(type="ogg", name="Some very very very very very very very very very very very very very very very very long file name") - bm.file.save(bm.name, file) + + # save twice so Django adds some stuff + bm.file.save(bm.name, self.file) + bm.file.save(bm.name, self.file) bm.save() # reload to see what was really saved -- 2.20.1