def parse_address_search(): """Parses the address for API call""" if request.args: raw_address_text = request.args.get("address-search") address_url_encode, citystatezip_url_encode, address_for_walkscore = create_address_url(raw_address_text) property_from_url, error_code = Property.generate_from_address(address=address_url_encode, citystatezip=citystatezip_url_encode) #instantiate a session if 'properties' not in session.keys(): session['properties'] = [] if error_code == Property.ERROR_OK: if property_from_url.zpid not in session['properties']: session['properties'].append(property_from_url.zpid) this_property = Property.query.filter(Property.zpid == property_from_url.zpid).first() if this_property is None: db.session.add(property_from_url) db.session.commit() this_property = property_from_url return render_template("address-confirmation.html", house=this_property) elif error_code == Property.ERROR_MANY: message = "Ambiguous Result. Please check your address and specify a unique property." return error_message_utility(message) else: message = "No property found. Please search again." return error_message_utility(message)
def test_parsing_partial(self): input_str = "1600 Pennsylvania Ave, 20500" address_url, citystate_zip_url, _ = utils.create_address_url(input_str) self.assertEqual(address_url, "1600+Pennsylvania+Ave") self.assertEqual(citystate_zip_url, "%2C++20500")
def test_parsing_full(self): input_str = "1600 Pennsylvania Avenue, Washington, D.C. 20500" address_url, citystate_zip_url, _ = utils.create_address_url(input_str) self.assertEqual(address_url, "1600+Pennsylvania+Avenue") self.assertEqual(citystate_zip_url, "Washington%2C+D.C.+20500")