Merge branch 'master' into ofop
[redakcja.git] / apps / catalogue / tests / publish.py
1 # -*- coding: utf-8 -*-
2 #
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.
5 #
6 """Tests for the publishing process."""
7
8 from catalogue.test_utils import get_fixture
9
10 from mock import patch
11 from django.test import TestCase
12 from django.contrib.auth.models import User
13 from catalogue.models import Book
14
15
16 class PublishTests(TestCase):
17     def setUp(self):
18         self.user = User.objects.create(username='tester')
19         self.text1 = get_fixture('chunk1.xml')
20         self.book = Book.create(self.user, self.text1, slug='test-book')
21
22     @patch('apiclient.api_call')
23     def test_unpublishable(self, api_call):
24         with self.assertRaises(AssertionError):
25             self.book.publish(self.user)
26
27     @patch('apiclient.api_call')
28     def test_publish(self, api_call):
29         self.book[0].head.set_publishable(True)
30         self.book.publish(self.user)
31         api_call.assert_called_with(self.user, 'books/', {"book_xml": self.text1})
32
33     @patch('apiclient.api_call')
34     def test_publish_multiple(self, api_call):
35         self.book[0].head.set_publishable(True)
36         self.book[0].split(slug='part-2')
37         self.book[1].commit(get_fixture('chunk2.xml'))
38         self.book[1].head.set_publishable(True)
39         self.book.publish(self.user)
40         api_call.assert_called_with(self.user, 'books/', {"book_xml": get_fixture('expected.xml')})