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 the publishing process."""
6 from documents.test_utils import get_fixture
8 from unittest.mock import patch
9 from django.test import TestCase
10 from django.contrib.auth.models import User
11 from documents.models import Book
14 class PublishTests(TestCase):
16 self.user = User.objects.create(username='tester')
17 self.text1 = get_fixture('chunk1.xml')
18 self.book = Book.create(self.user, self.text1, slug='test-book')
20 @patch('apiclient.api_call')
21 def test_unpublishable(self, api_call):
22 with self.assertRaises(AssertionError):
23 self.book.publish(self.user)
25 @patch('apiclient.api_call')
26 def test_publish(self, api_call):
27 self.book[0].head.set_publishable(True)
28 self.book.publish(self.user)
29 api_call.assert_called_with(
33 "book_xml": self.text1,
40 @patch('apiclient.api_call')
41 def test_publish_multiple(self, api_call):
42 self.book[0].head.set_publishable(True)
43 self.book[0].split(slug='part-2')
44 self.book[1].commit(get_fixture('chunk2.xml'))
45 self.book[1].head.set_publishable(True)
46 self.book.publish(self.user)
47 api_call.assert_called_with(
51 "book_xml": get_fixture('expected.xml'),