1 from django.conf import settings
2 from django.test import TestCase
5 from slughifi import slughifi
6 from librarian import WLURI
8 class WLTestCase(TestCase):
10 Generic base class for tests. Adds settings freeze and clears MEDIA_ROOT.
13 self._MEDIA_ROOT, settings.MEDIA_ROOT = settings.MEDIA_ROOT, tempfile.mkdtemp(prefix='djangotest_')
14 settings.NO_BUILD_PDF = settings.NO_BUILD_MOBI = settings.NO_BUILD_EPUB = settings.NO_BUILD_TXT = True
15 settings.CELERY_ALWAYS_EAGER = True
18 shutil.rmtree(settings.MEDIA_ROOT, True)
19 settings.MEDIA_ROOT = self._MEDIA_ROOT
21 class PersonStub(object):
23 def __init__(self, first_names, last_name):
24 self.first_names = first_names
25 self.last_name = last_name
28 class BookInfoStub(object):
30 def __init__(self, **kwargs):
33 def __setattr__(self, key, value):
34 if not key.startswith('_'):
35 self.__dict[key] = value
36 return object.__setattr__(self, key, value)
38 def __getattr__(self, key):
39 return self.__dict[key]
42 return dict((key, unicode(value)) for key, value in self.__dict.items())
45 def info_args(title, language=None):
46 """ generate some keywords for comfortable BookInfoCreation """
47 slug = unicode(slughifi(title))
51 'title': unicode(title),
52 'url': WLURI.from_slug_and_lang(slug, language),
53 'about': u"http://wolnelektury.pl/example/URI/%s" % slug,