From a57500c966af897abf66846af4193a35c546d5fd Mon Sep 17 00:00:00 2001 From: antoniocarlon Date: Thu, 13 Sep 2018 16:01:53 +0200 Subject: [PATCH 1/5] Fixed tests --- test/integration/test_admin0_functions.py | 5 +- test/integration/test_admin1_functions.py | 15 +++-- .../test_data_observatory_functions.py | 55 +++++++++---------- test/integration/test_ipaddress_functions.py | 11 ++-- test/integration/test_isolines_functions.py | 7 +-- test/integration/test_namedplace_functions.py | 19 +++---- test/integration/test_postalcode_functions.py | 15 +++-- test/integration/test_routing_functions.py | 12 ++-- test/integration/test_street_functions.py | 3 +- 9 files changed, 67 insertions(+), 75 deletions(-) diff --git a/test/integration/test_admin0_functions.py b/test/integration/test_admin0_functions.py index e6dbe27..9d3dd79 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, assert_equal +from nose.tools import assert_not_equal, assert_true from ..helpers.integration_test_helper import IntegrationTestHelper @@ -12,7 +12,6 @@ class TestAdmin0Functions(TestCase): self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], - self.env_variables['api_key'] ) def test_if_select_with_admin0_is_ok(self): @@ -29,4 +28,4 @@ class TestAdmin0Functions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Geocoding permission denied", "function cdb_geocode_admin0_polygon(text) does not exist"]) diff --git a/test/integration/test_admin1_functions.py b/test/integration/test_admin1_functions.py index 0aca567..edfe19e 100644 --- a/test/integration/test_admin1_functions.py +++ b/test/integration/test_admin1_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal, assert_equal +from nose.tools import assert_not_equal, assert_true from ..helpers.integration_test_helper import IntegrationTestHelper @@ -12,30 +12,29 @@ class TestAdmin1Functions(TestCase): self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], - self.env_variables['api_key'] ) def test_if_select_with_admin1_without_country_is_ok(self): query = "SELECT cdb_geocode_admin1_polygon(province) as geometry " \ "FROM {0} LIMIT 1&api_key={1}".format( - self.env_variables['table_name'], - self.env_variables['api_key']) + self.env_variables['table_name'], + self.env_variables['api_key']) geometry = IntegrationTestHelper.execute_query(self.sql_api_url, query) assert_not_equal(geometry['geometry'], None) def test_if_select_with_admin1_with_country_is_ok(self): query = "SELECT cdb_geocode_admin1_polygon(province,country)" \ "as geometry FROM {0} LIMIT 1&api_key={1}".format( - self.env_variables['table_name'], - self.env_variables['api_key']) + self.env_variables['table_name'], + self.env_variables['api_key']) geometry = IntegrationTestHelper.execute_query(self.sql_api_url, query) assert_not_equal(geometry['geometry'], None) def test_if_select_with_admin1_without_api_key_raise_error(self): query = "SELECT cdb_geocode_admin1_polygon(province) as geometry " \ "FROM {0} LIMIT 1".format( - self.env_variables['table_name']) + 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") + assert_true(e.message[0] in ["Geocoding permission denied", "function cdb_geocode_admin1_polygon(text) does not exist"]) diff --git a/test/integration/test_data_observatory_functions.py b/test/integration/test_data_observatory_functions.py index 105483f..00e916b 100644 --- a/test/integration/test_data_observatory_functions.py +++ b/test/integration/test_data_observatory_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal, assert_equal +from nose.tools import assert_not_equal, assert_true from ..helpers.integration_test_helper import IntegrationTestHelper @@ -12,7 +12,6 @@ class TestDataObservatoryFunctions(TestCase): self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], - self.env_variables['api_key'] ) def test_if_get_demographic_snapshot_is_ok(self): @@ -25,7 +24,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getdemographicsnapshot(geometry) does not exist"]) def test_if_get_segment_snapshot_is_ok(self): query = "SELECT OBS_GetSegmentSnapshot(CDB_LatLng(40.704512, -73.936669)) as snapshot;&api_key={0}".format(self.env_variables['api_key']) @@ -37,7 +36,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getsegmentsnapshot(geometry) does not exist"]) def test_if_get_measure_with_point_is_ok(self): query = "SELECT OBS_GetMeasure(CDB_LatLng(40.704512, -73.936669), 'us.census.acs.B01003001') as measure;&api_key={0}".format(self.env_variables['api_key']) @@ -54,7 +53,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getmeasure(geometry, unknown) does not exist"]) def test_if_get_measure_by_id_ok(self): query = "SELECT OBS_GetMeasureById('36047048500', 'us.census.acs.B01003001', 'us.census.tiger.census_tract', '2010 - 2014') as measure;&api_key={0}".format(self.env_variables['api_key']) @@ -66,7 +65,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getmeasurebyid(unknown, unknown, unknown, unknown) does not exist"]) def test_if_get_category_is_ok(self): query = "SELECT OBS_GetCategory(CDB_LatLng(40.704512, -73.936669), 'us.census.spielman_singleton_segments.X10', 'us.census.tiger.census_tract', '2010 - 2014') as category;&api_key={0}".format(self.env_variables['api_key']) @@ -78,7 +77,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getcategory(geometry, unknown, unknown, unknown) does not exist"]) def test_if_get_us_census_measure_with_point_is_ok(self): query = "SELECT OBS_GetUSCensusMeasure(CDB_LatLng(40.704512, -73.936669), 'male population') as measure;&api_key={0}".format(self.env_variables['api_key']) @@ -95,7 +94,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getuscensusmeasure(geometry, unknown) does not exist"]) def test_if_get_us_census_category_is_ok(self): query = "SELECT OBS_GetUSCensusCategory('0103000020E61000000100000021000000BB366F6D917B52C0E7BB6EA82B5A444067224C85937B52C0810205E70E5A4440596D6342997B52C09BED2952F35944400A96386CA27B52C07B6D31F9D95944402B81A0A8AE7B52C0D16B73D5C3594440C34C397FBD7B52C0D8B5B7C0B1594440CFD90A5ECE7B52C0BE8DD86CA45944405C7E229FE07B52C0A904EE5C9C59444017C1F28EF37B52C05E2745E099594440AE8A3873067C52C0FD62540F9D5944402F272292187C52C05502CBCAA5594440C3F17139297C52C0B3FBC4BCB3594440DDAE56C5377C52C00C46175CC6594440E96AB6A6437C52C0355C94F1DC5944402313AE684C7C52C05340159FF6594440B3B90FB5517C52C031F30168125A44407F43B357537C52C0DF95053B2F5A444059C17840517C52C0D9E08EFC4B5A44406580E8834B7C52C046B5B591675A444035736A5A427C52C0AF9A1AEB805A44402E721C1E367C52C0D226550F975A4440506D5C47277C52C0A2968A24A95A4440507C2868167C52C0D51FCE78B65A4440C4438226047C52C02369F888BE5A4440C9F10C36F17B52C027B1B205C15A4440AABE2451DE7B52C0F5E383D6BD5A44402A18B431CC7B52C01785C11AB55A444018320D8ABB7B52C070265B28A75A4440E28A0EFEAC7B52C09E518C88945A44401D08D61CA17B52C09E8195F27D5A4440D7C3405B987B52C0643CB044645A444047B16D0F937B52C04EC9837B485A4440BB366F6D917B52C0E7BB6EA82B5A4440'::geometry, 'Spielman-Singleton Segments: 10 Clusters') as category;&api_key={0}".format(self.env_variables['api_key']) @@ -107,7 +106,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getuscensuscategory(geometry, unknown) does not exist"]) def test_if_get_population_is_ok(self): query = "SELECT OBS_GetPopulation(CDB_LatLng(40.704512, -73.936669)) as population;&api_key={0}".format(self.env_variables['api_key']) @@ -119,7 +118,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getpopulation(geometry) does not exist"]) def test_if_obs_search_is_ok(self): sql = "SELECT id FROM OBS_Search('total_pop') WHERE id LIKE 'es.ine%' LIMIT 1;" @@ -133,7 +132,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_search(unknown) does not exist"]) def test_if_obs_get_available_boundaries_is_ok(self): query = "SELECT boundary_id FROM OBS_GetAvailableBoundaries(CDB_LatLng(40.704512, -73.936669)) LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -145,7 +144,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getavailableboundaries(geometry) does not exist"]) def test_if_obs_get_boundary_is_ok(self): query = "SELECT OBS_GetBoundary(CDB_LatLng(40.704512, -73.936669), 'us.census.tiger.census_tract') as boundary;&api_key={0}".format(self.env_variables['api_key']) @@ -157,7 +156,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getboundary(geometry, unknown) does not exist"]) def test_if_obs_get_boundary_id_is_ok(self): query = "SELECT OBS_GetBoundaryId(CDB_LatLng(40.704512, -73.936669), 'us.census.tiger.census_tract', '2015') as boundary_id;&api_key={0}".format(self.env_variables['api_key']) @@ -169,7 +168,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getboundaryid(geometry, unknown, unknown) does not exist"]) def test_if_obs_get_boundary_by_id_is_ok(self): query = "SELECT OBS_GetBoundaryById('36047', 'us.census.tiger.county', '2014') as boundary;&api_key={0}".format(self.env_variables['api_key']) @@ -181,7 +180,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getboundarybyid(unknown, unknown, unknown) does not exist"]) def test_if_obs_get_boundaries_by_geometry_is_ok(self): query = "SELECT geom_refs FROM OBS_GetBoundariesByGeometry(ST_MakeEnvelope(-73.9452409744,40.6988851644,-73.9280319214,40.7101254524,4326), 'us.census.tiger.census_tract') ORDER BY geom_refs ASC LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -193,7 +192,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getboundariesbygeometry(geometry, unknown) does not exist"]) def test_if_obs_get_boundaries_by_point_and_radius_is_ok(self): query = "SELECT geom_refs FROM OBS_GetBoundariesByPointAndRadius(CDB_LatLng(40.704512, -73.936669), 500, 'us.census.tiger.census_tract') ORDER BY geom_refs ASC LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -205,7 +204,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getboundariesbypointandradius(geometry, integer, unknown) does not exist"]) def test_if_obs_get_points_by_geometry_is_ok(self): query = "SELECT geom_refs FROM OBS_GetPointsByGeometry(ST_MakeEnvelope(-73.9452409744,40.6988851644,-73.9280319214,40.7101254524,4326), 'us.census.tiger.census_tract') ORDER BY geom_refs ASC LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -217,7 +216,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getpointsbygeometry(geometry, unknown) does not exist"]) def test_if_obs_get_points_by_point_and_radius_is_ok(self): query = "SELECT geom_refs FROM OBS_GetPointsByPointAndRadius(CDB_LatLng(40.704512, -73.936669), 500, 'us.census.tiger.census_tract', '2014') ORDER BY geom_refs ASC LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -229,19 +228,19 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getpointsbypointandradius(geometry, integer, unknown, unknown) does not exist"]) def test_if_obs_get_legacy_builder_metadata_is_ok(self): query = "SELECT name FROM OBS_LegacyBuilderMetadata() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) result = IntegrationTestHelper.execute_query(self.sql_api_url, query) assert_not_equal(result['name'], None) - def test_if_obs_get_points_by_point_and_radius_without_api_key_raise_error(self): + def test_if_legacy_builder_metadata_without_api_key_raise_error(self): query = "SELECT name FROM OBS_LegacyBuilderMetadata() LIMIT 1;" try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_legacybuildermetadata() does not exist"]) def test_if_obs_get_available_numerators_is_ok(self): query = "SELECT numer_id FROM OBS_GetAvailableNumerators() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -253,7 +252,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getavailablenumerators() does not exist"]) def test_if_obs_get_available_denominators_is_ok(self): query = "SELECT denom_id FROM OBS_GetAvailableDenominators() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -265,7 +264,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getavailabledenominators() does not exist"]) def test_if_obs_get_available_geometries_is_ok(self): query = "SELECT geom_id FROM OBS_GetAvailableGeometries() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -277,7 +276,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getavailablegeometries() does not exist"]) def test_if_obs_get_available_timespans_is_ok(self): query = "SELECT timespan_id FROM OBS_GetAvailableTimespans() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -289,7 +288,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getavailabletimespans() does not exist"]) def test_if_obs_get_meta_is_ok(self): params = '\'[{\"numer_id\": \"us.census.acs.B01003001\"}]\'' @@ -303,7 +302,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getmeta(geometry, unknown, integer, integer, integer) does not exist"]) def test_if_obs_get_data_is_ok(self): params_1 = '\'[{\"numer_id\": \"us.census.acs.B01003001\", \"geom_id\": \"us.census.tiger.county\"}]\'' @@ -323,8 +322,8 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query_1) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getmeta(geometry, unknown, integer, integer, integer) does not exist"]) try: IntegrationTestHelper.execute_query(self.sql_api_url, query_2) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Observatory permission denied", "function obs_getmeta(geometry, unknown) does not exist"]) diff --git a/test/integration/test_ipaddress_functions.py b/test/integration/test_ipaddress_functions.py index e257541..5a06916 100644 --- a/test/integration/test_ipaddress_functions.py +++ b/test/integration/test_ipaddress_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal, assert_equal +from nose.tools import assert_not_equal, assert_true from ..helpers.integration_test_helper import IntegrationTestHelper @@ -12,22 +12,21 @@ class TestPostalcodeFunctions(TestCase): self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], - self.env_variables['api_key'] ) def test_if_select_with_ipaddress_point_is_ok(self): query = "SELECT cdb_geocode_ipaddress_point(ip) " \ "as geometry FROM {0} LIMIT 1&api_key={1}".format( - self.env_variables['table_name'], - self.env_variables['api_key']) + self.env_variables['table_name'], + self.env_variables['api_key']) geometry = IntegrationTestHelper.execute_query(self.sql_api_url, query) assert_not_equal(geometry['geometry'], None) def test_if_select_with_ipaddress_without_api_key_raise_error(self): query = "SELECT cdb_geocode_ipaddress_point(ip) " \ "as geometry FROM {0} LIMIT 1".format( - self.env_variables['table_name']) + 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") + assert_true(e.message[0] in ["Geocoding permission denied", "function cdb_geocode_ipaddress_point(text) does not exist"]) diff --git a/test/integration/test_isolines_functions.py b/test/integration/test_isolines_functions.py index 3e322d0..6622b40 100644 --- a/test/integration/test_isolines_functions.py +++ b/test/integration/test_isolines_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal, assert_equal +from nose.tools import assert_not_equal, assert_true from ..helpers.integration_test_helper import IntegrationTestHelper @@ -12,7 +12,6 @@ class TestIsolinesFunctions(TestCase): self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], - self.env_variables['api_key'] ) def test_if_select_with_isochrones_is_ok(self): @@ -28,7 +27,7 @@ class TestIsolinesFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Isolines permission denied", "function cdb_isochrone(geometry, unknown, integer[]) does not exist"]) def test_if_select_with_isodistance_is_ok(self): query = "SELECT * FROM cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, " \ @@ -43,4 +42,4 @@ class TestIsolinesFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Isolines permission denied", "function cdb_isodistance(geometry, unknown, integer[]) does not exist"]) diff --git a/test/integration/test_namedplace_functions.py b/test/integration/test_namedplace_functions.py index 008b6e4..6ed87d4 100644 --- a/test/integration/test_namedplace_functions.py +++ b/test/integration/test_namedplace_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal, assert_equal +from nose.tools import assert_not_equal, assert_true from ..helpers.integration_test_helper import IntegrationTestHelper @@ -12,38 +12,37 @@ class TestNameplaceFunctions(TestCase): self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], - self.env_variables['api_key'] ) def test_if_select_with_namedplace_city_is_ok(self): query = "SELECT cdb_geocode_namedplace_point(city) as geometry " \ "FROM {0} LIMIT 1&api_key={1}".format( - self.env_variables['table_name'], - self.env_variables['api_key']) + self.env_variables['table_name'], + self.env_variables['api_key']) geometry = IntegrationTestHelper.execute_query(self.sql_api_url, query) assert_not_equal(geometry['geometry'], None) def test_if_select_with_namedplace_city_country_is_ok(self): query = "SELECT cdb_geocode_namedplace_point(city,country) " \ "as geometry FROM {0} LIMIT 1&api_key={1}".format( - self.env_variables['table_name'], - self.env_variables['api_key']) + self.env_variables['table_name'], + self.env_variables['api_key']) geometry = IntegrationTestHelper.execute_query(self.sql_api_url, query) assert_not_equal(geometry['geometry'], None) def test_if_select_with_namedplace_city_province_country_is_ok(self): query = "SELECT cdb_geocode_namedplace_point(city,province,country) " \ "as geometry FROM {0} LIMIT 1&api_key={1}".format( - self.env_variables['table_name'], - self.env_variables['api_key']) + self.env_variables['table_name'], + self.env_variables['api_key']) geometry = IntegrationTestHelper.execute_query(self.sql_api_url, query) assert_not_equal(geometry['geometry'], None) def test_if_select_with_namedplace_without_api_key_raise_error(self): query = "SELECT cdb_geocode_namedplace_point(city) as geometry " \ "FROM {0} LIMIT 1".format( - self.env_variables['table_name']) + 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") + assert_true(e.message[0] in ["Geocoding permission denied", "function cdb_geocode_namedplace_point(text) does not exist"]) diff --git a/test/integration/test_postalcode_functions.py b/test/integration/test_postalcode_functions.py index 942758d..909d4a3 100644 --- a/test/integration/test_postalcode_functions.py +++ b/test/integration/test_postalcode_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal, assert_equal +from nose.tools import assert_not_equal, assert_true from ..helpers.integration_test_helper import IntegrationTestHelper @@ -12,30 +12,29 @@ class TestPostalcodeFunctions(TestCase): self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], - self.env_variables['api_key'] ) def test_if_select_with_postalcode_polygon_is_ok(self): query = "SELECT cdb_geocode_postalcode_polygon(postalcode, country) " \ "as geometry FROM {0} WHERE country='USA'&api_key={1}".format( - self.env_variables['table_name'], - self.env_variables['api_key']) + self.env_variables['table_name'], + self.env_variables['api_key']) geometry = IntegrationTestHelper.execute_query(self.sql_api_url, query) assert_not_equal(geometry['geometry'], None) def test_if_select_with_postalcode_point_is_ok(self): query = "SELECT cdb_geocode_postalcode_point(postalcode, country) " \ "as geometry FROM {0} WHERE country='Spain'&api_key={1}".format( - self.env_variables['table_name'], - self.env_variables['api_key']) + self.env_variables['table_name'], + self.env_variables['api_key']) geometry = IntegrationTestHelper.execute_query(self.sql_api_url, query) assert_not_equal(geometry['geometry'], None) def test_if_select_with_postalcode_without_api_key_raise_error(self): query = "SELECT cdb_geocode_postalcode_polygon(postalcode, country) " \ "as geometry FROM {0} WHERE country = 'USA'".format( - self.env_variables['table_name']) + 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") + assert_true(e.message[0] in ["Geocoding permission denied", "function cdb_geocode_postalcode_polygon(text, text) does not exist"]) \ No newline at end of file diff --git a/test/integration/test_routing_functions.py b/test/integration/test_routing_functions.py index 6d38e00..d6a9ea9 100644 --- a/test/integration/test_routing_functions.py +++ b/test/integration/test_routing_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal, assert_equal +from nose.tools import assert_not_equal, assert_true from ..helpers.integration_test_helper import IntegrationTestHelper @@ -12,7 +12,6 @@ class TestRoutingFunctions(TestCase): self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], - self.env_variables['api_key'] ) def test_if_select_with_routing_point_to_point_is_ok(self): @@ -32,7 +31,7 @@ class TestRoutingFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Routing permission denied", "function cdb_route_point_to_point(geometry, geometry, unknown, text[]) does not exist"]) def test_if_select_with_routing_with_waypoints_is_ok(self): query = "SELECT duration, length, shape as the_geom " \ @@ -46,11 +45,12 @@ class TestRoutingFunctions(TestCase): def test_if_select_with_routing_with_waypoints_without_api_key_raise_error(self): query = "SELECT duration, length, shape as the_geom " \ - "FROM cdb_route_with_waypoints(Array['POINT(-3.7109 40.4234)'::GEOMETRY, "\ + "FROM cdb_route_with_waypoints(Array['POINT(-3.7109 40.4234)'::geometry, "\ "'POINT(-3.7059 40.4203)'::geometry, 'POINT(-3.7046 40.4180)'::geometry]" \ "::geometry[], 'car', " \ - "ARRAY['mode_type=shortest']::text[])&api_key={0}" + "ARRAY['mode_type=shortest']::text[])&api_key={0}".format( + self.env_variables['api_key']) try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_equal(e.message[0], "The api_key must be provided") + assert_true(e.message[0] in ["Routing permission denied", "function cdb_route_with_waypoints(geometry, geometry, text, text[]) does not exist"]) diff --git a/test/integration/test_street_functions.py b/test/integration/test_street_functions.py index b7557c9..fd1b983 100644 --- a/test/integration/test_street_functions.py +++ b/test/integration/test_street_functions.py @@ -110,7 +110,6 @@ class TestStreetFunctionsSetUp(TestCase): self.env_variables['schema'], self.env_variables['username'], self.env_variables['host'], - self.env_variables['api_key'] ) if not self.fixture_points: @@ -123,7 +122,6 @@ class TestStreetFunctionsSetUp(TestCase): self.metadata = self.METADATAS[provider] - def _run_authenticated(self, query): authenticated_query = "{}&api_key={}".format(query, self.env_variables[ @@ -137,6 +135,7 @@ class TestStreetFunctionsSetUp(TestCase): "where service = 'hires_geocoder'" return self._run_authenticated(query)['rows'][0]['used_quota'] + class TestStreetFunctions(TestStreetFunctionsSetUp): def test_if_select_with_street_point_is_ok(self): From 4598d5ed7df56d164c59aa0a9e332e7f5be8378f Mon Sep 17 00:00:00 2001 From: antoniocarlon Date: Fri, 14 Sep 2018 10:14:59 +0200 Subject: [PATCH 2/5] Added CR suggestion --- test/integration/test_admin0_functions.py | 4 +- test/integration/test_admin1_functions.py | 4 +- .../test_data_observatory_functions.py | 52 +++++++++---------- test/integration/test_ipaddress_functions.py | 4 +- test/integration/test_isolines_functions.py | 6 +-- test/integration/test_namedplace_functions.py | 4 +- test/integration/test_postalcode_functions.py | 4 +- test/integration/test_routing_functions.py | 6 +-- 8 files changed, 42 insertions(+), 42 deletions(-) diff --git a/test/integration/test_admin0_functions.py b/test/integration/test_admin0_functions.py index 9d3dd79..7e98abe 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, assert_true +from nose.tools import assert_not_equal, assert_in from ..helpers.integration_test_helper import IntegrationTestHelper @@ -28,4 +28,4 @@ class TestAdmin0Functions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Geocoding permission denied", "function cdb_geocode_admin0_polygon(text) does not exist"]) + assert_in(e.message[0], ["Geocoding permission denied", "function cdb_geocode_admin0_polygon(text) does not exist"]) diff --git a/test/integration/test_admin1_functions.py b/test/integration/test_admin1_functions.py index edfe19e..92ffb41 100644 --- a/test/integration/test_admin1_functions.py +++ b/test/integration/test_admin1_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal, assert_true +from nose.tools import assert_not_equal, assert_in from ..helpers.integration_test_helper import IntegrationTestHelper @@ -37,4 +37,4 @@ class TestAdmin1Functions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Geocoding permission denied", "function cdb_geocode_admin1_polygon(text) does not exist"]) + assert_in(e.message[0], ["Geocoding permission denied", "function cdb_geocode_admin1_polygon(text) does not exist"]) diff --git a/test/integration/test_data_observatory_functions.py b/test/integration/test_data_observatory_functions.py index 00e916b..661678a 100644 --- a/test/integration/test_data_observatory_functions.py +++ b/test/integration/test_data_observatory_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal, assert_true +from nose.tools import assert_not_equal, assert_in from ..helpers.integration_test_helper import IntegrationTestHelper @@ -24,7 +24,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getdemographicsnapshot(geometry) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getdemographicsnapshot(geometry) does not exist"]) def test_if_get_segment_snapshot_is_ok(self): query = "SELECT OBS_GetSegmentSnapshot(CDB_LatLng(40.704512, -73.936669)) as snapshot;&api_key={0}".format(self.env_variables['api_key']) @@ -36,7 +36,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getsegmentsnapshot(geometry) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getsegmentsnapshot(geometry) does not exist"]) def test_if_get_measure_with_point_is_ok(self): query = "SELECT OBS_GetMeasure(CDB_LatLng(40.704512, -73.936669), 'us.census.acs.B01003001') as measure;&api_key={0}".format(self.env_variables['api_key']) @@ -53,7 +53,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getmeasure(geometry, unknown) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getmeasure(geometry, unknown) does not exist"]) def test_if_get_measure_by_id_ok(self): query = "SELECT OBS_GetMeasureById('36047048500', 'us.census.acs.B01003001', 'us.census.tiger.census_tract', '2010 - 2014') as measure;&api_key={0}".format(self.env_variables['api_key']) @@ -65,7 +65,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getmeasurebyid(unknown, unknown, unknown, unknown) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getmeasurebyid(unknown, unknown, unknown, unknown) does not exist"]) def test_if_get_category_is_ok(self): query = "SELECT OBS_GetCategory(CDB_LatLng(40.704512, -73.936669), 'us.census.spielman_singleton_segments.X10', 'us.census.tiger.census_tract', '2010 - 2014') as category;&api_key={0}".format(self.env_variables['api_key']) @@ -77,7 +77,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getcategory(geometry, unknown, unknown, unknown) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getcategory(geometry, unknown, unknown, unknown) does not exist"]) def test_if_get_us_census_measure_with_point_is_ok(self): query = "SELECT OBS_GetUSCensusMeasure(CDB_LatLng(40.704512, -73.936669), 'male population') as measure;&api_key={0}".format(self.env_variables['api_key']) @@ -94,7 +94,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getuscensusmeasure(geometry, unknown) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getuscensusmeasure(geometry, unknown) does not exist"]) def test_if_get_us_census_category_is_ok(self): query = "SELECT OBS_GetUSCensusCategory('0103000020E61000000100000021000000BB366F6D917B52C0E7BB6EA82B5A444067224C85937B52C0810205E70E5A4440596D6342997B52C09BED2952F35944400A96386CA27B52C07B6D31F9D95944402B81A0A8AE7B52C0D16B73D5C3594440C34C397FBD7B52C0D8B5B7C0B1594440CFD90A5ECE7B52C0BE8DD86CA45944405C7E229FE07B52C0A904EE5C9C59444017C1F28EF37B52C05E2745E099594440AE8A3873067C52C0FD62540F9D5944402F272292187C52C05502CBCAA5594440C3F17139297C52C0B3FBC4BCB3594440DDAE56C5377C52C00C46175CC6594440E96AB6A6437C52C0355C94F1DC5944402313AE684C7C52C05340159FF6594440B3B90FB5517C52C031F30168125A44407F43B357537C52C0DF95053B2F5A444059C17840517C52C0D9E08EFC4B5A44406580E8834B7C52C046B5B591675A444035736A5A427C52C0AF9A1AEB805A44402E721C1E367C52C0D226550F975A4440506D5C47277C52C0A2968A24A95A4440507C2868167C52C0D51FCE78B65A4440C4438226047C52C02369F888BE5A4440C9F10C36F17B52C027B1B205C15A4440AABE2451DE7B52C0F5E383D6BD5A44402A18B431CC7B52C01785C11AB55A444018320D8ABB7B52C070265B28A75A4440E28A0EFEAC7B52C09E518C88945A44401D08D61CA17B52C09E8195F27D5A4440D7C3405B987B52C0643CB044645A444047B16D0F937B52C04EC9837B485A4440BB366F6D917B52C0E7BB6EA82B5A4440'::geometry, 'Spielman-Singleton Segments: 10 Clusters') as category;&api_key={0}".format(self.env_variables['api_key']) @@ -106,7 +106,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getuscensuscategory(geometry, unknown) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getuscensuscategory(geometry, unknown) does not exist"]) def test_if_get_population_is_ok(self): query = "SELECT OBS_GetPopulation(CDB_LatLng(40.704512, -73.936669)) as population;&api_key={0}".format(self.env_variables['api_key']) @@ -118,7 +118,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getpopulation(geometry) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getpopulation(geometry) does not exist"]) def test_if_obs_search_is_ok(self): sql = "SELECT id FROM OBS_Search('total_pop') WHERE id LIKE 'es.ine%' LIMIT 1;" @@ -132,7 +132,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_search(unknown) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_search(unknown) does not exist"]) def test_if_obs_get_available_boundaries_is_ok(self): query = "SELECT boundary_id FROM OBS_GetAvailableBoundaries(CDB_LatLng(40.704512, -73.936669)) LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -144,7 +144,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getavailableboundaries(geometry) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getavailableboundaries(geometry) does not exist"]) def test_if_obs_get_boundary_is_ok(self): query = "SELECT OBS_GetBoundary(CDB_LatLng(40.704512, -73.936669), 'us.census.tiger.census_tract') as boundary;&api_key={0}".format(self.env_variables['api_key']) @@ -156,7 +156,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getboundary(geometry, unknown) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getboundary(geometry, unknown) does not exist"]) def test_if_obs_get_boundary_id_is_ok(self): query = "SELECT OBS_GetBoundaryId(CDB_LatLng(40.704512, -73.936669), 'us.census.tiger.census_tract', '2015') as boundary_id;&api_key={0}".format(self.env_variables['api_key']) @@ -168,7 +168,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getboundaryid(geometry, unknown, unknown) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getboundaryid(geometry, unknown, unknown) does not exist"]) def test_if_obs_get_boundary_by_id_is_ok(self): query = "SELECT OBS_GetBoundaryById('36047', 'us.census.tiger.county', '2014') as boundary;&api_key={0}".format(self.env_variables['api_key']) @@ -180,7 +180,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getboundarybyid(unknown, unknown, unknown) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getboundarybyid(unknown, unknown, unknown) does not exist"]) def test_if_obs_get_boundaries_by_geometry_is_ok(self): query = "SELECT geom_refs FROM OBS_GetBoundariesByGeometry(ST_MakeEnvelope(-73.9452409744,40.6988851644,-73.9280319214,40.7101254524,4326), 'us.census.tiger.census_tract') ORDER BY geom_refs ASC LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -192,7 +192,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getboundariesbygeometry(geometry, unknown) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getboundariesbygeometry(geometry, unknown) does not exist"]) def test_if_obs_get_boundaries_by_point_and_radius_is_ok(self): query = "SELECT geom_refs FROM OBS_GetBoundariesByPointAndRadius(CDB_LatLng(40.704512, -73.936669), 500, 'us.census.tiger.census_tract') ORDER BY geom_refs ASC LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -204,7 +204,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getboundariesbypointandradius(geometry, integer, unknown) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getboundariesbypointandradius(geometry, integer, unknown) does not exist"]) def test_if_obs_get_points_by_geometry_is_ok(self): query = "SELECT geom_refs FROM OBS_GetPointsByGeometry(ST_MakeEnvelope(-73.9452409744,40.6988851644,-73.9280319214,40.7101254524,4326), 'us.census.tiger.census_tract') ORDER BY geom_refs ASC LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -216,7 +216,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getpointsbygeometry(geometry, unknown) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getpointsbygeometry(geometry, unknown) does not exist"]) def test_if_obs_get_points_by_point_and_radius_is_ok(self): query = "SELECT geom_refs FROM OBS_GetPointsByPointAndRadius(CDB_LatLng(40.704512, -73.936669), 500, 'us.census.tiger.census_tract', '2014') ORDER BY geom_refs ASC LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -228,7 +228,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getpointsbypointandradius(geometry, integer, unknown, unknown) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getpointsbypointandradius(geometry, integer, unknown, unknown) does not exist"]) def test_if_obs_get_legacy_builder_metadata_is_ok(self): query = "SELECT name FROM OBS_LegacyBuilderMetadata() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -240,7 +240,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_legacybuildermetadata() does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_legacybuildermetadata() does not exist"]) def test_if_obs_get_available_numerators_is_ok(self): query = "SELECT numer_id FROM OBS_GetAvailableNumerators() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -252,7 +252,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getavailablenumerators() does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getavailablenumerators() does not exist"]) def test_if_obs_get_available_denominators_is_ok(self): query = "SELECT denom_id FROM OBS_GetAvailableDenominators() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -264,7 +264,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getavailabledenominators() does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getavailabledenominators() does not exist"]) def test_if_obs_get_available_geometries_is_ok(self): query = "SELECT geom_id FROM OBS_GetAvailableGeometries() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -276,7 +276,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getavailablegeometries() does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getavailablegeometries() does not exist"]) def test_if_obs_get_available_timespans_is_ok(self): query = "SELECT timespan_id FROM OBS_GetAvailableTimespans() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -288,7 +288,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getavailabletimespans() does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getavailabletimespans() does not exist"]) def test_if_obs_get_meta_is_ok(self): params = '\'[{\"numer_id\": \"us.census.acs.B01003001\"}]\'' @@ -302,7 +302,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getmeta(geometry, unknown, integer, integer, integer) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getmeta(geometry, unknown, integer, integer, integer) does not exist"]) def test_if_obs_get_data_is_ok(self): params_1 = '\'[{\"numer_id\": \"us.census.acs.B01003001\", \"geom_id\": \"us.census.tiger.county\"}]\'' @@ -322,8 +322,8 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query_1) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getmeta(geometry, unknown, integer, integer, integer) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getmeta(geometry, unknown, integer, integer, integer) does not exist"]) try: IntegrationTestHelper.execute_query(self.sql_api_url, query_2) except Exception as e: - assert_true(e.message[0] in ["Observatory permission denied", "function obs_getmeta(geometry, unknown) does not exist"]) + assert_in(e.message[0], ["Observatory permission denied", "function obs_getmeta(geometry, unknown) does not exist"]) diff --git a/test/integration/test_ipaddress_functions.py b/test/integration/test_ipaddress_functions.py index 5a06916..191d7d7 100644 --- a/test/integration/test_ipaddress_functions.py +++ b/test/integration/test_ipaddress_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal, assert_true +from nose.tools import assert_not_equal, assert_in from ..helpers.integration_test_helper import IntegrationTestHelper @@ -29,4 +29,4 @@ class TestPostalcodeFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Geocoding permission denied", "function cdb_geocode_ipaddress_point(text) does not exist"]) + assert_in(e.message[0], ["Geocoding permission denied", "function cdb_geocode_ipaddress_point(text) does not exist"]) diff --git a/test/integration/test_isolines_functions.py b/test/integration/test_isolines_functions.py index 6622b40..8da7e00 100644 --- a/test/integration/test_isolines_functions.py +++ b/test/integration/test_isolines_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal, assert_true +from nose.tools import assert_not_equal, assert_in from ..helpers.integration_test_helper import IntegrationTestHelper @@ -27,7 +27,7 @@ class TestIsolinesFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Isolines permission denied", "function cdb_isochrone(geometry, unknown, integer[]) does not exist"]) + assert_in(e.message[0], ["Isolines permission denied", "function cdb_isochrone(geometry, unknown, integer[]) does not exist"]) def test_if_select_with_isodistance_is_ok(self): query = "SELECT * FROM cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, " \ @@ -42,4 +42,4 @@ class TestIsolinesFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Isolines permission denied", "function cdb_isodistance(geometry, unknown, integer[]) does not exist"]) + assert_in(e.message[0], ["Isolines permission denied", "function cdb_isodistance(geometry, unknown, integer[]) does not exist"]) diff --git a/test/integration/test_namedplace_functions.py b/test/integration/test_namedplace_functions.py index 6ed87d4..6d64fd5 100644 --- a/test/integration/test_namedplace_functions.py +++ b/test/integration/test_namedplace_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal, assert_true +from nose.tools import assert_not_equal, assert_in from ..helpers.integration_test_helper import IntegrationTestHelper @@ -45,4 +45,4 @@ class TestNameplaceFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Geocoding permission denied", "function cdb_geocode_namedplace_point(text) does not exist"]) + assert_in(e.message[0], ["Geocoding permission denied", "function cdb_geocode_namedplace_point(text) does not exist"]) diff --git a/test/integration/test_postalcode_functions.py b/test/integration/test_postalcode_functions.py index 909d4a3..13151af 100644 --- a/test/integration/test_postalcode_functions.py +++ b/test/integration/test_postalcode_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal, assert_true +from nose.tools import assert_not_equal, assert_in from ..helpers.integration_test_helper import IntegrationTestHelper @@ -37,4 +37,4 @@ class TestPostalcodeFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Geocoding permission denied", "function cdb_geocode_postalcode_polygon(text, text) does not exist"]) \ No newline at end of file + assert_in(e.message[0], ["Geocoding permission denied", "function cdb_geocode_postalcode_polygon(text, text) does not exist"]) \ No newline at end of file diff --git a/test/integration/test_routing_functions.py b/test/integration/test_routing_functions.py index d6a9ea9..6e9ad65 100644 --- a/test/integration/test_routing_functions.py +++ b/test/integration/test_routing_functions.py @@ -1,6 +1,6 @@ from unittest import TestCase from nose.tools import assert_raises -from nose.tools import assert_not_equal, assert_true +from nose.tools import assert_not_equal, assert_in from ..helpers.integration_test_helper import IntegrationTestHelper @@ -31,7 +31,7 @@ class TestRoutingFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Routing permission denied", "function cdb_route_point_to_point(geometry, geometry, unknown, text[]) does not exist"]) + assert_in(e.message[0], ["Routing permission denied", "function cdb_route_point_to_point(geometry, geometry, unknown, text[]) does not exist"]) def test_if_select_with_routing_with_waypoints_is_ok(self): query = "SELECT duration, length, shape as the_geom " \ @@ -53,4 +53,4 @@ class TestRoutingFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_true(e.message[0] in ["Routing permission denied", "function cdb_route_with_waypoints(geometry, geometry, text, text[]) does not exist"]) + assert_in(e.message[0], ["Routing permission denied", "function cdb_route_with_waypoints(geometry, geometry, text, text[]) does not exist"]) From 4aa587d32bbfb1e859cb2e138424d5c84fbad279 Mon Sep 17 00:00:00 2001 From: antoniocarlon Date: Fri, 14 Sep 2018 12:46:43 +0200 Subject: [PATCH 3/5] Fixing DO integration tests --- .../test_data_observatory_functions.py | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/test/integration/test_data_observatory_functions.py b/test/integration/test_data_observatory_functions.py index 661678a..23305bf 100644 --- a/test/integration/test_data_observatory_functions.py +++ b/test/integration/test_data_observatory_functions.py @@ -24,7 +24,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getdemographicsnapshot(geometry) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getdemographicsnapshot(geometry) does not exist"]) def test_if_get_segment_snapshot_is_ok(self): query = "SELECT OBS_GetSegmentSnapshot(CDB_LatLng(40.704512, -73.936669)) as snapshot;&api_key={0}".format(self.env_variables['api_key']) @@ -36,7 +36,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getsegmentsnapshot(geometry) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getsegmentsnapshot(geometry) does not exist"]) def test_if_get_measure_with_point_is_ok(self): query = "SELECT OBS_GetMeasure(CDB_LatLng(40.704512, -73.936669), 'us.census.acs.B01003001') as measure;&api_key={0}".format(self.env_variables['api_key']) @@ -53,7 +53,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getmeasure(geometry, unknown) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getmeasure(geometry, unknown) does not exist"]) def test_if_get_measure_by_id_ok(self): query = "SELECT OBS_GetMeasureById('36047048500', 'us.census.acs.B01003001', 'us.census.tiger.census_tract', '2010 - 2014') as measure;&api_key={0}".format(self.env_variables['api_key']) @@ -65,7 +65,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getmeasurebyid(unknown, unknown, unknown, unknown) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getmeasurebyid(unknown, unknown, unknown, unknown) does not exist"]) def test_if_get_category_is_ok(self): query = "SELECT OBS_GetCategory(CDB_LatLng(40.704512, -73.936669), 'us.census.spielman_singleton_segments.X10', 'us.census.tiger.census_tract', '2010 - 2014') as category;&api_key={0}".format(self.env_variables['api_key']) @@ -77,7 +77,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getcategory(geometry, unknown, unknown, unknown) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getcategory(geometry, unknown, unknown, unknown) does not exist"]) def test_if_get_us_census_measure_with_point_is_ok(self): query = "SELECT OBS_GetUSCensusMeasure(CDB_LatLng(40.704512, -73.936669), 'male population') as measure;&api_key={0}".format(self.env_variables['api_key']) @@ -94,7 +94,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getuscensusmeasure(geometry, unknown) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getuscensusmeasure(geometry, unknown) does not exist"]) def test_if_get_us_census_category_is_ok(self): query = "SELECT OBS_GetUSCensusCategory('0103000020E61000000100000021000000BB366F6D917B52C0E7BB6EA82B5A444067224C85937B52C0810205E70E5A4440596D6342997B52C09BED2952F35944400A96386CA27B52C07B6D31F9D95944402B81A0A8AE7B52C0D16B73D5C3594440C34C397FBD7B52C0D8B5B7C0B1594440CFD90A5ECE7B52C0BE8DD86CA45944405C7E229FE07B52C0A904EE5C9C59444017C1F28EF37B52C05E2745E099594440AE8A3873067C52C0FD62540F9D5944402F272292187C52C05502CBCAA5594440C3F17139297C52C0B3FBC4BCB3594440DDAE56C5377C52C00C46175CC6594440E96AB6A6437C52C0355C94F1DC5944402313AE684C7C52C05340159FF6594440B3B90FB5517C52C031F30168125A44407F43B357537C52C0DF95053B2F5A444059C17840517C52C0D9E08EFC4B5A44406580E8834B7C52C046B5B591675A444035736A5A427C52C0AF9A1AEB805A44402E721C1E367C52C0D226550F975A4440506D5C47277C52C0A2968A24A95A4440507C2868167C52C0D51FCE78B65A4440C4438226047C52C02369F888BE5A4440C9F10C36F17B52C027B1B205C15A4440AABE2451DE7B52C0F5E383D6BD5A44402A18B431CC7B52C01785C11AB55A444018320D8ABB7B52C070265B28A75A4440E28A0EFEAC7B52C09E518C88945A44401D08D61CA17B52C09E8195F27D5A4440D7C3405B987B52C0643CB044645A444047B16D0F937B52C04EC9837B485A4440BB366F6D917B52C0E7BB6EA82B5A4440'::geometry, 'Spielman-Singleton Segments: 10 Clusters') as category;&api_key={0}".format(self.env_variables['api_key']) @@ -106,7 +106,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getuscensuscategory(geometry, unknown) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getuscensuscategory(geometry, unknown) does not exist"]) def test_if_get_population_is_ok(self): query = "SELECT OBS_GetPopulation(CDB_LatLng(40.704512, -73.936669)) as population;&api_key={0}".format(self.env_variables['api_key']) @@ -118,7 +118,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getpopulation(geometry) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getpopulation(geometry) does not exist"]) def test_if_obs_search_is_ok(self): sql = "SELECT id FROM OBS_Search('total_pop') WHERE id LIKE 'es.ine%' LIMIT 1;" @@ -132,7 +132,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_search(unknown) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_search(unknown) does not exist"]) def test_if_obs_get_available_boundaries_is_ok(self): query = "SELECT boundary_id FROM OBS_GetAvailableBoundaries(CDB_LatLng(40.704512, -73.936669)) LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -144,7 +144,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getavailableboundaries(geometry) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getavailableboundaries(geometry) does not exist"]) def test_if_obs_get_boundary_is_ok(self): query = "SELECT OBS_GetBoundary(CDB_LatLng(40.704512, -73.936669), 'us.census.tiger.census_tract') as boundary;&api_key={0}".format(self.env_variables['api_key']) @@ -156,7 +156,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getboundary(geometry, unknown) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getboundary(geometry, unknown) does not exist"]) def test_if_obs_get_boundary_id_is_ok(self): query = "SELECT OBS_GetBoundaryId(CDB_LatLng(40.704512, -73.936669), 'us.census.tiger.census_tract', '2015') as boundary_id;&api_key={0}".format(self.env_variables['api_key']) @@ -168,7 +168,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getboundaryid(geometry, unknown, unknown) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getboundaryid(geometry, unknown, unknown) does not exist"]) def test_if_obs_get_boundary_by_id_is_ok(self): query = "SELECT OBS_GetBoundaryById('36047', 'us.census.tiger.county', '2014') as boundary;&api_key={0}".format(self.env_variables['api_key']) @@ -180,7 +180,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getboundarybyid(unknown, unknown, unknown) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getboundarybyid(unknown, unknown, unknown) does not exist"]) def test_if_obs_get_boundaries_by_geometry_is_ok(self): query = "SELECT geom_refs FROM OBS_GetBoundariesByGeometry(ST_MakeEnvelope(-73.9452409744,40.6988851644,-73.9280319214,40.7101254524,4326), 'us.census.tiger.census_tract') ORDER BY geom_refs ASC LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -192,7 +192,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getboundariesbygeometry(geometry, unknown) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getboundariesbygeometry(geometry, unknown) does not exist"]) def test_if_obs_get_boundaries_by_point_and_radius_is_ok(self): query = "SELECT geom_refs FROM OBS_GetBoundariesByPointAndRadius(CDB_LatLng(40.704512, -73.936669), 500, 'us.census.tiger.census_tract') ORDER BY geom_refs ASC LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -204,7 +204,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getboundariesbypointandradius(geometry, integer, unknown) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getboundariesbypointandradius(geometry, integer, unknown) does not exist"]) def test_if_obs_get_points_by_geometry_is_ok(self): query = "SELECT geom_refs FROM OBS_GetPointsByGeometry(ST_MakeEnvelope(-73.9452409744,40.6988851644,-73.9280319214,40.7101254524,4326), 'us.census.tiger.census_tract') ORDER BY geom_refs ASC LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -216,7 +216,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getpointsbygeometry(geometry, unknown) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getpointsbygeometry(geometry, unknown) does not exist"]) def test_if_obs_get_points_by_point_and_radius_is_ok(self): query = "SELECT geom_refs FROM OBS_GetPointsByPointAndRadius(CDB_LatLng(40.704512, -73.936669), 500, 'us.census.tiger.census_tract', '2014') ORDER BY geom_refs ASC LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -228,7 +228,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getpointsbypointandradius(geometry, integer, unknown, unknown) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getpointsbypointandradius(geometry, integer, unknown, unknown) does not exist"]) def test_if_obs_get_legacy_builder_metadata_is_ok(self): query = "SELECT name FROM OBS_LegacyBuilderMetadata() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -240,7 +240,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_legacybuildermetadata() does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_legacybuildermetadata() does not exist"]) def test_if_obs_get_available_numerators_is_ok(self): query = "SELECT numer_id FROM OBS_GetAvailableNumerators() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -252,7 +252,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getavailablenumerators() does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getavailablenumerators() does not exist"]) def test_if_obs_get_available_denominators_is_ok(self): query = "SELECT denom_id FROM OBS_GetAvailableDenominators() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -264,7 +264,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getavailabledenominators() does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getavailabledenominators() does not exist"]) def test_if_obs_get_available_geometries_is_ok(self): query = "SELECT geom_id FROM OBS_GetAvailableGeometries() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -276,7 +276,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getavailablegeometries() does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getavailablegeometries() does not exist"]) def test_if_obs_get_available_timespans_is_ok(self): query = "SELECT timespan_id FROM OBS_GetAvailableTimespans() LIMIT 1;&api_key={0}".format(self.env_variables['api_key']) @@ -288,7 +288,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getavailabletimespans() does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getavailabletimespans() does not exist"]) def test_if_obs_get_meta_is_ok(self): params = '\'[{\"numer_id\": \"us.census.acs.B01003001\"}]\'' @@ -302,7 +302,7 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getmeta(geometry, unknown, integer, integer, integer) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getmeta(geometry, unknown, integer, integer, integer) does not exist"]) def test_if_obs_get_data_is_ok(self): params_1 = '\'[{\"numer_id\": \"us.census.acs.B01003001\", \"geom_id\": \"us.census.tiger.county\"}]\'' @@ -322,8 +322,8 @@ class TestDataObservatoryFunctions(TestCase): try: IntegrationTestHelper.execute_query(self.sql_api_url, query_1) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getmeta(geometry, unknown, integer, integer, integer) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getmeta(geometry, unknown, integer, integer, integer) does not exist"]) try: IntegrationTestHelper.execute_query(self.sql_api_url, query_2) except Exception as e: - assert_in(e.message[0], ["Observatory permission denied", "function obs_getmeta(geometry, unknown) does not exist"]) + assert_in(e.message[0], ["Data Observatory permission denied", "function obs_getmeta(geometry, unknown) does not exist"]) From 61a27a9f9dea421c23c0fd486b93ffd3828fef55 Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Wed, 3 Oct 2018 14:21:55 +0200 Subject: [PATCH 4/5] Tomtom QPS fix Tomtom return 403 status code in the following scenarios: - Forbidden - Not authorized - Account inactive - Account over queries per second limit - Account over rate limit - Rate limit exceeded So when we reach the QPS limit we receive a 403 instead of 429 so we have to include the provider in the qps service to differentiate between providers that returns 429 and special cases like tomtom --- .../cartodb_services/tomtom/isolines.py | 2 +- .../cartodb_services/tools/qps.py | 23 +++++++++---------- server/lib/python/cartodb_services/setup.py | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/tomtom/isolines.py b/server/lib/python/cartodb_services/cartodb_services/tomtom/isolines.py index a6fc062..8a58f12 100644 --- a/server/lib/python/cartodb_services/cartodb_services/tomtom/isolines.py +++ b/server/lib/python/cartodb_services/cartodb_services/tomtom/isolines.py @@ -64,7 +64,7 @@ class TomTomIsolines(): return self._parse_coordinates(reachable_range[ENTRY_BOUNDARY]) - @qps_retry(qps=5) + @qps_retry(qps=5, provider='tomtom') def _calculate_isoline(self, origin, time_range, profile=DEFAULT_PROFILE, date_time=DEFAULT_DEPARTAT): diff --git a/server/lib/python/cartodb_services/cartodb_services/tools/qps.py b/server/lib/python/cartodb_services/cartodb_services/tools/qps.py index 074155b..ef210ab 100644 --- a/server/lib/python/cartodb_services/cartodb_services/tools/qps.py +++ b/server/lib/python/cartodb_services/cartodb_services/tools/qps.py @@ -18,15 +18,10 @@ def qps_retry(original_function=None, **options): """ if original_function is not None: def wrapped_function(*args, **kwargs): - if 'timeout' in options: - timeout = options['timeout'] - else: - timeout = DEFAULT_RETRY_TIMEOUT - if 'qps' in options: - qps = options['qps'] - else: - qps = DEFAULT_QUERIES_PER_SECOND - return QPSService(retry_timeout=timeout, queries_per_second=qps).call(original_function, *args, **kwargs) + timeout = options.get('timeout', DEFAULT_RETRY_TIMEOUT) + qps = options.get('qps', DEFAULT_QUERIES_PER_SECOND) + provider = options.get('provider', None) + return QPSService(retry_timeout=timeout, queries_per_second=qps, provider=provider).call(original_function, *args, **kwargs) return wrapped_function else: def partial_wrapper(func): @@ -36,9 +31,10 @@ def qps_retry(original_function=None, **options): class QPSService: - def __init__(self, queries_per_second, retry_timeout): + def __init__(self, queries_per_second, retry_timeout, provider): self._queries_per_second = queries_per_second self._retry_timeout = retry_timeout + self._provider = provider def call(self, fn, *args, **kwargs): start_time = datetime.now() @@ -48,8 +44,11 @@ class QPSService: return fn(*args, **kwargs) except Exception as e: response = getattr(e, 'response', None) - if response is not None and (response.status_code == 429): - self.retry(start_time, attempt_number) + if response is not None: + if self._provider is not None and self._provider == 'tomtom' and (response.status_code == 403): + self.retry(start_time, attempt_number) + elif response.status_code == 429: + self.retry(start_time, attempt_number) else: raise e attempt_number += 1 diff --git a/server/lib/python/cartodb_services/setup.py b/server/lib/python/cartodb_services/setup.py index ea9ab90..2693d0e 100644 --- a/server/lib/python/cartodb_services/setup.py +++ b/server/lib/python/cartodb_services/setup.py @@ -10,7 +10,7 @@ from setuptools import setup, find_packages setup( name='cartodb_services', - version='0.20.0', + version='0.20.1', description='CartoDB Services API Python Library', From 56a2ebb21045863ebf6105cdb7d732af571d5b27 Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Wed, 3 Oct 2018 18:50:20 +0200 Subject: [PATCH 5/5] Fix qps timeout bug --- .../lib/python/cartodb_services/cartodb_services/tools/qps.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/lib/python/cartodb_services/cartodb_services/tools/qps.py b/server/lib/python/cartodb_services/cartodb_services/tools/qps.py index ef210ab..24d110e 100644 --- a/server/lib/python/cartodb_services/cartodb_services/tools/qps.py +++ b/server/lib/python/cartodb_services/cartodb_services/tools/qps.py @@ -49,6 +49,8 @@ class QPSService: self.retry(start_time, attempt_number) elif response.status_code == 429: self.retry(start_time, attempt_number) + else: + raise e else: raise e attempt_number += 1