1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.test import TestCase
6 from django.test.utils import override_settings
8 from slughifi import slughifi
9 from librarian import WLURI
12 MEDIA_ROOT=tempfile.mkdtemp(prefix='djangotest_'),
13 CATALOGUE_DONT_BUILD={'pdf', 'mobi', 'epub', 'txt', 'fb2', 'cover'},
14 NO_SEARCH_INDEX = True,
15 CELERY_ALWAYS_EAGER = True,
17 'api': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'},
18 'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'},
19 'permanent': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'},
22 class WLTestCase(TestCase):
24 Generic base class for tests. Adds settings freeze and clears MEDIA_ROOT.
29 class PersonStub(object):
31 def __init__(self, first_names, last_name):
32 self.first_names = first_names
33 self.last_name = last_name
36 return " ".join(self.first_names + (self.last_name,))
39 class BookInfoStub(object):
40 _empty_fields = ['cover_url', 'variant_of']
41 # allow single definition for multiple-value fields
46 def __init__(self, **kwargs):
49 def __setattr__(self, key, value):
50 if not key.startswith('_'):
51 self.__dict[key] = value
52 return object.__setattr__(self, key, value)
54 def __getattr__(self, key):
56 return self.__dict[key]
58 if key in self._empty_fields:
60 elif key in self._salias:
61 return [getattr(self, self._salias[key])]
66 return dict((key, unicode(value)) for key, value in self.__dict.items())
69 def info_args(title, language=None):
70 """ generate some keywords for comfortable BookInfoCreation """
71 slug = unicode(slughifi(title))
75 'title': unicode(title),
76 'url': WLURI.from_slug(slug),
77 'about': u"http://wolnelektury.pl/example/URI/%s" % slug,