def test_updateSpotifyfromBDD(self): class Mock_Track: def __init__(self, id, name, artist, album, duration): self.id = id self.name = name self.artist = artist self.album = album self.duration = duration mock1 = Mock_Track('08jkW1RWXUwKA3W0bqWGuU', 'Get Lucky - Karaoke', 'Tribute to Daft Punk', 'Get Lucky', 258101) mock2 = Mock_Track('58MZs0B5Amxl0Mwc9FIRZc', 'DARE - Junior Sanchez Remix', 'Gorillaz', 'D-Sides [Special Edition]', 326373) objapi = APISFY("credenciales.txt") objbdd = DBSFY('Arma_tu_biblio_test.db') objsync = sinchronize() idsSp = objapi.getPlaylistsIDSfromSpotify() print("getPlaylistfromSpotify berfore delete", idsSp) try: print("Borrando playlist de spotify...") objapi.deleteTrack(idsSp) print("Borrado") print("Borrando base de datos...") objbdd.deleteAllTracks() print("Borrada") bddlist = objbdd.getPlaylistFromDB() if len(bddlist) < 1: print("lista vacia") objbdd.saveTrack(mock1) objbdd.saveTrack(mock2) print("Tracks added to db") playlistbdd = objbdd.getPlaylistFromDB() ids = objbdd.getIDSFromDB(playlistbdd) print(ids) print(objsync.updateSpotifyfromBDD(objapi, ids)) ids = objapi.getPlaylistsIDSfromSpotify() print("getPlaylistfromSpotify ", ids) else: print("hey i love you") except: print("Error in test_updateSpotifyfromBDD")
def test_getIDSfromDB(self): class Mock_Track: def __init__(self,id, name, artist, album, duration): self.id = id self.name = name self.artist = artist self.album = album self.duration = duration obj=DBSFY('Arma_tu_biblio.db') try: obj.deleteAllTracks() except: return 1 mock1=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',"Dare",'Gorillaz','D-Sides [Special Edition]', 326373123) mock2=Mock_Track('BBBBBBBBBBBBBBBBBBBBBB',"Get Lucky",'Daft Punk','Album Daft-Punk', 326373123) obj.saveTrack(mock1) obj.saveTrack(mock2) playlist=obj.getPlaylistFromDB() r=['AAAAAAAAAAAAAAAAAAAAAA','BBBBBBBBBBBBBBBBBBBBBB'] self.assertEqual(obj.getIDSFromDB(playlist),r)
class SpotyPie(): api=None bdd=None sync=None def __init__(self,credentialsFilePath,BDDFIlePath ): self.sync=sinchronize() self.bdd=DBSFY(BDDFIlePath) self.api=APISFY(credentialsFilePath) self.makeSync() print() #><<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ok def searchTrack(self, songName, artistName): return self.api.getTrackfromSpotify(songName,artistName) #><<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ok def addTrackToMyPlaylist(self,track):#must be Track Object idlist_adapt={track.id} if self.api.saveTrack(idlist_adapt) !=0: print (" [-] Error in addTrackToMyPlaylist") return 1 self.bdd.saveTrack(track) return 0 #><<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ok def showMyPlaylist(self): playlist=[] try: playlist=self.bdd.getPlaylistFromDB() if len(playlist)>0: #print(self.api.printPlaylist(playlist)) return self.api.printPlaylist(playlist) return playlist except: print(" [-] Error in showMyPlaylist:getPlaylistFromDB") return 1 #><<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ok def deleteTrack(self,idtrack): #pasarlo en forma de str #print("deleting...",idtrack) # try: listid_adapt=[idtrack] if self.api.deleteTrack(listid_adapt)!=0: print(" [-] Error in deleteTrack:api") return 1 if self.bdd.deleteTrack(idtrack) != 0: print(" [-] Error in deleteTrack:bdd") return 1 return 0 # except: # print("Error in deleteTrack") # return 1 #><<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ok def deleteAllTracks(self): try: playlist_sp=self.api.getPlaylistsIDSfromSpotify() #print("playlist: >>> ",playlist_sp) if len(playlist_sp)>0: if self.api.deleteTrack(playlist_sp) !=0: print(" [-] Error in delete track from spotify") return 1 print(" [+] Tracks deleted from spotify") idsbdd=self.bdd.getIDSFromDB(self.bdd.getPlaylistFromDB()) #print(" >>>>>>>>>",idsbdd) if len(idsbdd)>0: if self.bdd.deleteAllTracks()!=0: return 1 print(" [+] Tracks deleted from database") if len(idsbdd)<1 and len(playlist_sp)<1: print(" [+] No hay informacion") return 1 print(" [+] Tracks deleted") return 0 except: return 1 print(" [-] Error in deleteAllTrack") # ><<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> def close(self): try: self.bdd.con.close() self.bdd=None self.api=None # except: print(" [-] Error in close") return 1 #><<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> def makeSync(self): # try: # print("Debuging makesync") unsync=[] idsSpotify=self.api.getPlaylistsIDSfromSpotify() # print(" > idsSpotify: ",idsSpotify) # ok if len(idsSpotify)>0: tracksbdd=self.bdd.getPlaylistFromDB() # print(" > tracksbdd: ",tracksbdd) # ok if type(tracksbdd)==int: print(" [-] Type is int!") return 1 if(len(tracksbdd)>0): idsBDD=self.bdd.getIDSFromDB(tracksbdd) # print(" > idsBDD: ",idsBDD) # ok unsync=self.sync.checkBDDvsSpotify(idsSpotify,idsBDD) # print(" > unsync: ",unsync) # ok if(len(unsync)>0): self.sync.updateSpotifyfromBDD(self.api,unsync) self.bdd.deleteAllTracks() # print("\n\nself.api.getTrackslistfromSpotify() ",self.api.getTrackslistfromSpotify()) self.sync.updateBDDfromSpotify(self.api.getTrackslistfromSpotify(),self.bdd) #print("Synchronized 01!") return 0 else: self.sync.updateBDDfromSpotify(self.api.getTrackslistfromSpotify(),self.bdd) #print("Synchronized 02!") return 0 idsbdd=self.bdd.getIDSFromDB(self.bdd.getPlaylistFromDB()) if len(idsbdd)>0: self.sync.updateSpotifyfromBDD(self.api,idsbdd) #print("Synchronized! 03") return 0 else: print(" [+] Nada que sincronizar") return 0 print() return 1