Ticket #670: public domain countdown problems under IE7, fixed.
[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
14     def tearDown(self):
15         shutil.rmtree(settings.MEDIA_ROOT, True)
16         settings.MEDIA_ROOT = self._MEDIA_ROOT
17
18 class PersonStub(object):
19
20     def __init__(self, first_names, last_name):
21         self.first_names = first_names
22         self.last_name = last_name
23
24
25 class BookInfoStub(object):
26
27     def __init__(self, **kwargs):
28         self.__dict = kwargs
29
30     def __setattr__(self, key, value):
31         if not key.startswith('_'):
32             self.__dict[key] = value
33         return object.__setattr__(self, key, value)
34
35     def __getattr__(self, key):
36         return self.__dict[key]
37
38     def to_dict(self):
39         return dict((key, unicode(value)) for key, value in self.__dict.items())
40
41
42 def info_args(title):
43     """ generate some keywords for comfortable BookInfoCreation  """
44     slug = unicode(slughifi(title))
45     return {
46         'title': unicode(title),
47         'slug': slug,
48         'url': u"http://wolnelektury.pl/example/%s" % slug,
49         'about': u"http://wolnelektury.pl/example/URI/%s" % slug,
50     }