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