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 manipulating books in the catalogue."""
8 from django.test import TestCase
9 from django.contrib.auth.models import User
10 from catalogue.models import Book
13 class ManipulationTests(TestCase):
16 self.user = User.objects.create(username='tester')
17 self.book1 = Book.create(self.user, 'book 1', slug='book1')
18 self.book2 = Book.create(self.user, 'book 2', slug='book2')
20 def test_append(self):
21 self.book1.append(self.book2)
22 self.assertEqual(Book.objects.all().count(), 1)
23 self.assertEqual(len(self.book1), 2)
25 def test_append_to_self(self):
26 with self.assertRaises(AssertionError):
27 self.book1.append(Book.objects.get(pk=self.book1.pk))
28 self.assertEqual(Book.objects.all().count(), 2)
29 self.assertEqual(len(self.book1), 1)
31 def test_prepend_history(self):
32 self.book1.prepend_history(self.book2)
33 self.assertEqual(Book.objects.all().count(), 1)
34 self.assertEqual(len(self.book1), 1)
35 self.assertEqual(self.book1.materialize(), 'book 1')
37 def test_prepend_history_to_self(self):
38 with self.assertRaises(AssertionError):
39 self.book1.prepend_history(self.book1)
40 self.assertEqual(Book.objects.all().count(), 2)
41 self.assertEqual(self.book1.materialize(), 'book 1')
42 self.assertEqual(self.book2.materialize(), 'book 2')
44 def test_split_book(self):
45 self.book1.chunk_set.create(number=2, title='Second chunk',
47 self.book1[1].commit('I survived!')
48 self.assertEqual(len(self.book1), 2)
50 self.assertEqual(set([b.slug for b in Book.objects.all()]),
51 set(['book2', '1', 'book3']))
53 Book.objects.get(slug='book3').materialize(),