Skip to content

Commit

Permalink
more data from linkedin (with tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
keul committed Jun 15, 2013
1 parent 838235e commit 58f8bd2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions example_test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ test_providers =
# google_hybrid
# yahoo
# live
# linkedin

facebook.app =
facebook.login =
Expand Down Expand Up @@ -56,6 +57,7 @@ login_providers =
# google_hybrid
# yahoo
# live
# linkedin

# OpenID storage required by:
# google, yahoo and openid providers
Expand Down
7 changes: 7 additions & 0 deletions tests/selenium/testapp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,12 @@ def main(global_conf, **settings):
consumer_secret=settings['velruse.yahoo.consumer_secret'],
)

if 'linkedin' in providers:
config.include('velruse.providers.linkedin')
config.add_linkedin_login(
settings['velruse.linkedin.consumer_key'],
settings['velruse.linkedin.consumer_secret'],
)

config.scan(__name__)
return config.make_wsgi_app()
1 change: 1 addition & 0 deletions tests/selenium/testapp/templates/login.mako
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ${form('yahoo', 'Login with Yahoo',
oauth='true',
openid_identifier='yahoo.com')}
${form('live', 'Login with Windows Live')}
${form('linkedin', 'Login with Linkedin')}

</body>
</html>
36 changes: 36 additions & 0 deletions tests/selenium/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,39 @@ def test_it(self):
creds = result['credentials']
self.assertTrue('oauthAccessToken' in creds)
self.assertTrue('oauthAccessTokenSecret' in creds)

class TestLinedin(ProviderTests, unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.require_provider('linkedin')
cls.login = config['linkedin.login']
cls.password = config['linkedin.password']
cls.login_url = find_login_url(config, 'linkedin.login_url')

def test_it(self):
import pdb;pdb.set_trace()
self.assertEqual(browser.title, 'Auth Page')
browser.find_element_by_id('linkedin').submit()
self.assertEqual(browser.title, 'Authorize | LinkedIn')
form = browser.find_element_by_name('oauthAuthorizeForm')
login = form.find_element_by_id('session_key-oauthAuthorizeForm')
login.send_keys(self.login)
passwd = form.find_element_by_id('session_password-oauthAuthorizeForm')
passwd.send_keys(self.password)
form.find_element_by_name('authorize').submit()
result = WebDriverWait(browser, 2).until(
EC.presence_of_element_located((By.ID, 'result')))
self.assertEqual(browser.title, 'Result Page')
result = json.loads(result.text)
self.assertTrue('profile' in result)
self.assertTrue('credentials' in result)
profile = result['profile']
self.assertTrue('displayName' in profile)
self.assertTrue('accounts' in profile)
self.assertTrue('photos' in profile)
# BBB: Linkedin app must be enabled toshare e-mail
self.assertTrue('emails' in profile)
creds = result['credentials']
self.assertTrue('oauthAccessToken' in creds)
self.assertTrue('oauthAccessTokenSecret' in creds)
8 changes: 7 additions & 1 deletion velruse/providers/linkedin.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def callback(self, request):
resource_owner_secret=creds['oauthAccessTokenSecret'])

profile_url = 'http://api.linkedin.com/v1/people/~'
profile_url += ':(first-name,last-name,id,date-of-birth,picture-url)'
profile_url += (':(first-name,last-name,id,date-of-birth,picture-url,'
'email-address)')
profile_url += '?format=json'

resp = requests.get(profile_url, auth=oauth)
Expand All @@ -148,6 +149,11 @@ def callback(self, request):
'familyName': data['lastName'],
'formatted': '%s %s' % (data['firstName'], data['lastName'])
}
if data.get('emailAddress'):
profile['emails'] = [{'value':data.get('emailAddress')}]
if data.get('pictureUrl'):
profile['photos'] = [{'value': data.get('pictureUrl')}]

profile['accounts'] = [{
'domain': 'linkedin.com',
'userid': data['id']
Expand Down

0 comments on commit 58f8bd2

Please sign in to comment.