tests: start wcs as a django app
This commit is contained in:
parent
dfdc887569
commit
fb79e150a2
|
@ -27,6 +27,7 @@ wcsctl_present = pytest.mark.skipif('WCSCTL' not in os.environ,
|
|||
reason='WCSCTL not defined in environment')
|
||||
|
||||
WCSCTL = os.environ.get('WCSCTL')
|
||||
WCS_MANAGE = os.path.join(os.path.dirname(WCSCTL), 'manage.py')
|
||||
|
||||
WCS_SCRIPTS = {
|
||||
'setup-auth': """
|
||||
|
@ -140,6 +141,7 @@ formdef.store()
|
|||
}
|
||||
|
||||
WCS_DIR = tempfile.mkdtemp()
|
||||
WCS_PID = None
|
||||
|
||||
def run_wcs_script(script, hostname):
|
||||
script_path = os.path.join(WCS_DIR, script + '.py')
|
||||
|
@ -151,6 +153,8 @@ def run_wcs_script(script, hostname):
|
|||
|
||||
|
||||
def setup_module(module):
|
||||
global WCS_PID
|
||||
|
||||
if not WCSCTL:
|
||||
return
|
||||
|
||||
|
@ -167,21 +171,32 @@ combo = combo
|
|||
''')
|
||||
fd.close()
|
||||
|
||||
pidfile = os.path.join(WCS_DIR, 'wcs.pid')
|
||||
subprocess.check_call([WCSCTL, 'start', '--daemonize', '--http',
|
||||
'--port', '8999',
|
||||
'--pidfile', pidfile, '--app-dir', WCS_DIR])
|
||||
t0 = time.time()
|
||||
while not os.path.exists(pidfile):
|
||||
time.sleep(0.2)
|
||||
if time.time() - t0 > 30:
|
||||
raise AssertionError('failed to start wcs')
|
||||
with open(os.path.join(WCS_DIR, 'wcs.cfg'), 'w') as fd:
|
||||
print >> fd, '''[main]
|
||||
app_dir = %s''' % WCS_DIR
|
||||
|
||||
with open(os.path.join(WCS_DIR, 'local_settings.py'), 'w') as fd:
|
||||
print >> fd, '''
|
||||
WCS_LEGACY_CONFIG_FILE = '%s/wcs.cfg'
|
||||
THEMES_DIRECTORY = '/'
|
||||
ALLOWED_HOSTS = ['127.0.0.1', '127.0.0.2']
|
||||
''' % WCS_DIR
|
||||
|
||||
WCS_PID = os.fork()
|
||||
if not WCS_PID:
|
||||
os.chdir(os.path.dirname(WCS_MANAGE))
|
||||
print 'running child'
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'wcs.settings'
|
||||
os.environ['WCS_SETTINGS_FILE'] = os.path.join(WCS_DIR, 'local_settings.py')
|
||||
os.execvp('python', ['python', WCS_MANAGE, 'runserver', '--noreload', '0.0.0.0:8999'])
|
||||
sys.exit(0)
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
def teardown_module(module):
|
||||
pidfile = os.path.join(WCS_DIR, 'wcs.pid')
|
||||
subprocess.check_call([WCSCTL, 'stop',
|
||||
'--pidfile', pidfile, '--app-dir', WCS_DIR])
|
||||
shutil.rmtree(WCS_DIR)
|
||||
if WCS_PID:
|
||||
os.kill(WCS_PID, 9)
|
||||
shutil.rmtree(WCS_DIR)
|
||||
|
||||
|
||||
def check_wcs_open(url):
|
||||
|
|
Loading…
Reference in New Issue