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