1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
4 from os.path import abspath, dirname, join
6 from traceback import extract_stack
7 from django.conf import settings
8 from django.test import TestCase
9 from django.test.utils import override_settings
10 from slugify import slugify
11 from librarian import WLURI
15 MEDIA_ROOT=tempfile.mkdtemp(prefix='djangotest_'),
16 CATALOGUE_DONT_BUILD={'pdf', 'mobi', 'epub', 'txt', 'fb2', 'cover'},
18 CELERY_TASK_ALWAYS_EAGER=True,
20 'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'},
23 class WLTestCase(TestCase):
25 Generic base class for tests. Adds settings freeze and clears MEDIA_ROOT.
32 def __init__(self, first_names, last_name):
33 self.first_names = first_names
34 self.last_name = last_name
37 return " ".join(self.first_names + (self.last_name,))
41 _empty_fields = ['cover_url', 'variant_of']
42 # allow single definition for multiple-value fields
50 def __init__(self, **kwargs):
53 def __setattr__(self, key, value):
54 if not key.startswith('_'):
55 self.__dict[key] = value
56 return object.__setattr__(self, key, value)
58 def __getattr__(self, key):
60 return self.__dict[key]
62 if key in self._empty_fields:
64 if key in self._salias:
65 return [getattr(self, self._salias[key])]
66 raise AttributeError(e)
69 return dict((key, str(value)) for key, value in self.__dict.items())
72 def info_args(title, language=None):
73 """ generate some keywords for comfortable BookInfoCreation """
74 slug = str(slugify(title))
80 'about': "http://wolnelektury.pl/example/URI/%s" % slug,
85 def get_fixture(path, app=None):
87 mod_path = app.__file__
88 f_path = join(dirname(abspath(mod_path)), 'tests/files', path)
90 mod_path = extract_stack(limit=2)[0][0]
91 f_path = join(dirname(abspath(mod_path)), 'files', path)
95 def get_mp3_length(path):