Newer
Older
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
import os
import tempfile
import shutil
import unittest
from uffd import create_app, db
def dump(basename, resp):
basename = basename.replace('.', '_').replace('/', '_')
suffix = '.html'
root = os.environ.get('DUMP_PAGES')
if not root:
return
os.makedirs(root, exist_ok=True)
path = os.path.join(root, basename+suffix)
with open(path, 'xb') as f:
f.write(resp.data)
class UffdTestCase(unittest.TestCase):
def setUp(self):
self.dir = tempfile.mkdtemp()
# It would be far better to create a minimal app here, but since the
# session module depends on almost everything else, that is not really feasable
self.app = create_app({
'TESTING': True,
'DEBUG': True,
'SQLALCHEMY_DATABASE_URI': 'sqlite:///%s/db.sqlite'%self.dir,
'SECRET_KEY': 'DEBUGKEY',
'LDAP_SERVICE_MOCK': True,
})
self.setUpApp()
self.client = self.app.test_client()
self.client.__enter__()
# Just do some request so that we can use url_for
self.client.get(path='/')
db.create_all()
def setUpApp(self):
pass
def tearDown(self):
self.client.__exit__(None, None, None)
shutil.rmtree(self.dir)