More readable keyboard.
[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 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(self.user, 'books/', {"book_xml": self.text1, "days": 0}, beta=False)
30
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)