| 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 | # |
| 21 | import dtest,time,disorder,re |
| 22 | |
| 23 | def test(): |
| 24 | """Exercise database dumper""" |
| 25 | dtest.start_daemon() |
| 26 | dtest.create_user() |
| 27 | c = disorder.client() |
| 28 | track = "%s/Joe Bloggs/First Album/02:Second track.ogg" % dtest.tracks |
| 29 | dump = "%s/dumpfile" % dtest.testroot |
| 30 | print " setting a track pref" |
| 31 | c.set(track, "foo", "before") |
| 32 | assert c.get(track, "foo") == "before", "checking track foo=before" |
| 33 | print " setting a global pref" |
| 34 | c.setglobal("foo", "before"); |
| 35 | assert c.getglobal("foo") == "before", "checking global foo=before" |
| 36 | print " adding a tag" |
| 37 | # Exercise the tags-changed code |
| 38 | c.set(track, "tags", " first tag, Another Tag") |
| 39 | assert dtest.lists_have_same_contents(c.tags(), |
| 40 | [u"another tag", u"first tag"]),\ |
| 41 | "checking tag list(1)" |
| 42 | c.set(track, "tags", "wibble, another tag ") |
| 43 | assert dtest.lists_have_same_contents(c.tags(), |
| 44 | [u"another tag", u"wibble"]),\ |
| 45 | "checking tag list(2)" |
| 46 | print " checking track appears in tag search" |
| 47 | tracks = c.search(["tag:wibble"]) |
| 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)" |
| 53 | print " dumping database" |
| 54 | print dtest.command(["disorder-dump", "--config", disorder._configfile, |
| 55 | "--dump", dump]) |
| 56 | print " changing track pref" |
| 57 | c.set(track, "foo", "after dump"); |
| 58 | assert c.get(track, "foo") == "after dump", "checking track foo=after dump" |
| 59 | print " changing global pref" |
| 60 | c.setglobal("foo", "after dump"); |
| 61 | assert c.getglobal("foo") == "after dump", "checking global foo=after dump" |
| 62 | print " adding fresh track pref" |
| 63 | c.set(track, "bar", "after dump") |
| 64 | print " adding fresh global pref" |
| 65 | c.setglobal("bar", "after dump") |
| 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() |
| 72 | print " checking track pref" |
| 73 | assert c.get(track, "foo") == "before", "checking track foo=before after undump" |
| 74 | print " checking global pref" |
| 75 | assert c.getglobal("foo") == "before", "checking global foo=before after undump" |
| 76 | print " checking fresh track pref" |
| 77 | assert c.get(track, "bar") is None, "checking fresh track pref has gone" |
| 78 | print " checking fresh global pref" |
| 79 | assert c.getglobal("bar") is None, "checking fresh global pref has gone" |
| 80 | print " checking tag search still works" |
| 81 | tracks = c.search(["tag:wibble"]) |
| 82 | assert len(tracks) == 1, "checking there is exactly one search result" |
| 83 | assert tracks[0] == track, "checking for right search result(3)" |
| 84 | assert dtest.lists_have_same_contents(c.tags(), |
| 85 | [u"another tag", u"wibble"]),\ |
| 86 | "checking tag list(3)" |
| 87 | |
| 88 | if __name__ == '__main__': |
| 89 | dtest.run() |