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"""
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"
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)"
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"
49 print "dumping database"
50 print dtest
.command(["disorder-dump", "--config", disorder
._configfile
,
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"
58 print "adding fresh track pref"
59 c
.set(track
, "bar", "after")
60 print "adding fresh global pref"
61 c
.setglobal("bar", "after")
63 print "restoring database"
64 print dtest
.command(["disorder-dump", "--config", disorder
._configfile
,
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"
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"
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"
80 assert dtest
.lists_have_same_contents(c
.tags(),
81 [u
"another tag", u
"wibble"]),\
82 "checking tag list(3)"
84 if __name__
== '__main__':