def setUp(self): self.client_id = 'qwerty' self.client_secret = 'ytrewq' self.redirect_uri = 'http://localhost/mixcloud-callback' self.o = mixcloud.MixcloudOauth(client_id=self.client_id, client_secret=self.client_secret, redirect_uri=self.redirect_uri) self.m = mixcloud.Mixcloud() httpretty.reset() self.mc = MockServer()
def mixcl(request): try: lst = [] a = UserSocialAuth.objects.get(user_id=request.user.id, provider='mixcloud') m = mixcloud.Mixcloud(access_token=a.access_token) u = m.user(a.uid) for c in u.cloudcasts(): lst.append(c.name) data = {'mixcloud': lst, 'm': m} return render(request, 'mixcloud.html', data) except UserSocialAuth.DoesNotExist: return render(request, 'mixcloud.html', {})
def get_context_data(self, **kwargs): context = super(AudioFileView, self).get_context_data(**kwargs) # soundcloud try: token = UserSocialAuth.objects.get(user_id=self.request.user.id, provider='soundcloud') client = soundcloud.Client(use_ssl=False, access_token=token.access_token) context['soundcloud'] = client.get('/me/tracks') except: context['soundcloud'] = None # spotify try: sp = UserSocialAuth.objects.get(user_id=self.request.user.id, provider='spotify') token = sp.access_token sp_client = spotipy.Spotify(auth=token) try: results = sp_client.current_user_saved_tracks() tracks = [] for item in results['items']: tracks.append(item['track']) context['tracks'] = tracks except spotipy.SpotifyException: # Expired token sp.delete() context['tracks'] = None except UserSocialAuth.DoesNotExist: context['tracks'] = None # mixcloud try: token = UserSocialAuth.objects.get(user_id=self.request.user.id, provider='mixcloud') client = mixcloud.Mixcloud(access_token=token.access_token) mxcld = [] for tracks in client.user(token.uid).cloudcasts(): mxcld.append(tracks) context['mixcloud'] = mxcld except: context['mixcloud'] = None return context
def testNetrc(self, netrc_init, netrc_authenticators): netrc_init.return_value = None # Don't blow up when netrc missing. netrc_authenticators.return_value = ('', None, 'my_access_token') m = mixcloud.Mixcloud() self.assertEqual(m.access_token, 'my_access_token')