validate lp_profile['display_name'] when get it from launchpad

if a user use an email address as display_name,launchpad will redacte it and
return "display_name": "<email address hidden>",so we hate to validate it
before using it.

Change-Id: I54d16a8786ed431c2ec5cce0691d7acff47ebc79
Close-Bug:1416311
This commit is contained in:
yanheven 2015-02-02 01:35:38 +00:00
parent 371bcdb048
commit 30c1da5f29
2 changed files with 11 additions and 2 deletions

View File

@ -39,13 +39,17 @@ def link_to_launchpad_id(link):
def lp_profile_by_launchpad_id(launchpad_id):
LOG.debug('Lookup user id %s at Launchpad', launchpad_id)
uri = LP_URI_V1 % ('~' + launchpad_id)
return utils.read_json_from_uri(uri)
lp_profile = utils.read_json_from_uri(uri)
utils.validate_lp_display_name(lp_profile)
return lp_profile
def lp_profile_by_email(email):
LOG.debug('Lookup user email %s at Launchpad', email)
uri = LP_URI_V1 % ('people/?ws.op=getByEmail&email=' + email)
return utils.read_json_from_uri(uri)
lp_profile = utils.read_json_from_uri(uri)
utils.validate_lp_display_name(lp_profile)
return lp_profile
def lp_module_exists(module):

View File

@ -266,3 +266,8 @@ def normalize_company_draft(name):
name = re.sub(',', ' ', name)
name = re.sub(r'\s+', ' ', name)
return name
def validate_lp_display_name(lp_profile):
if "<email address hidden>" == lp_profile['display_name']:
lp_profile['display_name'] = lp_profile['name']