fix for isbn import
[redakcja.git] / src / documents / tests / test_publish.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 the publishing process."""
5
6 from documents.test_utils import get_fixture
7
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
12
13
14 class PublishTests(TestCase):
15     def setUp(self):
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')
19
20     @patch('apiclient.api_call')
21     def test_unpublishable(self, api_call):
22         with self.assertRaises(AssertionError):
23             self.book.publish(self.user)
24
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(
30             self.user,
31             'books/',
32             {
33                 "book_xml": self.text1,
34                 "days": 0,
35                 "hidden": False
36             },
37             beta=False
38         )
39
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(
48             self.user,
49             'books/',
50             {
51                 "book_xml": get_fixture('expected.xml'),
52                 "days": 0,
53                 "hidden": False
54             },
55             beta=False
56         )