-
Notifications
You must be signed in to change notification settings - Fork 1
/
hello_tests.py
104 lines (66 loc) · 2.36 KB
/
hello_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
import hello
from song import Song, SongList
import spotipy
spotify = spotipy.Spotify()
import unittest
import tempfile
class HelloTestCase(unittest.TestCase):
def setUp(self):
hello.app.config['TESTING'] = True
self.app = hello.app.test_client()
def tearDown(self):
print "finishing..."
#os.close(self.db_fd)
#os.unlink(hello.app.config['DATABASE'])
def test_create_song(self):
print "testing if songs are created correctly"
song = Song(1, "TestSong", "TestArtist", 0)
assert 'TestSong' in song.getTitle()
assert 1 == song.getId()
def test_song_score(self):
print "testing if song score is modified correctly"
song = Song(1, "TestSong", "TestArtist", 0)
assert 'TestSong' in song.getTitle()
assert 1 == song.getScore()
song.incrementScore()
assert 2 == song.getScore()
song.decrementScore()
assert 1 == song.getScore()
def test_create_songlist(self):
print "testing if songlist is created correctly and can add/retrieve songs"
songList = SongList()
song = Song(1, "TestSong", "TestArtist", 0)
songList.add(song)
songtest = songList.getSongAt(0)
assert 'TestSong' in songtest.getTitle()
assert 1 == songtest.getId()
def test_sort_songlist(self):
print "testing if songlist sorts songs properly"
songList = SongList()
song1 = Song(1, "TestSong1", "TestArtist", 0)
song2 = Song(2, "TestSong2", "TestArtist", 0)
song2.incrementScore() #song2 should end up in index 0 after sort
songList.add(song1)
songList.add(song2)
songList.sortList()
songtest = songList.getSongAt(0)
assert 'TestSong2' in songtest.getTitle()
assert 2 == songtest.getId()
def test_get_search_results(self):
print "testing if search result data is correctly extracted"
text = "wonderwall"
results = spotify.search(text, limit = 10, type = 'track')
assert 'Wonderwall' in results['tracks']['items'][0]['name']
def test_add_search_results(self):
print "testing if chosen search result is added correctly"
text = "wonderwall"
results = spotify.search(text, limit = 10, type = 'track')
title = results['tracks']['items'][0]['name']
artist = results['tracks']['items'][0]['artists'][0]['name']
uri = results['tracks']['items'][0]['uri']
song1 = Song(1, title, artist, uri)
assert 'Wonderwall' in song1.getTitle()
assert 'Oasis' in song1.getArtist()
if __name__ == '__main__':
unittest.main()