def __init__(self, config: cov_base.CoverageConfigWrapper, civic_resolver: cov_civic.CivicCoverageResolver, geodetic_resolver: cov_geo.GeodeticCoverageResolver): """ Constructor :param config: Coverage configuration. :param civic_resolver: A resolver for civic address locations. :param geo_resolver: A resolver for geodetic locations. """ super().__init__() self._server_name: str = config.server_name().lower() self._do_coverage: bool = config.do_coverage() self._civic_resolver = civic_resolver self._geodetic_resolver = geodetic_resolver
def test_build_coverage_query(self, mock_config: cov_base.CoverageConfigWrapper, mock_point: mod_geodetic.Point): test_geom = Point(2.2, 1.1) mock_point.to_ogr_geometry = MagicMock() mock_point.to_ogr_geometry.return_value = ogr.CreateGeometryFromWkt( test_geom.wkt) mock_config.geodetic_coverage_table = MagicMock() mock_config.geodetic_coverage_table.return_value = 'the_table' expected = (""" select depth, serviceurn, lostserver, ST_Area(ST_Intersection(ST_GeomFromText('{0}', 4326), wkb_geometry)) from {1} where ST_Intersects(ST_GeomFromText('{0}', 4326), wkb_geometry) order by depth desc, st_area desc """.format(test_geom.wkt, 'the_table')) target: cov_geodetic.GeodeticCoverageResolver = cov_geodetic.GeodeticCoverageResolver( mock_config, None) actual = target.build_coverage_query(mock_point) self.assertIsNotNone(actual) self.assertEqual(expected, actual) mock_config.geodetic_coverage_table.assert_called_once()
def test_build_coverage_query(self, mock_config: cov_base.CoverageConfigWrapper): civ_addr = mod_civic.CivicAddress() civ_addr.country = 'country' civ_addr.a1 = 'a1' civ_addr.a2 = 'a2' civ_addr.a3 = 'a3' civ_addr.a4 = 'a4' civ_addr.a5 = 'a5' expected = 'SELECT * FROM the_table WHERE clause clause clause clause clause clause ' mock_config.civic_coverage_table = MagicMock() mock_config.civic_coverage_table.return_value = 'the_table' target: cov_civic.CivicCoverageResolver = cov_civic.CivicCoverageResolver( mock_config, None) target._build_where_clause = MagicMock() target._build_where_clause.return_value = 'clause ' actual = target.build_coverage_query(civ_addr) self.assertEqual(expected, actual) mock_config.civic_coverage_table.assert_called_once() calls = [ call('country', 'country'), call('a1', 'a1', appending=True), call('a2', 'a2', appending=True), call('a3', 'a3', appending=True), call('a4', 'a4', appending=True), call('a5', 'a5', appending=True) ] target._build_where_clause.assert_has_calls(calls)
def test_build_response_without_result_return_parent( self, mock_config: cov_base.CoverageConfigWrapper): input_matches = [] mock_config.parent_ecrf = MagicMock() mock_config.parent_ecrf.return_value = 'some.parent.ecrf' target: cov_geodetic.GeodeticCoverageResolver = cov_geodetic.GeodeticCoverageResolver( mock_config, None) actual = target.build_response(input_matches) self.assertEqual('some.parent.ecrf', actual) mock_config.parent_ecrf.assert_called_once()
def test_build_response_without_result_no_parent( self, mock_config: cov_base.CoverageConfigWrapper): input_matches = [] mock_config.parent_ecrf = MagicMock() mock_config.parent_ecrf.return_value = None target: cov_geodetic.GeodeticCoverageResolver = cov_geodetic.GeodeticCoverageResolver( mock_config, None) with self.assertRaises(lost_exp.NotFoundException): actual = target.build_response(input_matches) mock_config.parent_ecrf.assert_called_once()