2015-12-06 20:10:54 +08:00
|
|
|
import os
|
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
|
2015-12-06 20:30:15 +08:00
|
|
|
|
2015-12-06 20:10:54 +08:00
|
|
|
class IntegrationTestHelper:
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_environment_variables(cls):
|
|
|
|
username = os.environ["GEOCODER_API_TEST_USERNAME"]
|
|
|
|
api_key = os.environ["GEOCODER_API_TEST_API_KEY"]
|
|
|
|
host = os.environ["GEOCODER_API_TEST_HOST"]
|
2016-11-07 17:33:15 +08:00
|
|
|
schema = os.environ["GEOCODER_API_TEST_SCHEMA"]
|
2015-12-06 20:10:54 +08:00
|
|
|
table_name = os.environ["GEOCODER_API_TEST_TABLE_NAME"]
|
|
|
|
|
|
|
|
return {
|
|
|
|
"username": username,
|
|
|
|
"api_key": api_key,
|
2016-11-07 17:33:15 +08:00
|
|
|
"schema": schema,
|
2015-12-06 20:10:54 +08:00
|
|
|
"host": host,
|
|
|
|
"table_name": table_name
|
|
|
|
}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def execute_query(cls, sql_api_url, query):
|
2015-12-09 19:11:50 +08:00
|
|
|
requests.packages.urllib3.disable_warnings()
|
2015-12-06 20:30:15 +08:00
|
|
|
query_url = "{0}?q={1}".format(sql_api_url, query)
|
2015-12-06 20:10:54 +08:00
|
|
|
print "Executing query: {0}".format(query_url)
|
|
|
|
query_response = requests.get(query_url)
|
|
|
|
if query_response.status_code != 200:
|
2015-12-06 20:30:15 +08:00
|
|
|
raise Exception(json.loads(query_response.text)['error'])
|
2015-12-06 20:10:54 +08:00
|
|
|
query_response_data = json.loads(query_response.text)
|
|
|
|
|
2016-02-24 16:54:00 +08:00
|
|
|
return query_response_data['rows'][0]
|