def test_updateBDDfromSpotify(self): objapi=APISFY("credenciales.txt") objbdd=DBSFY('Arma_tu_biblio.db') objsync=sinchronize() ids=objapi.getPlaylistsIDSfromSpotify() #print("getPlaylistfromSpotify berfore delete",ids) #tracks=objapi.getTrackslistfromSpotify() try: tracksid=[] print(objbdd.deleteAllTracks()) # para prueba print(objapi.deleteTrack(ids)) # para prueba track1=objapi.getTrackfromSpotify('Dare','Gorillaz') tracksid.append(track1.id) #print(track1) track2=objapi.getTrackfromSpotify('Get lucky','Daft Punk') tracksid.append(track2.id) objapi.saveTrack(tracksid) #se guardaron los dos para la prueba print("tracks saved\nPlaylist spotify:\n") # play=objapi.getTrackslistfromSpotify() print(objapi.printPlaylist(play)) print("***************************************") self.assertEqual(0,objsync.updateBDDfromSpotify(play,objbdd)) bddplaylist=objbdd.getPlaylistFromDB() print(len(bddplaylist)) print(objapi.printPlaylist(bddplaylist)) except: print("Error en test_updateBDDfromSpotify")
def test_getPlaylisrFromDB(self): #revisar que pasa cuando no tienes nada en la labase obj=DBSFY('Arma_tu_biblio.db') showTracks = obj.getPlaylistFromDB() try: for x in showTracks: print(x) except: print("Error")
def test_deleteAllTracks(self): obj=DBSFY('Arma_tu_biblio.db') showTracks = obj.getPlaylistFromDB() try: for x in showTracks: print(x) print("Borrando todo...") obj.deleteAllTracks() print("Borrado...") except: print("Error")
def test_getTrackfromPlaylistWithID(self): # # CASO DE PRUEBA: playlist vacia **************************************** <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEST CASE # guardar unos dos tracks, obtenerlos y luego mostrarlos # mock de clase track 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 objBDD=DBSFY('Arma_tu_biblio.db') objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos objTrack=Mock_Track('58MZs0B5Amxl0Mwc9FIRZc','DARE - Junior Sanchez Remix','Gorillaz','D-Sides [Special Edition]', 326373) objBDD.saveTrack(objTrack) objTrack=Mock_Track('6TY7U0B5Amxl0Mwc9F1234','Una cancion','El artista','Mejor album', 387373) objBDD.saveTrack(objTrack) playlist=objBDD.getPlaylistFromDB() a=APISFY("credenciales.txt") # print(a.getTrackfromPlaylistWithID(playlist,0)) a=None objeBDD=None objTrack=None playlist=None
def test_deleteTrack(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 bdd=DBSFY('Arma_tu_biblio.db') objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',"Dare",'Gorillaz','D-Sides [Special Edition]', 326373) bdd.cur.execute("DELETE FROM Track") bdd.con.commit() print("Base de datos limpia") bdd.saveTrack(objTrack) print("\n\nTrack saved, print tracks ... \n\n") q=bdd.cur.execute("SELECT * FROM Track").fetchall() for reg in q: print(reg) print("\n\nBorrando track ...\n\n") bdd.deleteTrack(objTrack.id) # print("Borrado \nMostrando base de datos(debe estar vacia)") # r=bdd.cur.execute("SELECT * FROM Track").fetchall() for reg in r: print(":",reg) print("registros: ",r) self.assertEqual(len(r),0)
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
def __init__(self,credentialsFilePath,BDDFIlePath ): self.sync=sinchronize() self.bdd=DBSFY(BDDFIlePath) self.api=APISFY(credentialsFilePath) self.makeSync() print()
def test_saveTrack(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 objBDD=DBSFY('Arma_tu_biblio.db') # #CASO DE PRUEBA: UN TRACK CORRECTO **************************************** <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEST CASE objTrack=Mock_Track('58MZs0B5Amxl0Mwc9FIRZc','DARE - Junior Sanchez Remix','Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos objBDD.saveTrack(objTrack) a=objBDD.getPlaylistFromDB() print(a[0].__str__()) self.assertEqual((a[0]).__str__(),"[58MZs0B5Amxl0Mwc9FIRZc, DARE - Junior Sanchez Remix, Gorillaz, D-Sides [Special Edition], 326373]") #CASO DE PRUEBA DE UN TRACK NULO **************************************** <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEST CASE print("TEST CASE: TRACK NULO") objTrack=None objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) self.assertEqual(a,1) # #CASO DE PRUEA: EL TRACK YA EXISTE **************************************** <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEST CASE print("TEST CASE: EL TRACK YA EXISTE") printer=APISFY("credenciales.txt") objTrack=Mock_Track('58MZs0B5Amxl0Mwc9FIRZc','DARE - Junior Sanchez Remix','Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") b=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if b==0 else print(objTrack.id,"No guardado") self.assertEqual(a,0) # si se guarda la primera vez self.assertEqual(b,1) # no se guarda la segunda vez play=objBDD.getPlaylistFromDB() m=printer.printPlaylist(play) self.assertEqual(len(play),1)#validar que solo se haya guardado uno #CASOS DE PRUEBA: PRUEBAS A id *************************************** <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEST CASES URI print("TEST CASE: id es ' ' ") #************************************************************************** objTrack=Mock_Track(' ','DARE - Junior Sanchez Remix','Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack= None print("TEST CASE: id es '' ") #************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Cancion',' ','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: id es None ") #************************************************************************** objTrack=Mock_Track(None,'DARE - Junior Sanchez Remix','Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack = None #continuar con string,float, zero pading, negatives, more than len and different print("TEST CASE: id es MAYOR A 22") #********************************************************************** objTrack=Mock_Track('A'*23,'DARE - Junior Sanchez Remix','Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack= None # caracteres no imprimibles y algunos especiales print("TEST CASE: id tiene caracteres especiales") #******************************************************* objTrack=Mock_Track('@'*22,'DARE - Junior Sanchez Remix','Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None #checar con float print("TEST CASE: id float") #***************************************************************************** objTrack=Mock_Track(234567890123456789.00,'DARE - Junior Sanchez Remix','Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None # print("TEST CASE: id tiene padding de ceros") #************************************************************ objTrack=Mock_Track(("0"*20)+"22",'DARE - Junior Sanchez Remix','Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,0) # lo guarda objTrack= None # CASOS DE PRUEBA: PRUEBAS A NAME *************************************** <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEST CASES NAME print("TEST CASE: name es ' ' ") #************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',' ','Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: Name es '' ") #************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Cancion','','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None # print("TEST CASE: name es None ") #************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',None,'Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: name es MAYOR A 100") #********************************************************************** objTrack=Mock_Track('A'*22,"B"*101,'Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: name tiene caracteres especiales") #******************************************************* objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',"Dare",'Gorillaz','D-Sides [Special Edition]', 326373) objTrack.name="@#$%%&/()=" objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,0) # lo guarda por que aun no se ha definido esta validacion objTrack=None # checar con int print("TEST CASE: name int como int") #***************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',1234,'Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda por que acepta solo strings objTrack= None print("TEST CASE: name int como string") #*************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',"1234",'Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,0) # lo guarda por que esta como string objTrack = None print("TEST CASE: name flaot como tal") #**************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',1234.5,'Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda por que acepta solo strings objTrack= None # print("TEST CASE: name float como string") #*************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',"1234.5",'Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,0) # lo guarda por que esta como string objTrack=None # aun falta validar mas detalles, mas casos de prueba y mejorar el codigo #CASOS DE PRUEBA: PRUEBAS A ARITST *************************************** <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEST CASES ARTIST print("TEST CASE: artist es ' ' ") #************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Cancion',' ','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: artist es '' ") #************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Cancion','','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None # print("TEST CASE: artist es None ") #************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Cancion',None,'D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: artist es MAYOR A 100") #********************************************************************** objTrack=Mock_Track('A'*22,'Dare',"B"*101,'D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: artist tiene caracteres especiales") #******************************************************* objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',"Dare",'$#%&/=','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,0) # lo guarda por que aun no se ha definido esta validacion objTrack=None # # # checar con int print("TEST CASE: artist int como int") #***************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Dare',1234,'D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda por que acepta solo strings objTrack= None print("TEST CASE: artist int como string") #*************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',"Dare",'1234','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,0) # lo guarda por que esta como string objTrack = None print("TEST CASE: artist flaot como tal") #**************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Dare',1234.5,'D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda por que acepta solo strings objTrack= None print("TEST CASE: artist float como string") #*************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',"Dare",'1234.5','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,0) # lo guarda por que esta como string objTrack=None #aun falta validar mas detalles, mas casos de prueba y mejorar el codigo # CASOS DE PRUEBA: PRUEBAS A ALBUM *************************************** <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEST CASES album print("TEST CASE: album es ' ' ") #************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Cancion','Gorillaz',' ', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: album es '' ") #************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Cancion','Gorillaz','', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: album es None ") #************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Cancion',"Gorillaz",None, 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: album es MAYOR A 50") #********************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Dare',"Gorillaz",'B'*101, 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: album tiene caracteres especiales") #******************************************************* objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',"Dare",'Gorillaz','D-Sides [Special Edition]', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,0) # lo guarda por que aun no se ha definido esta validacion objTrack=None # # checar con int print("TEST CASE: album int como int") #***************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Dare',"Gorillaz",1234, 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda por que acepta solo strings objTrack= None print("TEST CASE: album int como string") #*************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',"Dare","Gorillaz",'1234', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,0) # lo guarda por que esta como string objTrack = None print("TEST CASE: album flaot como tal") #**************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Dare',"Gorillaz",1234.5, 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda por que acepta solo strings objTrack= None print("TEST CASE: album float como string") #*************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',"Dare",'Gorillaz','1234.5', 326373) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,0) # lo guarda por que esta como string objTrack=None # aun falta validar mas detalles, mas casos de prueba y mejorar el codigo #CASOS DE PRUEBA: PRUEBAS A DURATION *************************************** <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEST CASES DURATION print("TEST CASE: duration es ' ' ") #************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Cancion','Gorillaz','D-Sides [Special Edition]', ' ' ) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: duration es '' ") #************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Cancion','Gorillaz','D-Sides [Special Edition]', '') objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: duration es None ") #************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Cancion',"Gorillaz",'D-Sides [Special Edition]', None) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: duration es string") #********************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Dare',"Gorillaz",'D-Sides [Special Edition]', "Esto es una cadena") objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None print("TEST CASE: duration mayor a 2147483647") #******************************************************* objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',"Dare",'Gorillaz','D-Sides [Special Edition]', 2147483647+3) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no guarda objTrack=None # checar con int print("TEST CASE: duration es 0") #***************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Dare',"Gorillaz",'D-Sides [Special Edition]', 0) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda por que acepta solo strings objTrack= None print("TEST CASE: duration es negativo") #*************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',"Dare","Gorillaz",'D-Sides [Special Edition]', -1) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack = None print("TEST CASE: duration flaot") #**************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA','Dare',"Gorillaz",'D-Sides [Special Edition]', 326373.5) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda por que acepta solo strings objTrack= None print("TEST CASE: duration float como double") #*************************************************************************** objTrack=Mock_Track('AAAAAAAAAAAAAAAAAAAAAA',"Dare",'Gorillaz','D-Sides [Special Edition]', 326373.15) objBDD.cur.execute("DELETE FROM Track")#limpiamos la base de datos a=objBDD.saveTrack(objTrack) print(objTrack.id, "guardado") if a==0 else print(objTrack.id,"No guardado") self.assertEqual(a,1) # no lo guarda objTrack=None
def __init__(self, credentialsFilePath, BDDFIlePath): sync = synchronize() bdd = DBSFY(BDDFIlePath) api = APISF(credentialsFilePath) self.makeSync()
def main(): apisfy = APISFY() dbsfy = DBSFY('Arma_tu_biblio.db') print('Bienvenido akralma, ¿Que quieres hacer?') cont = 0 option = int( input('1. Buscar canción' + '\n' + '2. Ver tu biblioteca' + '\n' + '3. Modificar tu biblioteca' + '\n' '4. Salir' + '\n' + '5. Migrar Datos' + '\n')) library = sp.current_user_saved_tracks() while cont == 0: if option == 1: list_tracks = [] track = search_info(APISFY) print('¿Quieres agregar esta cancion a tu biblioteca?') save = int(input('1. Si' + '\n' + '2. No' + '\n')) if save == 1: list_tracks.append(track.id) sp.current_user_saved_tracks_add( list_tracks) # Guarda en biblioteca save_track(dbsfy, library) #Guarda archivo en DB print('La canción ha sido agregada' + '\n') elif save == 2: print(option) if option == 2: show_track(dbsfy) if option == 3: name = input('¿Cual cancion quieres eliminar?: ' + '\n') del_track(dbsfy, name) print('¿Quieres seguir eliminando?' + '\n') stop = int(input('1.Si ' + '2. No' + '\n')) if stop == 1: print(name) else: print(option) if option == 4: sys.exit() if option == 5: library = sp.current_user_saved_tracks() for item in library['items']: song = item['track'] iD = song['id'] name = song['name'] artist = song['artists'][0]['name'] album = song['album']['name'] duration = song['duration_ms'] conect = sqlite3.connect('Arma_tu_biblio.db') cursor = conect.cursor() cursor.execute("INSERT INTO Track VALUES" "('{}','{}','{}','{}','{}')".format( iD, name, artist, album, duration)) conect.commit() conect.close()