def test_make_spotify_request_with_config_timeout_uses_timeout_value(self, mock_auth, mock_request, spotify_client): config_client_id = 'config-client-id' config_secret_key = 'config-secret-key' timeout_value = 5 Config.configure(config_client_id, config_secret_key, timeout_value) client = SpotifyClient() auth_code = 'test-auth-code' dummy_response = {'status': 200, 'content': 'OK'} dummy_params = {'query': 'param'} dummy_data = {'key': 'value'} mock_response = mock.Mock() mock_response.raise_for_status.side_effect = None mock_response.json.return_value = dummy_response mock_auth.return_value = auth_code mock_request.return_value = mock_response resp = client._make_spotify_request('GET', '/dummy_endpoint', data=dummy_data, params=dummy_params) mock_request.assert_called_with( 'GET', '/dummy_endpoint', params=dummy_params, data=dummy_data, headers={'Authorization': 'Bearer {}'.format(auth_code)}, json=None, timeout=timeout_value, ) assert resp == dummy_response Config.clear_config()
def test_config_setup(self): client_id = 'test-client-id' secret_key = 'test-secret-key' Config.configure(client_id, secret_key) assert Config.CLIENT_ID == client_id assert Config.SECRET_KEY == secret_key
def test_auth_variables_are_read_from_config_if_configured(self): test_client_id = 'my-test-client-id' test_secret_key = 'my-test-secret-key' Config.configure(test_client_id, test_secret_key) client = SpotifyClient() assert client.client_id == test_client_id assert client.secret_key == test_secret_key
def test_auth_variables_are_read_from_parameters_if_passed(self): test_client_id = 'my-test-client-id' test_secret_key = 'my-test-secret-key' config_client_id = 'config-client-id' config_secret_key = 'config-secret-key' Config.configure(config_client_id, config_secret_key) client = SpotifyClient(test_client_id, test_secret_key) assert client.client_id == test_client_id assert client.secret_key == test_secret_key
from spotify_client import SpotifyClient from spotify_client.config import Config from codigo import SPOTIFY_CLIENT_ID from codigo import SPOTIFY_SECRET_KEY import playlist """ SPOTIFY_CLIENT_ID = '3292435de433462e94b8cd41f52c56d1' SPOTIFY_SECRET_KEY = '1ef25093520b4548aa1729ab296e17e8' AUTH_CODE = 'BQAEPapr4EOZXXWal4veZcnLWE8HpJgThTKBLBc0JyE-ec0wY2O96ap137msZd-JyIp-__dn2JdVSLKk5JRuRExDOO7Un04PuOGqsRYK6DEkXg7RtRu_aHlLMqGaYJWtTa5OOvIU6CH2VY42crT4MR8HudUiyjAxFffKp9Z287VZEOrWgz6O5FIBqxvjz1tg7uaIqOl-Vbl2xaZnBtsWrXNgOIlkRMH2kmnPQDlhWWqI' from spotify_client import SpotifyClient from spotify_client.config import Config Config.configure(SPOTIFY_CLIENT_ID, SPOTIFY_SECRET_KEY) client = SpotifyClient(SPOTIFY_CLIENT_ID, SPOTIFY_SECRET_KEY, identifier='test-spotify-client') user_id = "lauta1" playlist_name = "TEST-4" #song_name = ['spotify:track:3CYH422oy1cZNoo0GTG1TK', 'spotify:track:4Ws314Ylb27BVsvlZOy30C'] #client.create_playlist(AUTH_CODE,user_id,playlist_name) #Playlist_ID = "3NI721NPLpw1hgOBuxq2vX" #client.add_songs_to_playlist(AUTH_CODE,Playlist_ID,song_name) client.create_playlist(AUTH_CODE,user_id,playlist_name) """ spotifiId = SPOTIFY_CLIENT_ID secret_code = SPOTIFY_SECRET_KEY user_name = 'lauta1' nombre = 'prueba3'
'client_id': env.str('MTDJ_SPOTIFY_CLIENT_ID', default='__spotify_client_id_not_set__'), 'secret_key': env.str('MTDJ_SPOTIFY_SECRET_KEY', default='__spotify_secret_key_not_set__'), 'categories': env.list('MTDJ_SPOTIFY_CATEGORIES', default=['hiphop', 'rock', 'chill']), 'max_songs_from_list': env.int('MTDJ_SPOTIFY_MAX_SONGS_FROM_LIST', default=10), 'max_songs_from_category': env.int('MTDJ_SPOTIFY_MAX_SONGS_FROM_CATEGORY', default=25), 'max_playlist_from_category': env.int('MTDJ_SPOTIFY_MAX_PLAYLISTS_FROM_CATEGORY', default=10), 'auth_redirect_uri': env.str('MTDJ_SPOTIFY_REDIRECT_URI', default='https://moodytunes.vm/spotify/callback/'), 'auth_user_token_timeout': 60 * 60, # User auth token is good for one hour 'auth_user_scopes': [ SPOTIFY_PLAYLIST_MODIFY_SCOPE, SPOTIFY_TOP_ARTIST_READ_SCOPE, SPOTIFY_UPLOAD_PLAYLIST_IMAGE ], 'max_top_artists': env.int('MTDJ_SPOTIFY_MAX_TOP_ARTISTS', default=50), 'session_state_length': env.int('MTDJ_SPOTIFY_AUTH_STATE_LENGTH', default=48), } # Configure SpotifyClient with authentication credentials Config.configure(SPOTIFY['client_id'], SPOTIFY['secret_key'])
def test_no_configuration_set_raises_error(self): Config.clear_config() with pytest.raises(ImproperlyConfigured): SpotifyClient()
import requests from spotify_client import SpotifyClient from codigo import SPOTIFY_CLIENT_ID from codigo import SPOTIFY_SECRET_KEY from codigo import YOUTUBE_DEVELOPER_KEY from spotify_client.config import Config from googleapiclient.discovery import build import json import youtube_dl """SPOTIFY""" #configuracion y conexion Config.configure(SPOTIFY_CLIENT_ID, SPOTIFY_SECRET_KEY) client = SpotifyClient(SPOTIFY_CLIENT_ID, SPOTIFY_SECRET_KEY, identifier='test-spotify-client') #Crear playlist def createPlaylist(token, user_id, playlist_name): """ Token = Recibe el auth_code el cual es el token de spotify del usuario -> string User_id = recibe el el nombre de usuario de la cuenta de spotify -> string Playlist_name = El nombre de la platlist -> string """ try: return client.create_playlist(token, user_id, playlist_name)