From 58f8bd2935d1fc6c36176bf0b52b1178e64308dc Mon Sep 17 00:00:00 2001 From: Luca Fabbri Date: Sat, 15 Jun 2013 20:42:53 +0200 Subject: [PATCH] more data from linkedin (with tests) --- example_test.ini | 2 ++ tests/selenium/testapp/__init__.py | 7 ++++ tests/selenium/testapp/templates/login.mako | 1 + tests/selenium/tests.py | 36 +++++++++++++++++++++ velruse/providers/linkedin.py | 8 ++++- 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/example_test.ini b/example_test.ini index 7c575a0..331d52c 100644 --- a/example_test.ini +++ b/example_test.ini @@ -14,6 +14,7 @@ test_providers = # google_hybrid # yahoo # live +# linkedin facebook.app = facebook.login = @@ -56,6 +57,7 @@ login_providers = # google_hybrid # yahoo # live +# linkedin # OpenID storage required by: # google, yahoo and openid providers diff --git a/tests/selenium/testapp/__init__.py b/tests/selenium/testapp/__init__.py index a5f2339..9360aff 100644 --- a/tests/selenium/testapp/__init__.py +++ b/tests/selenium/testapp/__init__.py @@ -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() diff --git a/tests/selenium/testapp/templates/login.mako b/tests/selenium/testapp/templates/login.mako index b927dfc..e3fadac 100644 --- a/tests/selenium/testapp/templates/login.mako +++ b/tests/selenium/testapp/templates/login.mako @@ -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')} diff --git a/tests/selenium/tests.py b/tests/selenium/tests.py index b52d04e..b3b6493 100644 --- a/tests/selenium/tests.py +++ b/tests/selenium/tests.py @@ -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) diff --git a/velruse/providers/linkedin.py b/velruse/providers/linkedin.py index 4dfee04..ff7a333 100644 --- a/velruse/providers/linkedin.py +++ b/velruse/providers/linkedin.py @@ -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) @@ -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']