3 # This file is part of DisOrder.
4 # Copyright (C) 2007 Richard Kettlewell
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.
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.
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
21 import dtest,time,disorder,re
24 """Exercise database dumper"""
28 track = "%s/Joe Bloggs/First Album/02:Second track.ogg" % dtest.tracks
29 dump = "%s/dumpfile" % dtest.testroot
30 print " setting a track pref"
31 c.set(track, "foo", "before")
32 assert c.get(track, "foo") == "before", "checking track foo=before"
33 print " setting a global pref"
34 c.setglobal("foo", "before");
35 assert c.getglobal("foo") == "before", "checking global foo=before"
37 # Exercise the tags-changed code
38 c.set(track, "tags", " first tag, Another Tag")
39 assert dtest.lists_have_same_contents(c.tags(),
40 [u"another tag", u"first tag"]),\
41 "checking tag list(1)"
42 c.set(track, "tags", "wibble, another tag ")
43 assert dtest.lists_have_same_contents(c.tags(),
44 [u"another tag", u"wibble"]),\
45 "checking tag list(2)"
46 print " checking track appears in tag search"
47 tracks = c.search(["tag:wibble"])
48 assert len(tracks) == 1, "checking there is exactly one search result(1)"
49 assert tracks[0] == track, "checking for right search result(1)"
50 tracks = c.search(["tag: another tAg "])
51 assert len(tracks) == 1, "checking there is exactly one search result(2)"
52 assert tracks[0] == track, "checking for right search result(2)"
53 print " dumping database"
54 print dtest.command(["disorder-dump", "--config", disorder._configfile,
56 print " changing track pref"
57 c.set(track, "foo", "after dump");
58 print c.get(track, "foo")
59 assert c.get(track, "foo") == "after dump", "checking track foo=after dump"
60 print " changing global pref"
61 c.setglobal("foo", "after dump");
62 assert c.getglobal("foo") == "after dump", "checking global foo=after dump"
63 print " adding fresh track pref"
64 c.set(track, "bar", "after dump")
65 print " adding fresh global pref"
66 c.setglobal("bar", "after dump")
68 print "restoring database"
69 print dtest.command(["disorder-dump", "--config", disorder._configfile,
73 print " checking track pref"
74 assert c.get(track, "foo") == "before", "checking track foo=before after undump"
75 print " checking global pref"
76 assert c.getglobal("foo") == "before", "checking global foo=before after undump"
77 print " checking fresh track pref"
78 assert c.get(track, "bar") is None, "checking fresh track pref has gone"
79 print " checking fresh global pref"
80 assert c.getglobal("bar") is None, "checking fresh global pref has gone"
81 print " checking tag search still works"
82 tracks = c.search(["tag:wibble"])
83 assert len(tracks) == 1, "checking there is exactly one search result"
84 assert tracks[0] == track, "checking for right search result(3)"
85 assert dtest.lists_have_same_contents(c.tags(),
86 [u"another tag", u"wibble"]),\
87 "checking tag list(3)"
89 if __name__ == '__main__':