show isbn for woblink
[redakcja.git] / src / documents / tests / test_book.py
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.
3 #
4 """Tests for manipulating books in the catalogue."""
5
6 from django.test import TestCase
7 from django.contrib.auth.models import User
8 from documents.models import Book
9
10
11 class ManipulationTests(TestCase):
12
13     def setUp(self):
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')
17
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)
22
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)
28
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')
34
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')
41
42     def test_split_book(self):
43         self.book1.chunk_set.create(number=2, title='Second chunk',
44                 slug='book3')
45         self.book1[1].commit('I survived!')
46         self.assertEqual(len(self.book1), 2)
47         self.book1.split()
48         self.assertEqual(set([b.slug for b in Book.objects.all()]),
49                 set(['book2', '1', 'book3']))
50         self.assertEqual(
51                 Book.objects.get(slug='book3').materialize(),
52                 'I survived!')