3a8af57aa7648e7f7b358c5e5127ede88dc3f323
[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
6 class WLTestCase(TestCase):
7     """
8         Generic base class for tests. Adds settings freeze and clears MEDIA_ROOT.
9     """
10     def setUp(self):
11         self._MEDIA_ROOT, settings.MEDIA_ROOT = settings.MEDIA_ROOT, tempfile.mkdtemp(prefix='djangotest_')
12
13     def tearDown(self):
14         shutil.rmtree(settings.MEDIA_ROOT, True)
15         settings.MEDIA_ROOT = self._MEDIA_ROOT
16
17 class PersonStub(object):
18
19     def __init__(self, first_names, last_name):
20         self.first_names = first_names
21         self.last_name = last_name
22
23
24 class BookInfoStub(object):
25
26     def __init__(self, **kwargs):
27         self.__dict = kwargs
28
29     def __setattr__(self, key, value):
30         if not key.startswith('_'):
31             self.__dict[key] = value
32         return object.__setattr__(self, key, value)
33
34     def __getattr__(self, key):
35         return self.__dict[key]
36
37     def to_dict(self):
38         return dict((key, unicode(value)) for key, value in self.__dict.items())