| 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 3 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, |
| 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 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | # |
| 19 | import dtest,time,disorder,re |
| 20 | |
| 21 | def test(): |
| 22 | """Exercise database dumper""" |
| 23 | dtest.start_daemon() |
| 24 | dtest.create_user() |
| 25 | dtest.rescan() |
| 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" |
| 35 | print " adding a tag" |
| 36 | # Exercise the tags-changed code |
| 37 | c.set(track, "tags", " first tag, Another Tag") |
| 38 | assert dtest.lists_have_same_contents(c.tags(), |
| 39 | [u"another tag", u"first tag"]),\ |
| 40 | "checking tag list(1)" |
| 41 | c.set(track, "tags", "wibble, another tag ") |
| 42 | assert dtest.lists_have_same_contents(c.tags(), |
| 43 | [u"another tag", u"wibble"]),\ |
| 44 | "checking tag list(2)" |
| 45 | print " checking track appears in tag search" |
| 46 | tracks = c.search(["tag:wibble"]) |
| 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)" |
| 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 dump"); |
| 57 | assert c.get(track, "foo") == "after dump", "checking track foo=after dump" |
| 58 | print " changing global pref" |
| 59 | c.setglobal("foo", "after dump"); |
| 60 | assert c.getglobal("foo") == "after dump", "checking global foo=after dump" |
| 61 | print " adding fresh track pref" |
| 62 | c.set(track, "bar", "after dump") |
| 63 | print " adding fresh global pref" |
| 64 | c.setglobal("bar", "after dump") |
| 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" |
| 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" |
| 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" |
| 82 | assert tracks[0] == track, "checking for right search result(3)" |
| 83 | assert dtest.lists_have_same_contents(c.tags(), |
| 84 | [u"another tag", u"wibble"]),\ |
| 85 | "checking tag list(3)" |
| 86 | |
| 87 | if __name__ == '__main__': |
| 88 | dtest.run() |