diff --git a/test/helpers/integration_test_helper.py b/test/helpers/integration_test_helper.py index 63c7b9a..7b3d24f 100644 --- a/test/helpers/integration_test_helper.py +++ b/test/helpers/integration_test_helper.py @@ -2,6 +2,7 @@ import os import requests import json + class IntegrationTestHelper: @classmethod @@ -20,11 +21,11 @@ class IntegrationTestHelper: @classmethod def execute_query(cls, sql_api_url, query): - query_url = "{0}&q={1}".format(sql_api_url, query) + query_url = "{0}?q={1}".format(sql_api_url, query) print "Executing query: {0}".format(query_url) query_response = requests.get(query_url) if query_response.status_code != 200: - raise Exception("Error executing SQL API query") + raise Exception(json.loads(query_response.text)['error']) query_response_data = json.loads(query_response.text) return query_response_data['rows'][0]['geometry'] diff --git a/test/integration/test_admin0_functions.py b/test/integration/test_admin0_functions.py index eac3c76..cb34171 100644 --- a/test/integration/test_admin0_functions.py +++ b/test/integration/test_admin0_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal +from nose.tools import assert_not_equal, assert_equal from ..helpers.integration_test_helper import IntegrationTestHelper @@ -8,7 +8,7 @@ class TestAdmin0Functions(TestCase): def setUp(self): self.env_variables = IntegrationTestHelper.get_environment_variables() - self.sql_api_url = "https://{0}.{1}/api/v2/sql?api_key={2}".format( + self.sql_api_url = "https://{0}.{1}/api/v2/sql".format( self.env_variables['username'], self.env_variables['host'], self.env_variables['api_key'] @@ -16,7 +16,17 @@ class TestAdmin0Functions(TestCase): def test_if_select_with_admin0_is_ok(self): query = "SELECT cdb_geocode_admin0_polygon(name) as geometry " \ - "FROM {0} LIMIT 1".format( - self.env_variables['table_name']) + "FROM {0} LIMIT 1&api_key={1}".format( + self.env_variables['table_name'], + self.env_variables['api_key']) geometry = IntegrationTestHelper.execute_query(self.sql_api_url, query) assert_not_equal(geometry, None) + + def test_if_select_with_admin0_without_api_key_raise_error(self): + query = "SELECT cdb_geocode_admin0_polygon(name) as geometry " \ + "FROM {0} LIMIT 1".format( + self.env_variables['table_name']) + try: + IntegrationTestHelper.execute_query(self.sql_api_url, query) + except Exception as e: + assert_equal(e.message[0], "The api_key must be provided")