From 0d2710238c43e233ec76d8afa609704777807f42 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 13 Oct 2011 11:49:15 +0200 Subject: [PATCH] tests fix --- .../catalogue/{tests.py => tests/__init__.py} | 23 ++++++--- apps/catalogue/tests/files/chunk1.xml | 41 ++++++++++++++++ apps/catalogue/tests/files/chunk2.xml | 11 +++++ apps/catalogue/tests/files/expected.xml | 48 +++++++++++++++++++ 4 files changed, 116 insertions(+), 7 deletions(-) rename apps/catalogue/{tests.py => tests/__init__.py} (64%) create mode 100755 apps/catalogue/tests/files/chunk1.xml create mode 100755 apps/catalogue/tests/files/chunk2.xml create mode 100755 apps/catalogue/tests/files/expected.xml diff --git a/apps/catalogue/tests.py b/apps/catalogue/tests/__init__.py similarity index 64% rename from apps/catalogue/tests.py rename to apps/catalogue/tests/__init__.py index 8b21f6d9..9d0f36f8 100755 --- a/apps/catalogue/tests.py +++ b/apps/catalogue/tests/__init__.py @@ -1,42 +1,51 @@ +from os.path import abspath, dirname, join from nose.tools import * from mock import patch from django.test import TestCase from django.contrib.auth.models import User from catalogue.models import Book, BookPublishRecord + +def get_fixture(path): + f_path = join(dirname(abspath(__file__)), 'files', path) + with open(f_path) as f: + return unicode(f.read(), 'utf-8') + + class PublishTests(TestCase): def setUp(self): self.user = User.objects.create(username='tester') - self.book = Book.create(self.user, 'publish me') + self.text1 = get_fixture('chunk1.xml') + self.book = Book.create(self.user, self.text1, slug='test-book') @patch('apiclient.api_call') def test_unpublishable(self, api_call): - with self.assertRaises(Book.NoTextError): + with self.assertRaises(AssertionError): 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'}) + api_call.assert_called_with(self.user, 'books/', {"book_xml": self.text1}) @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].commit(get_fixture('chunk2.xml')) 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'}) + api_call.assert_called_with(self.user, 'books/', {"book_xml": get_fixture('expected.xml')}) 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') + self.book1 = Book.create(self.user, 'book 1', slug='book1') + self.book2 = Book.create(self.user, 'book 2', slug='book2') def test_append(self): self.book1.append(self.book2) diff --git a/apps/catalogue/tests/files/chunk1.xml b/apps/catalogue/tests/files/chunk1.xml new file mode 100755 index 00000000..8497f606 --- /dev/null +++ b/apps/catalogue/tests/files/chunk1.xml @@ -0,0 +1,41 @@ + + + + + +Mickiewicz, Adam +Do M*** +Fundacja Nowoczesna Polska +Romantyzm +Liryka +Wiersz + +http://wolnelektury.pl/katalog/lektura/sonety-odeskie-do-m +http://www.polona.pl/Content/2222 +Mickiewicz, Adam (1798-1855), Poezje, tom 1 (Wiersze młodzieńcze - Ballady i romanse - Wiersze do r. 1824), Krakowska Spółdzielnia Wydawnicza, wyd. 2 zwiększone, Kraków, 1922 + +Domena publiczna - Adam Mickiewicz zm. 1855 +1926 +xml +text +text +2007-09-06 + + + + +Adam Mickiewicz +Sonety odeskie +Do M*** + +Wiérsz napisany w roku 1822 + + +Precz z moich oczu!... posłucham od razu,/ +Precz z mego serca!... i serce posłucha,/ +Precz z méj pamięci!... Nie! tego rozkazu/ +Moja i twoja pamięć nie posłucha. + + + + diff --git a/apps/catalogue/tests/files/chunk2.xml b/apps/catalogue/tests/files/chunk2.xml new file mode 100755 index 00000000..63a243e1 --- /dev/null +++ b/apps/catalogue/tests/files/chunk2.xml @@ -0,0 +1,11 @@ + + + +Jak cień tém dłuższy, gdy padnie z daleka,/ +Tém szerzéj koło żałobne roztoczy,/ +Tak moja postać, im daléj ucieka,/ +Tém grubszym kirem twą pamięć pomroczy. + + + + diff --git a/apps/catalogue/tests/files/expected.xml b/apps/catalogue/tests/files/expected.xml new file mode 100755 index 00000000..ccbeefbb --- /dev/null +++ b/apps/catalogue/tests/files/expected.xml @@ -0,0 +1,48 @@ + + + + + +Mickiewicz, Adam +Do M*** +Fundacja Nowoczesna Polska +Romantyzm +Liryka +Wiersz + +http://wolnelektury.pl/katalog/lektura/sonety-odeskie-do-m +http://www.polona.pl/Content/2222 +Mickiewicz, Adam (1798-1855), Poezje, tom 1 (Wiersze młodzieńcze - Ballady i romanse - Wiersze do r. 1824), Krakowska Spółdzielnia Wydawnicza, wyd. 2 zwiększone, Kraków, 1922 + +Domena publiczna - Adam Mickiewicz zm. 1855 +1926 +xml +text +text +2007-09-06 + + + + +Adam Mickiewicz +Sonety odeskie +Do M*** + +Wiérsz napisany w roku 1822 + + +Precz z moich oczu!... posłucham od razu,/ +Precz z mego serca!... i serce posłucha,/ +Precz z méj pamięci!... Nie! tego rozkazu/ +Moja i twoja pamięć nie posłucha. + + + +Jak cień tém dłuższy, gdy padnie z daleka,/ +Tém szerzéj koło żałobne roztoczy,/ +Tak moja postać, im daléj ucieka,/ +Tém grubszym kirem twą pamięć pomroczy. + + + + -- 2.20.1