Skip to content

Commit

Permalink
Merge pull request #33 from brighthive/feat/relax-address-validation
Browse files Browse the repository at this point in the history
feat: relax validation of mailing address
  • Loading branch information
gregmundy authored Sep 9, 2020
2 parents e3a019e + eea0d75 commit 23d783b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
mci:
image: brighthive/master-client-index:latest
image: brighthive/master-client-index:1.0.5
ports:
- "8001:8000"
environment:
Expand Down
36 changes: 29 additions & 7 deletions mci/api/v1_0_0/user_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def create_new_user(self, user_object):
matching_service_uri = config.get_matching_service_uri()
new_user_json = json.dumps(new_user.as_dict, default=str)
try:
response = requests.post(matching_service_uri, data=new_user_json, timeout=5)
response = requests.post(
matching_service_uri, data=new_user_json, timeout=5)
except ConnectionError:
return {
'error': 'The matching service did not return a response.'
Expand Down Expand Up @@ -328,11 +329,32 @@ def _find_address_id(self, address):
}

try:
new_address = Address(address.get('address', '').title(),
address.get('city', '').title(),
address.get('state', '').upper(),
address.get('postal_code', ''),
address.get('country', '').upper())
try:
_address = address.get('address', '').title()
except Exception:
_address = None

try:
_city = address.get('city', '').title()
except Exception:
_city = None

try:
_state = address.get('state', '').upper()
except Exception:
_state = None

try:
_postal_code = address.get('postal_code', '')
except Exception:
_postal_code = None

try:
_country = address.get('country', '').upper()
except Exception:
_country = None

new_address = Address(_address, _city, _state, _postal_code, _country)

address = Address.query.filter_by(address=new_address.address, city=new_address.city,
state=new_address.state, postal_code=new_address.postal_code,
Expand All @@ -344,7 +366,7 @@ def _find_address_id(self, address):
db.session.add(new_address)
db.session.commit()
result['id'] = new_address.id
except Exception:
except Exception as e:
result['error'] = 'Invalid Mailing Address format.'

return result
Expand Down
26 changes: 1 addition & 25 deletions mci/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ def after_request(response):
'status_code': response.status_code,
'status': response.status,
'content_length': response.content_length,
'user_agent': str(request.user_agent),
'payload': response.json
'user_agent': str(request.user_agent)
}
if info['status_code'] >= 200 and info['status_code'] < 300:
logger.info(info)
Expand Down Expand Up @@ -130,27 +129,4 @@ def create_app():

app.register_error_handler(Exception, handle_errors)
app.after_request(after_request)

# @app.after_request
# def after_request(response):
# info = {
# 'remote_addr': request.remote_addr,
# 'request_time': str(datetime.utcnow()),
# 'method': request.method,
# 'path': request.path,
# 'scheme': request.scheme.upper(),
# 'status_code': response.status_code,
# 'status': response.status,
# 'content_length': response.content_length,
# 'user_agent': str(request.user_agent),
# 'payload': {
# 'last_name': request.json['last_name'] if 'last_name' in request.json else '',
# 'gender_id': request.json['gender_id'] if 'gender_id' in request.json else ''
# }
# }
# if info['status_code'] >= 200 and info['status_code'] < 300:
# logger.info(info)
# else:
# logger.error(info)
# return response
return app

0 comments on commit 23d783b

Please sign in to comment.