chiark / gitweb /
more tag normalization work
[disorder] / tests / dump.py
CommitLineData
f35e5800
RK
1#! /usr/bin/env python
2#
3# This file is part of DisOrder.
4# Copyright (C) 2007 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 c = disorder.client()
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"
f47d40ba 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)"
f47d40ba
RK
45 print "checking track appears in tag search"
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)"
f35e5800
RK
52 print "dumping database"
53 print dtest.command(["disorder-dump", "--config", disorder._configfile,
54 "--dump", dump])
55 print "changing track pref"
56 c.set(track, "foo", "after");
57 assert c.get(track, "foo") == "after", "checking track foo=before"
58 print "changing global pref"
59 c.setglobal("foo", "after");
60 assert c.getglobal("foo") == "after", "checking global foo=before"
fb1bc1f5
RK
61 print "adding fresh track pref"
62 c.set(track, "bar", "after")
63 print "adding fresh global pref"
64 c.setglobal("bar", "after")
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()
71 print "checking track pref"
72 assert c.get(track, "foo") == "before", "checking track foo=before after undump"
73 print "checking global pref"
74 assert c.getglobal("foo") == "before", "checking global foo=before after undump"
fb1bc1f5
RK
75 print "checking fresh track pref"
76 assert c.get(track, "bar") is None, "checking fresh track pref has gone"
77 print "checking fresh global pref"
78 assert c.getglobal("bar") is None, "checking fresh global pref has gone"
f47d40ba
RK
79 print "checking tag search still works"
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()