2015-12-06 20:10:54 +08:00
|
|
|
import getopt
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import subprocess
|
|
|
|
import os
|
2015-12-09 20:13:24 +08:00
|
|
|
import re
|
2015-12-06 22:01:46 +08:00
|
|
|
from helpers.import_helper import ImportHelper
|
2015-12-06 20:10:54 +08:00
|
|
|
|
2015-12-04 23:58:28 +08:00
|
|
|
|
|
|
|
def main():
|
2016-11-07 17:33:15 +08:00
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "h", ["help", "host=", "schema="])
|
2015-12-04 23:58:28 +08:00
|
|
|
|
|
|
|
if len(args) < 2:
|
2015-12-06 20:10:54 +08:00
|
|
|
usage()
|
|
|
|
sys.exit()
|
2015-12-04 23:58:28 +08:00
|
|
|
|
2016-11-07 17:33:15 +08:00
|
|
|
schema = "https"
|
2015-12-04 23:58:28 +08:00
|
|
|
host = "cartodb.com"
|
|
|
|
username = args[0]
|
|
|
|
api_key = args[1]
|
|
|
|
table_name = "geocoder_api_test_dataset_".format(int(time.time()))
|
|
|
|
for o, a in opts:
|
|
|
|
if o in ("-h", "--help"):
|
|
|
|
usage()
|
|
|
|
sys.exit()
|
|
|
|
elif o in ("--host"):
|
2015-12-06 20:10:54 +08:00
|
|
|
host = opts[0][1]
|
2016-11-07 17:33:15 +08:00
|
|
|
elif o in ("--schema"):
|
|
|
|
schema = opts[1][1]
|
2015-12-04 23:58:28 +08:00
|
|
|
else:
|
|
|
|
assert False, "unhandled option"
|
|
|
|
|
|
|
|
try:
|
2016-11-07 17:33:15 +08:00
|
|
|
table_name = ImportHelper.import_test_dataset(username, api_key, host,
|
|
|
|
schema)
|
|
|
|
set_environment_variables(username, api_key, table_name, host, schema)
|
2015-12-06 20:10:54 +08:00
|
|
|
execute_tests()
|
2015-12-06 22:01:46 +08:00
|
|
|
except Exception as e:
|
|
|
|
print e.message
|
|
|
|
sys.exit(1)
|
2015-12-04 23:58:28 +08:00
|
|
|
finally:
|
2015-12-06 20:10:54 +08:00
|
|
|
clean_environment_variables()
|
2016-11-07 17:33:15 +08:00
|
|
|
ImportHelper.clean_test_dataset(username, api_key, table_name, host,
|
|
|
|
schema)
|
2015-12-06 20:10:54 +08:00
|
|
|
|
2015-12-04 23:58:28 +08:00
|
|
|
|
|
|
|
def usage():
|
2015-12-06 20:10:54 +08:00
|
|
|
print """Usage: run_tests.py [options] username api_key
|
2015-12-04 23:58:28 +08:00
|
|
|
Options:
|
|
|
|
-h: Show this help
|
2016-11-07 17:33:15 +08:00
|
|
|
--host: take that host as base (by default is cartodb.com)
|
|
|
|
--schema: define the url schema [http/https] (by default https)"""
|
2015-12-06 20:10:54 +08:00
|
|
|
|
2015-12-04 23:58:28 +08:00
|
|
|
|
|
|
|
def execute_tests():
|
2015-12-09 20:13:24 +08:00
|
|
|
process = subprocess.Popen(
|
|
|
|
["nosetests", "--where=integration/"],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE
|
|
|
|
)
|
|
|
|
out, err = process.communicate()
|
|
|
|
print err
|
|
|
|
regexp = re.compile(r'FAILED \(.*\)')
|
|
|
|
if regexp.search(err) is not None:
|
|
|
|
sys.exit(1)
|
2015-12-06 20:10:54 +08:00
|
|
|
|
2015-12-04 23:58:28 +08:00
|
|
|
|
2016-11-07 17:33:15 +08:00
|
|
|
def set_environment_variables(username, api_key, table_name, host, schema):
|
2015-12-06 20:10:54 +08:00
|
|
|
os.environ["GEOCODER_API_TEST_USERNAME"] = username
|
|
|
|
os.environ["GEOCODER_API_TEST_API_KEY"] = api_key
|
|
|
|
os.environ["GEOCODER_API_TEST_TABLE_NAME"] = table_name
|
|
|
|
os.environ["GEOCODER_API_TEST_HOST"] = host
|
2016-11-07 17:33:15 +08:00
|
|
|
os.environ["GEOCODER_API_TEST_SCHEMA"] = schema
|
2015-12-06 20:10:54 +08:00
|
|
|
|
2015-12-04 23:58:28 +08:00
|
|
|
|
|
|
|
def clean_environment_variables():
|
2018-06-26 16:56:14 +08:00
|
|
|
os.environ.pop("GEOCODER_API_TEST_USERNAME", None)
|
|
|
|
os.environ.pop("GEOCODER_API_TEST_API_KEY", None)
|
|
|
|
os.environ.pop("GEOCODER_API_TEST_TABLE_NAME", None)
|
|
|
|
os.environ.pop("GEOCODER_API_TEST_HOST", None)
|
|
|
|
os.environ.pop("GEOCODER_API_TEST_SCHEMA", None)
|
2015-12-06 20:10:54 +08:00
|
|
|
|
2015-12-04 23:58:28 +08:00
|
|
|
if __name__ == "__main__":
|
2015-12-06 20:10:54 +08:00
|
|
|
main()
|