From: Radek Czajka Date: Fri, 18 Feb 2011 11:36:28 +0000 (+0100) Subject: bookmedia tests, long file name fix X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/fe4a9a390a93aed8b2380f4864c25f05d7f317ff?hp=24a30f976686c4d183c1bd09cdae95c15a7b8dae bookmedia tests, long file name fix --- 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