From 22fdbd0f4eb895f5d3616ebc9c00098e7f760bcb Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Mon, 7 Nov 2016 10:33:15 +0100 Subject: [PATCH] Added schema option to define in the integration tests --- test/helpers/import_helper.py | 23 ++++++++++--------- test/helpers/integration_test_helper.py | 2 ++ test/integration/test_admin0_functions.py | 3 ++- test/integration/test_admin1_functions.py | 3 ++- .../test_data_observatory_functions.py | 3 ++- test/integration/test_ipaddress_functions.py | 3 ++- test/integration/test_isolines_functions.py | 3 ++- test/integration/test_namedplace_functions.py | 3 ++- test/integration/test_postalcode_functions.py | 3 ++- test/integration/test_routing_functions.py | 3 ++- test/integration/test_street_functions.py | 3 ++- test/run_tests.py | 20 +++++++++++----- 12 files changed, 46 insertions(+), 26 deletions(-) diff --git a/test/helpers/import_helper.py b/test/helpers/import_helper.py index d4cb69b..59f1b23 100644 --- a/test/helpers/import_helper.py +++ b/test/helpers/import_helper.py @@ -9,11 +9,11 @@ import time class ImportHelper: @classmethod - def import_test_dataset(cls, username, api_key, host): + def import_test_dataset(cls, username, api_key, host, schema): requests.packages.urllib3.disable_warnings() - url = "https://{0}.{1}/api/v1/imports/"\ - "?type_guessing=false&privacy=public&api_key={2}".format( - username, host, api_key) + url = "{0}://{1}.{2}/api/v1/imports/"\ + "?type_guessing=false&privacy=public&api_key={3}".format( + schema, username, host, api_key) dataset = { 'file': open('fixtures/geocoder_api_test_dataset.csv', 'rb')} response = requests.post(url, files=dataset) @@ -27,7 +27,8 @@ class ImportHelper: username, host, api_key, - response_json['item_queue_id'] + response_json['item_queue_id'], + schema ) if table_name: return table_name @@ -35,10 +36,10 @@ class ImportHelper: time.sleep(5) @classmethod - def get_imported_table_name(cls, username, host, api_key, import_id): + def get_imported_table_name(cls, username, host, api_key, import_id, schema): requests.packages.urllib3.disable_warnings() - import_url = "https://{0}.{1}/api/v1/imports/{2}?api_key={3}".format( - username, host, import_id, api_key) + import_url = "{0}://{1}.{2}/api/v1/imports/{3}?api_key={4}".format( + schema, username, host, import_id, api_key) import_data_response = requests.get(import_url) if import_data_response.status_code != 200: print "Error getting the table name from " \ @@ -49,10 +50,10 @@ class ImportHelper: return import_data_json['table_name'] @classmethod - def clean_test_dataset(cls, username, api_key, table_name, host): + def clean_test_dataset(cls, username, api_key, table_name, host, schema): requests.packages.urllib3.disable_warnings() - url = "https://{0}.{1}/api/v2/sql?q=drop table {2}&api_key={3}".format( - username, host, table_name, api_key + url = "{0}://{1}.{2}/api/v2/sql?q=drop table {3}&api_key={4}".format( + schema, username, host, table_name, api_key ) response = requests.get(url) if response.status_code != 200: diff --git a/test/helpers/integration_test_helper.py b/test/helpers/integration_test_helper.py index 537fd31..1c51533 100644 --- a/test/helpers/integration_test_helper.py +++ b/test/helpers/integration_test_helper.py @@ -10,11 +10,13 @@ class IntegrationTestHelper: username = os.environ["GEOCODER_API_TEST_USERNAME"] api_key = os.environ["GEOCODER_API_TEST_API_KEY"] host = os.environ["GEOCODER_API_TEST_HOST"] + schema = os.environ["GEOCODER_API_TEST_SCHEMA"] table_name = os.environ["GEOCODER_API_TEST_TABLE_NAME"] return { "username": username, "api_key": api_key, + "schema": schema, "host": host, "table_name": table_name } diff --git a/test/integration/test_admin0_functions.py b/test/integration/test_admin0_functions.py index 4393ee3..e6dbe27 100644 --- a/test/integration/test_admin0_functions.py +++ b/test/integration/test_admin0_functions.py @@ -8,7 +8,8 @@ class TestAdmin0Functions(TestCase): def setUp(self): self.env_variables = IntegrationTestHelper.get_environment_variables() - self.sql_api_url = "https://{0}.{1}/api/v1/sql".format( + self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format( + self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], self.env_variables['api_key'] diff --git a/test/integration/test_admin1_functions.py b/test/integration/test_admin1_functions.py index 703b071..0aca567 100644 --- a/test/integration/test_admin1_functions.py +++ b/test/integration/test_admin1_functions.py @@ -8,7 +8,8 @@ class TestAdmin1Functions(TestCase): def setUp(self): self.env_variables = IntegrationTestHelper.get_environment_variables() - self.sql_api_url = "https://{0}.{1}/api/v1/sql".format( + self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format( + self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], self.env_variables['api_key'] diff --git a/test/integration/test_data_observatory_functions.py b/test/integration/test_data_observatory_functions.py index 87d14b5..ab0ccd4 100644 --- a/test/integration/test_data_observatory_functions.py +++ b/test/integration/test_data_observatory_functions.py @@ -8,7 +8,8 @@ class TestDataObservatoryFunctions(TestCase): def setUp(self): self.env_variables = IntegrationTestHelper.get_environment_variables() - self.sql_api_url = "https://{0}.{1}/api/v1/sql".format( + self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format( + self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], self.env_variables['api_key'] diff --git a/test/integration/test_ipaddress_functions.py b/test/integration/test_ipaddress_functions.py index 29011a6..e257541 100644 --- a/test/integration/test_ipaddress_functions.py +++ b/test/integration/test_ipaddress_functions.py @@ -8,7 +8,8 @@ class TestPostalcodeFunctions(TestCase): def setUp(self): self.env_variables = IntegrationTestHelper.get_environment_variables() - self.sql_api_url = "https://{0}.{1}/api/v1/sql".format( + self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format( + self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], self.env_variables['api_key'] diff --git a/test/integration/test_isolines_functions.py b/test/integration/test_isolines_functions.py index 0949867..3e322d0 100644 --- a/test/integration/test_isolines_functions.py +++ b/test/integration/test_isolines_functions.py @@ -8,7 +8,8 @@ class TestIsolinesFunctions(TestCase): def setUp(self): self.env_variables = IntegrationTestHelper.get_environment_variables() - self.sql_api_url = "https://{0}.{1}/api/v1/sql".format( + self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format( + self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], self.env_variables['api_key'] diff --git a/test/integration/test_namedplace_functions.py b/test/integration/test_namedplace_functions.py index a091422..008b6e4 100644 --- a/test/integration/test_namedplace_functions.py +++ b/test/integration/test_namedplace_functions.py @@ -8,7 +8,8 @@ class TestNameplaceFunctions(TestCase): def setUp(self): self.env_variables = IntegrationTestHelper.get_environment_variables() - self.sql_api_url = "https://{0}.{1}/api/v1/sql".format( + self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format( + self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], self.env_variables['api_key'] diff --git a/test/integration/test_postalcode_functions.py b/test/integration/test_postalcode_functions.py index 6e50c5c..942758d 100644 --- a/test/integration/test_postalcode_functions.py +++ b/test/integration/test_postalcode_functions.py @@ -8,7 +8,8 @@ class TestPostalcodeFunctions(TestCase): def setUp(self): self.env_variables = IntegrationTestHelper.get_environment_variables() - self.sql_api_url = "https://{0}.{1}/api/v1/sql".format( + self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format( + self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], self.env_variables['api_key'] diff --git a/test/integration/test_routing_functions.py b/test/integration/test_routing_functions.py index e9d2629..6d38e00 100644 --- a/test/integration/test_routing_functions.py +++ b/test/integration/test_routing_functions.py @@ -8,7 +8,8 @@ class TestRoutingFunctions(TestCase): def setUp(self): self.env_variables = IntegrationTestHelper.get_environment_variables() - self.sql_api_url = "https://{0}.{1}/api/v1/sql".format( + self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format( + self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], self.env_variables['api_key'] diff --git a/test/integration/test_street_functions.py b/test/integration/test_street_functions.py index 7edda67..0672425 100644 --- a/test/integration/test_street_functions.py +++ b/test/integration/test_street_functions.py @@ -8,7 +8,8 @@ class TestStreetFunctions(TestCase): def setUp(self): self.env_variables = IntegrationTestHelper.get_environment_variables() - self.sql_api_url = "https://{0}.{1}/api/v1/sql".format( + self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format( + self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], self.env_variables['api_key'] diff --git a/test/run_tests.py b/test/run_tests.py index d3bb62b..61dc3ef 100644 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -8,12 +8,13 @@ from helpers.import_helper import ImportHelper def main(): - opts, args = getopt.getopt(sys.argv[1:], "h", ["help", "host="]) + opts, args = getopt.getopt(sys.argv[1:], "h", ["help", "host=", "schema="]) if len(args) < 2: usage() sys.exit() + schema = "https" host = "cartodb.com" username = args[0] api_key = args[1] @@ -24,26 +25,31 @@ def main(): sys.exit() elif o in ("--host"): host = opts[0][1] + elif o in ("--schema"): + schema = opts[1][1] else: assert False, "unhandled option" try: - table_name = ImportHelper.import_test_dataset(username, api_key, host) - set_environment_variables(username, api_key, table_name, host) + table_name = ImportHelper.import_test_dataset(username, api_key, host, + schema) + set_environment_variables(username, api_key, table_name, host, schema) execute_tests() except Exception as e: print e.message sys.exit(1) finally: clean_environment_variables() - ImportHelper.clean_test_dataset(username, api_key, table_name, host) + ImportHelper.clean_test_dataset(username, api_key, table_name, host, + schema) def usage(): print """Usage: run_tests.py [options] username api_key Options: -h: Show this help - --host: take that host as base (by default is cartodb.com)""" + --host: take that host as base (by default is cartodb.com) + --schema: define the url schema [http/https] (by default https)""" def execute_tests(): @@ -59,11 +65,12 @@ def execute_tests(): sys.exit(1) -def set_environment_variables(username, api_key, table_name, host): +def set_environment_variables(username, api_key, table_name, host, schema): 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 + os.environ["GEOCODER_API_TEST_SCHEMA"] = schema def clean_environment_variables(): @@ -71,6 +78,7 @@ def clean_environment_variables(): del os.environ["GEOCODER_API_TEST_API_KEY"] del os.environ["GEOCODER_API_TEST_TABLE_NAME"] del os.environ["GEOCODER_API_TEST_HOST"] + del os.environ["GEOCODER_API_TEST_SCHEMA"] if __name__ == "__main__": main()