teh publish button again
[redakcja.git] / apps / catalogue / tests.py
1 from nose.tools import *
2 from mock import patch
3 from django.test import TestCase
4 from django.contrib.auth.models import User
5 from catalogue.models import Book, BookPublishRecord
6
7 class PublishTests(TestCase):
8
9     def setUp(self):
10         self.user = User.objects.create(username='tester')
11         self.book = Book.create(self.user, 'publish me')
12
13     @patch('apiclient.api_call')
14     def test_unpublishable(self, api_call):
15         with self.assertRaises(Book.NoTextError):
16             self.book.publish(self.user)
17
18     @patch('apiclient.api_call')
19     def test_publish(self, api_call):
20         self.book[0].head.set_publishable(True)
21         self.book.publish(self.user)
22         api_call.assert_called_with(self.user, 'books', {"book_xml": 'publish me'})
23
24     @patch('apiclient.api_call')
25     def test_publish_multiple(self, api_call):
26         self.book[0].head.set_publishable(True)
27         self.book[0].split(slug='part-2')
28         self.book[1].commit('take me \n<!-- TRIM_BEGIN -->\n too')
29         self.book[1].head.set_publishable(True)
30         self.book.publish(self.user)
31         api_call.assert_called_with(self.user, 'books', {"book_xml": 'publish me\n too'})