2012-11-09 21:03:57 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import subprocess
|
2012-11-13 23:54:08 +01:00
|
|
|
import requests
|
2013-05-21 23:09:08 +02:00
|
|
|
import optparse
|
2012-11-09 21:03:57 +01:00
|
|
|
import time
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
from os import path
|
2013-03-05 22:50:06 +01:00
|
|
|
import glob
|
2012-11-09 21:03:57 +01:00
|
|
|
|
2013-05-21 23:09:08 +02:00
|
|
|
#
|
|
|
|
# In order to use remote casperjs debugging, pass the --remote-debug flag
|
|
|
|
# This will start a remote debugging session listening on port 7777
|
|
|
|
#
|
|
|
|
# See https://wiki.humbughq.com/Testing%20the%20app for more information
|
|
|
|
# on how to use remote debugging
|
|
|
|
#
|
|
|
|
|
2013-01-10 19:05:53 +01:00
|
|
|
os.environ["TORNADO_SERVER"] = "http://localhost:9983"
|
|
|
|
|
2013-05-21 23:09:08 +02:00
|
|
|
parser = optparse.OptionParser(r"""
|
|
|
|
|
|
|
|
%prog --remote-debug file1 file2 file3""")
|
|
|
|
|
|
|
|
parser.add_option('--remote-debug',
|
|
|
|
help='Whether or not to enable remote debugging on port 7777',
|
|
|
|
action="store_true",
|
|
|
|
default=False)
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
2013-03-05 17:24:37 +01:00
|
|
|
test_files = []
|
2013-05-21 23:09:08 +02:00
|
|
|
for file in args:
|
2013-03-05 17:24:37 +01:00
|
|
|
if not os.path.exists(file):
|
|
|
|
file = path.join(path.dirname(__file__), 'tests', file)
|
|
|
|
test_files.append(path.abspath(file))
|
|
|
|
|
2012-11-09 21:03:57 +01:00
|
|
|
os.chdir(path.join(path.dirname(__file__), '../../..'))
|
|
|
|
|
|
|
|
subprocess.check_call('zephyr/tests/generate-fixtures')
|
|
|
|
|
2013-03-05 22:50:06 +01:00
|
|
|
subprocess.check_call(['rm', '-f'] + glob.glob('/tmp/casper-failure*.png'))
|
|
|
|
|
2012-11-09 21:03:57 +01:00
|
|
|
log = open('zephyr/tests/frontend/server.log', 'w')
|
|
|
|
|
|
|
|
# Run this not through the shell, so that we have the actual PID.
|
|
|
|
server = subprocess.Popen(('tools/run-dev.py', '--test'),
|
|
|
|
stdout=log, stderr=log)
|
|
|
|
|
2012-11-14 20:04:31 +01:00
|
|
|
def assert_server_running():
|
|
|
|
# Get the exit code of the server, or None if it is still running.
|
|
|
|
if server.poll() is not None:
|
|
|
|
raise RuntimeError, 'Server died unexpectedly! Check zephyr/tests/frontend/server.log'
|
|
|
|
|
2012-11-13 23:54:08 +01:00
|
|
|
def server_is_up():
|
2012-11-14 20:04:31 +01:00
|
|
|
assert_server_running()
|
2012-11-13 23:54:08 +01:00
|
|
|
try:
|
|
|
|
# We could get a 501 error if the reverse proxy is up but the Django app isn't.
|
|
|
|
return requests.get('http://localhost:9981/accounts/home').status_code == 200
|
|
|
|
except:
|
|
|
|
return False
|
|
|
|
|
2012-11-14 00:01:43 +01:00
|
|
|
ret = 1
|
2012-11-09 21:03:57 +01:00
|
|
|
|
2012-11-14 00:01:43 +01:00
|
|
|
try:
|
|
|
|
# Wait for the server to start up.
|
2012-11-16 16:56:15 +01:00
|
|
|
sys.stdout.write('Waiting for test server')
|
2012-11-14 00:01:43 +01:00
|
|
|
while not server_is_up():
|
2012-11-16 16:56:15 +01:00
|
|
|
sys.stdout.write('.')
|
|
|
|
sys.stdout.flush()
|
2012-11-14 00:01:43 +01:00
|
|
|
time.sleep(0.1)
|
2012-11-16 16:56:15 +01:00
|
|
|
sys.stdout.write('\n')
|
2012-11-09 21:03:57 +01:00
|
|
|
|
2013-05-21 23:09:08 +02:00
|
|
|
remote_debug = ""
|
|
|
|
if options.remote_debug:
|
|
|
|
remote_debug = "--remote-debugger-port=7777 --remote-debugger-autorun=yes"
|
|
|
|
cmd = "zephyr/tests/frontend/casperjs/bin/casperjs %s test " % (remote_debug,)
|
|
|
|
|
2013-03-05 17:24:37 +01:00
|
|
|
if test_files:
|
|
|
|
cmd += ' '.join(test_files)
|
|
|
|
else:
|
|
|
|
cmd += 'zephyr/tests/frontend/tests'
|
|
|
|
print "Running %s" % (cmd,)
|
|
|
|
ret = subprocess.call(cmd, shell=True)
|
2012-11-14 00:01:43 +01:00
|
|
|
finally:
|
2012-11-14 20:04:31 +01:00
|
|
|
assert_server_running()
|
2012-11-14 00:01:43 +01:00
|
|
|
server.terminate()
|
2012-11-09 21:03:57 +01:00
|
|
|
|
|
|
|
sys.exit(ret)
|