def handle_add_account_callback(request, auth_info): try: user_info = google.get_youtube_user_info(auth_info.access_token) except google.APIError, e: logging.error("handle_add_account_callback: %s" % e) messages.error(request, e.message) # there's no good place to redirect the user to since we don't know # what team/user they were trying to add the account for. I guess the # homepage is as good as any. return redirect('videos.views.index')
def test_get_user_info(self): mocker = test_utils.RequestsMocker() mocker.expect_request('get', 'https://www.googleapis.com/youtube/v3/channels', params={ 'part': 'id,snippet', 'mine': 'true', }, headers={ 'Authorization': 'Bearer test-access-token', }, body=json.dumps({ 'items': [{ 'id': 'test-channel-id', 'snippet': { 'title': 'test-username', }, }] })) google.get_youtube_user_info.run_original_for_test() with mocker: user_info = google.get_youtube_user_info('test-access-token') self.assertEqual(user_info, ('test-channel-id', 'test-username'))