def test_convert_address(): msdn = MSDN() coordinates = msdn.convert_address( street='1 Microsoft Way', city='Redmond', state='WA', zip_code='98052' ) assert type(coordinates) == list assert len(coordinates) == 2 assert type(coordinates[0]) == float assert type(coordinates[1]) == float
def convert_address(): """ Converts an address to lat/long coordinates """ # Get the query parameters from the request street = request.args.get('street') if street is None: error = {'error': 'Street not defined'} return make_response(jsonify(error), 400) city = request.args.get('city') if city is None: error = {'error': 'City not defined'} return make_response(jsonify(error), 400) state = request.args.get('state') if state is None: error = {'error': 'State not defined'} return make_response(jsonify(error), 400) zip_code = request.args.get('zipCode') if zip_code is None: error = {'error': 'Zip Code not defined'} return make_response(jsonify(error), 400) # Convert the address to coordinates msdn = MSDN() coordinates = msdn.convert_address(street=street, city=city, state=state, zip_code=zip_code) return jsonify({ 'coordinates': coordinates, 'address': { 'street': street, 'city': city, 'state': state, 'zipCode': zip_code } })