chiark / gitweb /
Disobedience memory/widget debugging stuff has thoroughly rotted, so
[disorder] / tests / dump.py
... / ...
CommitLineData
1#! /usr/bin/env python
2#
3# This file is part of DisOrder.
4# Copyright (C) 2007, 2008 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#
21import dtest,time,disorder,re
22
23def test():
24 """Exercise database dumper"""
25 dtest.start_daemon()
26 dtest.create_user()
27 dtest.rescan()
28 c = disorder.client()
29 track = "%s/Joe Bloggs/First Album/02:Second track.ogg" % dtest.tracks
30 dump = "%s/dumpfile" % dtest.testroot
31 print " setting a track pref"
32 c.set(track, "foo", "before")
33 assert c.get(track, "foo") == "before", "checking track foo=before"
34 print " setting a global pref"
35 c.setglobal("foo", "before");
36 assert c.getglobal("foo") == "before", "checking global foo=before"
37 print " adding a tag"
38 # Exercise the tags-changed code
39 c.set(track, "tags", " first tag, Another Tag")
40 assert dtest.lists_have_same_contents(c.tags(),
41 [u"another tag", u"first tag"]),\
42 "checking tag list(1)"
43 c.set(track, "tags", "wibble, another tag ")
44 assert dtest.lists_have_same_contents(c.tags(),
45 [u"another tag", u"wibble"]),\
46 "checking tag list(2)"
47 print " checking track appears in tag search"
48 tracks = c.search(["tag:wibble"])
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)"
54 print " dumping database"
55 print dtest.command(["disorder-dump", "--config", disorder._configfile,
56 "--dump", dump])
57 print " changing track pref"
58 c.set(track, "foo", "after dump");
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")
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()
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)"
88
89if __name__ == '__main__':
90 dtest.run()