From: Marcin Koziej Date: Mon, 21 May 2012 11:03:30 +0000 (+0200) Subject: minor fix for tests. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/8c43021c5d0731cf35203cb32bbc63c89271cbb5?ds=sidebyside;hp=7f4607810640a9e562f06df4f1b8ec6fee8b0eea minor fix for tests. --- diff --git a/apps/catalogue/helpers.py b/apps/catalogue/helpers.py index a97a0400..7b1f44a4 100644 --- a/apps/catalogue/helpers.py +++ b/apps/catalogue/helpers.py @@ -70,6 +70,11 @@ class GalleryMerger(object): m = not always and re.match(r"^([0-9])-", name) return "%1d-%s" % (prefix, m and name[2:] or name) + @property + def was_merged(self): + "Check if we have gallery size recorded" + return self.dest_size is not None + def merge(self): if not self.dest: return self.src diff --git a/apps/catalogue/models/book.py b/apps/catalogue/models/book.py index df1ff4e0..7e6cbfa2 100755 --- a/apps/catalogue/models/book.py +++ b/apps/catalogue/models/book.py @@ -200,10 +200,10 @@ class Book(models.Model): self.gallery = gm.merge() # and move the gallery starts - num_files = gm.dest_size - for chunk in self[len(self) - len_other:]: - chunk.gallery_start += gm.dest_size - gm.num_deleted - chunk.save() + if gm.was_merged: + for chunk in self[len(self) - len_other:]: + chunk.gallery_start += gm.dest_size - gm.num_deleted + chunk.save() other.delete() diff --git a/apps/catalogue/tests/__init__.py b/apps/catalogue/tests/__init__.py index 3421d333..ae7bef7d 100755 --- a/apps/catalogue/tests/__init__.py +++ b/apps/catalogue/tests/__init__.py @@ -93,9 +93,9 @@ class GalleryAppendTests(TestCase): self.book1.chunk_set.create(number=2, title='Second chunk', slug='book 1 / 2') c=self.book1[0] - c.gallery_start=0 + c.gallery_start=1 c=self.book1[1] - c.gallery_start=2 + c.gallery_start=3 self.scandir = join(settings.MEDIA_ROOT, settings.IMAGE_DIR) if not exists(self.scandir): @@ -114,10 +114,15 @@ class GalleryAppendTests(TestCase): self.book2 = Book.create(self.user, 'book 2', slug='book2') self.book2.chunk_set.create(number=2, title='Second chunk of second book', slug='book 2 / 2') + c = self.book2[0] - c.gallery_start = 0 + c.gallery_start = 1 + c.save() c = self.book2[1] - c.gallery_start = 2 + c.gallery_start = 3 + c.save() + + print "gallery starts:",self.book2[0].gallery_start, self.book2[1].gallery_start self.make_gallery(self.book1, { '1-0001_1l' : 'aa', @@ -137,6 +142,7 @@ class GalleryAppendTests(TestCase): files = listdir(join(self.scandir, self.book1.gallery)) files.sort() + print files self.assertEqual(files, [ '1-0001_1l', '1-0001_2r', @@ -148,7 +154,7 @@ class GalleryAppendTests(TestCase): '3-0002_2r', ]) - self.assertEqual((3, 5), (self.book1[2].gallery_start, self.book1[3].gallery_start)) + self.assertEqual((4, 6), (self.book1[2].gallery_start, self.book1[3].gallery_start)) def test_none_indexed(self):