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(self.user, 'books/', {"book_xml": self.text1, "days": 0}, beta=False)
31 @patch('apiclient.api_call')
32 def test_publish_multiple(self, api_call):
33 self.book[0].head.set_publishable(True)
34 self.book[0].split(slug='part-2')
35 self.book[1].commit(get_fixture('chunk2.xml'))
36 self.book[1].head.set_publishable(True)
37 self.book.publish(self.user)
38 api_call.assert_called_with(self.user, 'books/', {"book_xml": get_fixture('expected.xml'), "days": 0}, beta=False)