Android promo
[wolnelektury.git] / apps / catalogue / test_utils.py
1 from django.conf import settings
2 from django.test import TestCase
3 import shutil
4 import tempfile
5 from slughifi import slughifi
6
7 class WLTestCase(TestCase):
8     """
9         Generic base class for tests. Adds settings freeze and clears MEDIA_ROOT.
10     """
11     def setUp(self):
12         self._MEDIA_ROOT, settings.MEDIA_ROOT = settings.MEDIA_ROOT, tempfile.mkdtemp(prefix='djangotest_')
13         settings.NO_BUILD_EPUB = settings.NO_BUILD_TXT = True
14
15     def tearDown(self):
16         shutil.rmtree(settings.MEDIA_ROOT, True)
17         settings.MEDIA_ROOT = self._MEDIA_ROOT
18
19 class PersonStub(object):
20
21     def __init__(self, first_names, last_name):
22         self.first_names = first_names
23         self.last_name = last_name
24
25
26 class BookInfoStub(object):
27
28     def __init__(self, **kwargs):
29         self.__dict = kwargs
30
31     def __setattr__(self, key, value):
32         if not key.startswith('_'):
33             self.__dict[key] = value
34         return object.__setattr__(self, key, value)
35
36     def __getattr__(self, key):
37         return self.__dict[key]
38
39     def to_dict(self):
40         return dict((key, unicode(value)) for key, value in self.__dict.items())
41
42
43 def info_args(title):
44     """ generate some keywords for comfortable BookInfoCreation  """
45     slug = unicode(slughifi(title))
46     return {
47         'title': unicode(title),
48         'slug': slug,
49         'url': u"http://wolnelektury.pl/example/%s" % slug,
50         'about': u"http://wolnelektury.pl/example/URI/%s" % slug,
51     }