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