1 # -*- coding: utf-8 -*-
3 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 """Tests for galleries of scans."""
8 from os.path import join, basename, exists
9 from os import makedirs, listdir
10 from django.test import TestCase
11 from django.contrib.auth.models import User
12 from catalogue.models import Book
13 from tempfile import mkdtemp
14 from django.conf import settings
17 class GalleryAppendTests(TestCase):
19 self.user = User.objects.create(username='tester')
20 self.book1 = Book.create(self.user, 'book 1', slug='book1')
21 self.book1.chunk_set.create(number=2, title='Second chunk',
26 self.scandir = join(settings.MEDIA_ROOT, settings.IMAGE_DIR)
27 if not exists(self.scandir):
28 makedirs(self.scandir)
30 def make_gallery(self, book, files):
31 d = mkdtemp('gallery', dir=self.scandir)
32 for named, cont in files.items():
33 f = open(join(d, named), 'w')
36 book.gallery = basename(d)
39 def test_both_indexed(self):
40 self.book2 = Book.create(self.user, 'book 2', slug='book2')
41 self.book2.chunk_set.create(number=2, title='Second chunk of second book',
48 self.make_gallery(self.book1, {
55 self.make_gallery(self.book2, {
56 '1-0001_1l' : 'dd', # the same, should not be moved
62 self.book1.append(self.book2)
64 files = listdir(join(self.scandir, self.book1.gallery))
66 self.assertEqual(files, [
77 self.assertEqual((4, 6), (self.book1[2].gallery_start, self.book1[3].gallery_start))
80 def test_none_indexed(self):
81 self.book2 = Book.create(self.user, 'book 2', slug='book2')
82 self.make_gallery(self.book1, {
89 self.make_gallery(self.book2, {
96 self.book1.append(self.book2)
98 files = listdir(join(self.scandir, self.book1.gallery))
100 self.assertEqual(files, [
112 def test_none_indexed(self):
113 self.book2 = Book.create(self.user, 'book 2', slug='book2')
114 self.make_gallery(self.book1, {
121 self.make_gallery(self.book2, {
128 self.book1.append(self.book2)
130 files = listdir(join(self.scandir, self.book1.gallery))
132 self.assertEqual(files, [