/
__init__.py
69 lines (54 loc) · 1.78 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#coding:utf-8
import tempfile
import shutil
import os
import unittest2 as unittest
import django.conf
from cactus import Site
from cactus.bootstrap import bootstrap
from cactus.config.router import ConfigRouter
from cactus.utils.parallel import PARALLEL_DISABLED
class BaseTestCase(unittest.TestCase):
def setUp(self):
self.test_dir = tempfile.mkdtemp()
self.path = os.path.join(self.test_dir, 'test')
self.clear_django_settings()
bootstrap(self.path, os.path.join("cactus", "tests", "data", "skeleton"))
def tearDown(self):
shutil.rmtree(self.test_dir)
def clear_django_settings(self):
django.conf.settings._wrapped = django.conf.empty
def assertFileExists(self, path):
"""
Check that a file at path exists.
"""
try:
open(path)
except IOError:
self.fail("File does not exist: {0}".format(path))
def assertFileDoesNotExist(self, path):
"""
Check that the file at path does not exist.
"""
try:
open(path)
except IOError:
pass
else:
self.fail("File exists: {0}".format(path))
class SiteTestCase(BaseTestCase):
def setUp(self):
super(SiteTestCase, self).setUp()
self.config_path = os.path.join(self.path, 'config.json')
self.conf = ConfigRouter([self.config_path])
self.conf.set('site-url', 'http://example.com/')
for k, v in self.get_config_for_test().items():
self.conf.set(k, v)
self.conf.write()
self.site = Site(self.path, [self.config_path])
self.site._parallel = PARALLEL_DISABLED
def get_config_for_test(self):
"""
Hook to set config keys in other tests.
"""
return {}