chiark / gitweb /
Disobedience: basic support for required/prohibited tags.
[disorder] / tests / queue.py
CommitLineData
abf54aca 1#! /usr/bin/env python
213b4064
RK
2#
3# This file is part of DisOrder.
5aff007d 4# Copyright (C) 2007, 2008 Richard Kettlewell
213b4064 5#
e7eb3a27 6# This program is free software: you can redistribute it and/or modify
213b4064 7# it under the terms of the GNU General Public License as published by
e7eb3a27 8# the Free Software Foundation, either version 3 of the License, or
213b4064
RK
9# (at your option) any later version.
10#
e7eb3a27
RK
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
213b4064 16# You should have received a copy of the GNU General Public License
e7eb3a27 17# along with this program. If not, see <http://www.gnu.org/licenses/>.
213b4064 18#
d48eab4d 19import dtest,time,disorder,re
213b4064 20
61192f93
RK
21class wait_monitor(disorder.monitor):
22 def queue(self, q):
23 return False
24
213b4064 25def test():
96372bd1 26 """Check the queue is padded to the (default) configured length"""
213b4064 27 dtest.start_daemon()
f0feb22e 28 dtest.create_user()
213b4064 29 c = disorder.client()
61192f93
RK
30 print " disabling play"
31 c.disable()
32 print " waiting for queue to be populated..."
213b4064 33 q = c.queue()
61192f93
RK
34 while len(q) < 5:
35 print " queue at %d tracks" % len(q)
36 wait_monitor().run()
37 q = c.queue()
d48eab4d 38 print " getting queue via disorder(1)"
63ad732f
RK
39 q = dtest.command(["disorder",
40 "--config", disorder._configfile, "--no-per-user-config",
41 "queue"])
d48eab4d 42 tracks = filter(lambda s: re.match("^track", s), q)
61192f93 43 assert len(tracks) == 5, "queue is at proper length"
81e440ce
RK
44 print " disabling random play"
45 c.random_disable()
46 print " emptying queue"
47 for t in c.queue():
48 c.remove(t['id'])
49 print " checking queue is now empty"
50 q = c.queue()
51 assert q == [], "checking queue is empty"
52 print " enabling random play"
53 c.random_enable()
61192f93 54 print " waiting for queue to refill..."
81e440ce 55 q = c.queue()
61192f93
RK
56 while len(q) < 5:
57 print " queue at %d tracks" % len(q)
58 wait_monitor().run()
59 q = c.queue()
81e440ce
RK
60 print " disabling all play"
61 c.random_disable()
62 c.disable()
63 print " emptying queue"
64 for t in c.queue():
65 c.remove(t['id'])
66 t1 = "%s/Joe Bloggs/Third Album/01:First_track.ogg" % dtest.tracks
67 t2 = "%s/Joe Bloggs/Third Album/02:Second_track.ogg" % dtest.tracks
68 t3 = "%s/Joe Bloggs/Third Album/02:Second_track.ogg" % dtest.tracks
69 print " adding tracks"
70 i1 = c.play(t1)
71 i2 = c.play(t2)
72 i3 = c.play(t3)
73 q = c.queue()
74 assert map(lambda e:e['id'], q) == [i1, i2, i3], "checking queue order(1)"
75 print " moving last track to start"
76 c.moveafter(None, [i3])
77 q = c.queue()
78 assert map(lambda e:e['id'], q) == [i3, i1, i2], "checking queue order(2)"
79 print " moving two tracks"
80 c.moveafter(i1, [i2, i3])
81 q = c.queue()
82 assert map(lambda e:e['id'], q) == [i1, i2 ,i3], "checking queue order(3)"
83 print " removing a track"
84 c.remove(i2)
85 q = c.queue()
86 assert map(lambda e:e['id'], q) == [i1 ,i3], "checking queue order(4)"
213b4064
RK
87
88if __name__ == '__main__':
89 dtest.run()