Make temp dir handling in tests a bit more pythonic
(and let them work on Windows)
This commit is contained in:
parent
2e6db650f2
commit
fefbfcd503
|
@ -1,17 +1,20 @@
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
from flask.ext.testing import TestCase
|
from flask.ext.testing import TestCase
|
||||||
from realms.lib.util import random_string
|
from realms.lib.util import random_string
|
||||||
from realms import create_app
|
from realms import create_app
|
||||||
from subprocess import call
|
|
||||||
|
|
||||||
|
|
||||||
class BaseTest(TestCase):
|
class BaseTest(TestCase):
|
||||||
|
|
||||||
def create_app(self):
|
def create_app(self):
|
||||||
|
self.tempdir = tempfile.mkdtemp()
|
||||||
app = create_app()
|
app = create_app()
|
||||||
app.config['TESTING'] = True
|
app.config['TESTING'] = True
|
||||||
app.config['PRESERVE_CONTEXT_ON_EXCEPTION'] = False
|
app.config['PRESERVE_CONTEXT_ON_EXCEPTION'] = False
|
||||||
app.config['WIKI_PATH'] = '/tmp/%s' % random_string(12)
|
app.config['WIKI_PATH'] = os.path.join(self.tempdir, random_string(12))
|
||||||
app.config['DB_URI'] = 'sqlite:////tmp/%s.db' % random_string(12)
|
app.config['DB_URI'] = 'sqlite:///%s/%s.db' % (self.tempdir, random_string(12))
|
||||||
app.config.update(self.configure())
|
app.config.update(self.configure())
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
@ -19,5 +22,4 @@ class BaseTest(TestCase):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
call(['rm', '-rf', self.app.config['WIKI_PATH']])
|
shutil.rmtree(self.tempdir)
|
||||||
call(['rm', '-f', self.app.config['DB_URI'][10:]])
|
|
||||||
|
|
Loading…
Reference in a new issue