X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/fdd62169ba22c4c1be2f2306b5339eadd74ffb6d..2aaa98ee15d4e5032b4d4f0c83c140636fb8b10e:/apps/catalogue/tests.py diff --git a/apps/catalogue/tests.py b/apps/catalogue/tests.py old mode 100644 new mode 100755 index 65777379..8b21f6d9 --- a/apps/catalogue/tests.py +++ b/apps/catalogue/tests.py @@ -1,19 +1,50 @@ 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): - 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): + @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\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'}) - def test_storage_empty(self): - storage = models.DocumentStorage(self.dirpath) - eq_(storage.all(), []) + +class ManipulationTests(TestCase): + + def setUp(self): + self.user = User.objects.create(username='tester') + self.book1 = Book.create(self.user, 'book 1') + self.book2 = Book.create(self.user, 'book 2') + + def test_append(self): + self.book1.append(self.book2) + self.assertEqual(Book.objects.all().count(), 1) + self.assertEqual(len(self.book1), 2) + + def test_append_to_self(self): + with self.assertRaises(AssertionError): + self.book1.append(Book.objects.get(pk=self.book1.pk)) + self.assertEqual(Book.objects.all().count(), 2) + self.assertEqual(len(self.book1), 1)