def test_get_district_from_lat_lon(self): self.assertEqual( databases_utils.get_district_from_lat_lon( self.lat_lon_district_11), 11) with self.assertRaises(ValueError): databases_utils.get_district_from_lat_lon( self.lat_lon_not_in_chicago)
def _is_in_chicago(self,user_address): """ Checks if the address passed in string type is in Chicago. :param user_address :return boolean """ if not isinstance(user_address, str): return False if 'Chicago' not in user_address: user_address = user_address + ', Chicago, IL, USA' self._get_address_info(user_address) try: get_district_from_lat_lon(self._get_address_lat_lon()) except ValueError: return False if self.address_info['formatted_address'] == 'Chicago, IL, USA': return False return True
def __init__(self, address = None): if address: if not self._is_in_chicago(address): raise ValueError('Address not in Chicago') else: self.get_address() self.formatted_address = self.address_info['formatted_address'] self.lat,self.lon = self._get_address_lat_lon() self.district = get_district_from_lat_lon((self.lat,self.lon)) self.street_address = self._get_street_address() police_station_lat, police_station_lon = get_police_station_coordinates(self.district) self.distance_to_police_station = calculate_distance_between_points(self.lat,self.lon, police_station_lat, police_station_lon) self.summary = None
def test_get_district_from_lat_lon(self): self.assertEqual(databases_utils.get_district_from_lat_lon(self.lat_lon_district_11) , 11) with self.assertRaises(ValueError): databases_utils.get_district_from_lat_lon(self.lat_lon_not_in_chicago)