minor fixes
[redakcja.git] / apps / catalogue / tests.py
old mode 100644 (file)
new mode 100755 (executable)
index 6577737..b73ea35
@@ -1,19 +1,31 @@
 from nose.tools import *
 from nose.tools import *
-import wiki.models as models
-import shutil
-import tempfile
+from mock import patch
+from django.test import TestCase
+from django.contrib.auth.models import User
+from catalogue.models import Book, BookPublishRecord
 
 
+class PublishTests(TestCase):
 
 
-class TestStorageBase:
     def setUp(self):
     def setUp(self):
-        self.dirpath = tempfile.mkdtemp(prefix='nosetest_')
+        self.user = User.objects.create(username='tester')
+        self.book = Book.create(self.user, 'publish me')
 
 
-    def tearDown(self):
-        shutil.rmtree(self.dirpath)
+    @patch('apiclient.api_call')
+    def test_unpublishable(self, api_call):
+        with self.assertRaises(Book.NoTextError):
+            self.book.publish(self.user)
 
 
+    @patch('apiclient.api_call')
+    def test_publish(self, api_call):
+        self.book[0].head.set_publishable(True)
+        self.book.publish(self.user)
+        api_call.assert_called_with(self.user, 'books', {"book_xml": 'publish me'})
 
 
-class TestDocumentStorage(TestStorageBase):
-
-    def test_storage_empty(self):
-        storage = models.DocumentStorage(self.dirpath)
-        eq_(storage.all(), [])
+    @patch('apiclient.api_call')
+    def test_publish_multiple(self, api_call):
+        self.book[0].head.set_publishable(True)
+        self.book[0].split(slug='part-2')
+        self.book[1].commit('take me \n<!-- TRIM_BEGIN -->\n too')
+        self.book[1].head.set_publishable(True)
+        self.book.publish(self.user)
+        api_call.assert_called_with(self.user, 'books', {"book_xml": 'publish me\n too'})