304caaad178411d706b597b6b24102b1d7ee48f5
[jamaendo] / tests / testicle
1 #!/usr/bin/env python
2 # runs tons of test queries against the API,
3 # sleeping between each and printing the result
4
5 # debugging hack - add . to path
6 import os, sys
7 local_module_dir = os.path.join(os.path.dirname(sys.argv[0]), '..')
8 if os.path.isdir(local_module_dir):
9     sys.path.append(os.path.abspath(local_module_dir))
10
11 import time
12
13 import jamaendo.api2 as api2
14
15 class Tests(object):
16     def XXXtestSearchArtists(self):
17         result = api2.search_artists('porn')
18         print "Result:", result
19         print "Cache:", api2._artists
20
21     def XXXtestSearchAlbums(self):
22         result = api2.search_albums('porn')
23         print "Result:", result
24         print "Cache:", api2._albums
25
26     def XXXtestSearchTracks(self):
27         result = api2.search_tracks('porn')
28         print "Result:", result
29         print "Cache:", api2._tracks
30
31     def XXXtestAlbumsOfTheWeek(self):
32         result = api2.albums_of_the_week()
33         print "Result:", result
34         print "Cache:", api2._albums
35
36     def XXXtestNewReleases(self):
37         result = api2.new_releases()
38         print "Result:", result
39         print "Cache:", api2._tracks
40
41     def XXXtestTracksOfTheWeek(self):
42         result = api2.tracks_of_the_week()
43         print "Result:", result
44         print "Cache:", api2._tracks
45
46     def XXXtestStarredRadios(self):
47         result = api2.starred_radios()
48         print "Result:", result
49
50     def XXXtestGetRadio283(self):
51         result = api2.get_radio(283)
52         print "Result:", result
53
54     def XXXtestGetArtist91(self):
55         result = api2.get_artist(91)
56         print "Result:", result
57
58     def XXXtestGetAlbum27865(self):
59         result = api2.get_album(27865)
60         print "Result:", result
61
62     def XXXtestGetTrack353341(self):
63         result = api2.get_track(353341)
64         print "Result:", result
65
66     def XXXtestGetTracks27865(self):
67         result = api2.get_tracks(27865)
68         print "Result:", result
69
70     def XXXtestGetAlbums91(self):
71         result = api2.get_albums(91)
72         print "Result:", result
73
74     def testGetAlbumCover27865(self):
75         result = api2.get_album_cover(27865)
76         print "Result:", result
77
78     def testGetAlbumCoverAsync27865(self):
79         self.got_cover = False
80         def gotit(cover):
81             print "Got:", cover
82             self.got_cover = True
83         api2.get_album_cover_async(gotit, 27865)
84         while not self.got_cover:
85             print "Waiting for cover..."
86             time.sleep(4)
87
88 import traceback
89
90 def main():
91     for name in Tests.__dict__.keys():
92         if name.startswith('test'):
93             print "Running %s" % (name)
94             try:
95                 t = Tests()
96                 getattr(t, name)()
97             except Exception, e:
98                 traceback.print_exc()
99             print "Waiting..."
100             time.sleep(10)
101
102 if __name__=="__main__":
103     main()