Commit | Line | Data |
---|---|---|
f35e5800 RK |
1 | #! /usr/bin/env python |
2 | # | |
3 | # This file is part of DisOrder. | |
4 | # Copyright (C) 2007 Richard Kettlewell | |
5 | # | |
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 2 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, but | |
12 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | # General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
19 | # USA | |
20 | # | |
21 | import dtest,time,disorder,re | |
22 | ||
23 | def test(): | |
24 | """Exercise database dumper""" | |
25 | dtest.start_daemon() | |
26 | c = disorder.client() | |
27 | track = "%s/Joe Bloggs/First Album/02:Second track.ogg" % dtest.tracks | |
28 | dump = "%s/dumpfile" % dtest.testroot | |
29 | print "setting a track pref" | |
30 | c.set(track, "foo", "before") | |
31 | assert c.get(track, "foo") == "before", "checking track foo=before" | |
32 | print "setting a global pref" | |
33 | c.setglobal("foo", "before"); | |
34 | assert c.getglobal("foo") == "before", "checking global foo=before" | |
f47d40ba | 35 | print "adding a tag" |
31773020 RK |
36 | # Exercise the tags-changed code |
37 | c.set(track, "tags", "first tag, another tag") | |
38 | assert dtest.lists_have_same_contents(c.tags(), | |
39 | [u"another tag", u"first tag"]),\ | |
40 | "checking tag list(1)" | |
41 | c.set(track, "tags", "wibble, another tag") | |
42 | assert dtest.lists_have_same_contents(c.tags(), | |
43 | [u"another tag", u"wibble"]),\ | |
44 | "checking tag list(2)" | |
f47d40ba RK |
45 | print "checking track appears in tag search" |
46 | tracks = c.search(["tag:wibble"]) | |
47 | assert len(tracks) == 1, "checking there is exactly one search result" | |
48 | assert tracks[0] == track, "checking for right search result" | |
f35e5800 RK |
49 | print "dumping database" |
50 | print dtest.command(["disorder-dump", "--config", disorder._configfile, | |
51 | "--dump", dump]) | |
52 | print "changing track pref" | |
53 | c.set(track, "foo", "after"); | |
54 | assert c.get(track, "foo") == "after", "checking track foo=before" | |
55 | print "changing global pref" | |
56 | c.setglobal("foo", "after"); | |
57 | assert c.getglobal("foo") == "after", "checking global foo=before" | |
fb1bc1f5 RK |
58 | print "adding fresh track pref" |
59 | c.set(track, "bar", "after") | |
60 | print "adding fresh global pref" | |
61 | c.setglobal("bar", "after") | |
f35e5800 RK |
62 | dtest.stop_daemon(); |
63 | print "restoring database" | |
64 | print dtest.command(["disorder-dump", "--config", disorder._configfile, | |
65 | "--undump", dump]) | |
66 | dtest.start_daemon(); | |
67 | c = disorder.client() | |
68 | print "checking track pref" | |
69 | assert c.get(track, "foo") == "before", "checking track foo=before after undump" | |
70 | print "checking global pref" | |
71 | assert c.getglobal("foo") == "before", "checking global foo=before after undump" | |
fb1bc1f5 RK |
72 | print "checking fresh track pref" |
73 | assert c.get(track, "bar") is None, "checking fresh track pref has gone" | |
74 | print "checking fresh global pref" | |
75 | assert c.getglobal("bar") is None, "checking fresh global pref has gone" | |
f47d40ba RK |
76 | print "checking tag search still works" |
77 | tracks = c.search(["tag:wibble"]) | |
78 | assert len(tracks) == 1, "checking there is exactly one search result" | |
79 | assert tracks[0] == track, "checking for right search result" | |
31773020 RK |
80 | assert dtest.lists_have_same_contents(c.tags(), |
81 | [u"another tag", u"wibble"]),\ | |
82 | "checking tag list(3)" | |
f35e5800 RK |
83 | |
84 | if __name__ == '__main__': | |
85 | dtest.run() |