def test_get_spotify_oauth(self): func_oauth = spotify.get_spotify_oauth() self.assertEqual(func_oauth.client_id, current_app.config['SPOTIFY_CLIENT_ID']) self.assertEqual(func_oauth.client_secret, current_app.config['SPOTIFY_CLIENT_SECRET']) self.assertEqual(func_oauth.redirect_uri, 'http://localhost/profile/connect-spotify/callback') self.assertIsNone(func_oauth.scope) func_oauth = spotify.get_spotify_oauth( spotify.SPOTIFY_LISTEN_PERMISSIONS) self.assertIn('streaming', func_oauth.scope) self.assertIn('user-read-birthdate', func_oauth.scope) self.assertIn('user-read-email', func_oauth.scope) self.assertIn('user-read-private', func_oauth.scope) self.assertNotIn('user-read-recently-played', func_oauth.scope) self.assertNotIn('user-read-currently-playing', func_oauth.scope) func_oauth = spotify.get_spotify_oauth( spotify.SPOTIFY_IMPORT_PERMISSIONS) self.assertIn('user-read-currently-playing', func_oauth.scope) self.assertIn('user-read-recently-played', func_oauth.scope) self.assertNotIn('streaming', func_oauth.scope) self.assertNotIn('user-read-birthdate', func_oauth.scope) self.assertNotIn('user-read-email', func_oauth.scope) self.assertNotIn('user-read-private', func_oauth.scope)
def test_get_spotify_oauth(self): func_oauth = spotify.get_spotify_oauth() self.assertEqual(func_oauth.client_id, current_app.config['SPOTIFY_CLIENT_ID']) self.assertEqual(func_oauth.client_secret, current_app.config['SPOTIFY_CLIENT_SECRET']) self.assertEqual(func_oauth.redirect_uri, 'http://localhost/profile/connect-spotify/callback') self.assertEqual(func_oauth.scope, 'user-read-recently-played')
def connect_spotify(): if request.method == 'POST' and request.form.get('delete') == 'yes': spotify.remove_user(current_user.id) flash.success('Your Spotify account has been unlinked') user = spotify.get_user(current_user.id) only_listen_sp_oauth = spotify.get_spotify_oauth(spotify.SPOTIFY_LISTEN_PERMISSIONS) only_import_sp_oauth = spotify.get_spotify_oauth(spotify.SPOTIFY_IMPORT_PERMISSIONS) both_sp_oauth = spotify.get_spotify_oauth(spotify.SPOTIFY_LISTEN_PERMISSIONS + spotify.SPOTIFY_IMPORT_PERMISSIONS) return render_template( 'user/spotify.html', account=user, last_updated=user.last_updated_iso if user else None, latest_listened_at=user.latest_listened_at_iso if user else None, only_listen_url=only_listen_sp_oauth.get_authorize_url(), only_import_url=only_import_sp_oauth.get_authorize_url(), both_url=both_sp_oauth.get_authorize_url(), )
def connect_spotify_callback(): code = request.args.get('code') if not code: raise BadRequest('missing code') sp_oauth = spotify.get_spotify_oauth() try: token = sp_oauth.get_access_token(code) spotify.add_new_user(current_user.id, token) flash.success('Successfully authenticated with Spotify!') except spotipy.oauth2.SpotifyOauthError as e: current_app.logger.error('Unable to authenticate with Spotify: %s', str(e), exc_info=True) flash.warn('Unable to authenticate with Spotify (error {})'.format(e.args[0])) return redirect(url_for('profile.connect_spotify'))
def connect_spotify(): if request.method == 'POST' and request.form.get('delete') == 'yes': spotify.remove_user(current_user.id) flash.success('Your Spotify account has been unlinked') user = spotify.get_user(current_user.id) spotify_url = None if not user: sp_oauth = spotify.get_spotify_oauth() spotify_url = sp_oauth.get_authorize_url() return render_template( 'user/spotify.html', account=user, last_updated=user.last_updated_iso if user else None, latest_listened_at=user.latest_listened_at_iso if user else None, spotify_login_url=spotify_url)
def connect_spotify(): if request.method == 'POST' and request.form.get('delete') == 'yes': spotify.remove_user(current_user.id) flash.success('Your Spotify account has been unlinked') user = spotify.get_user(current_user.id) spotify_url = None if not user: sp_oauth = spotify.get_spotify_oauth() spotify_url = sp_oauth.get_authorize_url() return render_template( 'user/spotify.html', account=user, last_updated=user.last_updated_iso if user else None, latest_listened_at=user.latest_listened_at_iso if user else None, spotify_login_url=spotify_url )
def connect_spotify_callback(): code = request.args.get('code') if not code: raise BadRequest('missing code') sp_oauth = spotify.get_spotify_oauth() try: token = sp_oauth.get_access_token(code) spotify.add_new_user(current_user.id, token) flash.success('Successfully authenticated with Spotify!') except spotipy.oauth2.SpotifyOauthError as e: current_app.logger.error('Unable to authenticate with Spotify: %s', str(e), exc_info=True) flash.warn('Unable to authenticate with Spotify (error {})'.format( e.args[0])) return redirect(url_for('profile.connect_spotify'))
def test_get_spotify_oauth(self): func_oauth = spotify.get_spotify_oauth() self.assertEqual(func_oauth.client_id, current_app.config['SPOTIFY_CLIENT_ID']) self.assertEqual(func_oauth.client_secret, current_app.config['SPOTIFY_CLIENT_SECRET']) self.assertEqual(func_oauth.redirect_uri, 'http://localhost/profile/connect-spotify/callback') self.assertEqual(func_oauth.scope, 'user-read-recently-played')