1 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 """Tests for manipulating books in the catalogue."""
6 from django.test import TestCase
7 from django.contrib.auth.models import User
8 from documents.models import Book
11 class ManipulationTests(TestCase):
14 self.user = User.objects.create(username='tester')
15 self.book1 = Book.create(self.user, 'book 1', slug='book1')
16 self.book2 = Book.create(self.user, 'book 2', slug='book2')
18 def test_append(self):
19 self.book1.append(self.book2)
20 self.assertEqual(Book.objects.all().count(), 1)
21 self.assertEqual(len(self.book1), 2)
23 def test_append_to_self(self):
24 with self.assertRaises(AssertionError):
25 self.book1.append(Book.objects.get(pk=self.book1.pk))
26 self.assertEqual(Book.objects.all().count(), 2)
27 self.assertEqual(len(self.book1), 1)
29 def test_prepend_history(self):
30 self.book1.prepend_history(self.book2)
31 self.assertEqual(Book.objects.all().count(), 1)
32 self.assertEqual(len(self.book1), 1)
33 self.assertEqual(self.book1.materialize(), 'book 1')
35 def test_prepend_history_to_self(self):
36 with self.assertRaises(AssertionError):
37 self.book1.prepend_history(self.book1)
38 self.assertEqual(Book.objects.all().count(), 2)
39 self.assertEqual(self.book1.materialize(), 'book 1')
40 self.assertEqual(self.book2.materialize(), 'book 2')
42 def test_split_book(self):
43 self.book1.chunk_set.create(number=2, title='Second chunk',
45 self.book1[1].commit('I survived!')
46 self.assertEqual(len(self.book1), 2)
48 self.assertEqual(set([b.slug for b in Book.objects.all()]),
49 set(['book2', '1', 'book3']))
51 Book.objects.get(slug='book3').materialize(),