X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/199ba2f0ed2a8abdceddadd17e27d0f541f600c9..4e7cc908ea8309031dbb73638ff360d512ea405b:/apps/catalogue/tests.py?ds=sidebyside
diff --git a/apps/catalogue/tests.py b/apps/catalogue/tests.py
index ddd6fb73e..f5a35a41e 100644
--- a/apps/catalogue/tests.py
+++ b/apps/catalogue/tests.py
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-
from django.test import TestCase
from catalogue import models, views
+from django.core.files.base import ContentFile
from django.contrib.auth.models import User, AnonymousUser
from nose.tools import raises
+from StringIO import StringIO
+
+class BasicSearchLogicTests(TestCase):
-class BasicSearchTests(TestCase):
def setUp(self):
self.author_tag = models.Tag.objects.create(
name=u'Adam Mickiewicz [SubWord]',
@@ -69,3 +72,114 @@ class BasicSearchTests(TestCase):
self.assertEqual(views.find_best_matches(u'Żelenski'), (self.unicode_tag,))
self.assertEqual(views.find_best_matches(u'zelenski'), (self.unicode_tag,))
+
+class PersonStub(object):
+
+ def __init__(self, first_names, last_name):
+ self.first_names = first_names
+ self.last_name = last_name
+
+class BookInfoStub(object):
+
+ def __init__(self, **kwargs):
+ self.__dict = kwargs
+
+ def __setattr__(self, key, value):
+ if not key.startswith('_'):
+ self.__dict[key] = value
+ return object.__setattr__(self, key, value)
+
+ def __getattr__(self, key):
+ return self.__dict[key]
+
+ def to_dict(self):
+ return dict((key, unicode(value)) for key, value in self.__dict.items())
+
+class BookImportLogicTests(TestCase):
+
+ def setUp(self):
+ self.book_info = BookInfoStub(
+ url=u"http://wolnelektury.pl/example/default_book",
+ about=u"http://wolnelektury.pl/example/URI/default_book",
+ title=u"Default Book",
+ author=PersonStub(("Jim",), "Lazy"),
+ kind="X-Kind",
+ genre="X-Genre",
+ epoch="X-Epoch",
+ )
+
+ self.expected_tags = [
+ ('author', 'jim-lazy'),
+ ('book', 'l-default_book'),
+ ('genre', 'x-genre'),
+ ('epoch', 'x-epoch'),
+ ('kind', 'x-kind'),
+ ]
+ self.expected_tags.sort()
+
+ def test_empty_book(self):
+ BOOK_TEXT = "
Ala ma kota
\n') + + self.assert_(('theme', 'love') in [ (tag.category, tag.slug) for tag in book.tags ]) + + def test_book_replace_title(self): + BOOK_TEXT = """