示例#1
0
def test():
    """Exercise cookie protocol"""
    dtest.start_daemon()
    dtest.create_user()
    print " connecting"
    c = disorder.client()
    v = c.version()
    print " getting cookie"
    k = c.make_cookie()
    print " cookie value is %s" % k
    print " connecting with cookie"
    c = disorder.client()
    c.connect(k)
    v = c.version()
    print " it worked"
    print " connecting with cookie again"
    c = disorder.client()
    c.connect(k)
    v = c.version()
    print " it worked"
    print " revoking cookie"
    c.revoke()
    v = c.version()
    print " connection still works"
    print " connecting with revoked cookie"
    c = disorder.client()
    try:
      c.connect(k)
      print "*** should not be able to connect with revoked cookie ***"
      assert False
    except disorder.operationError:
      pass                              # good
    print " revoked cookie was rejected"
示例#2
0
def test():
    """Check that the file listing comes out right"""
    dtest.start_daemon()
    dtest.create_user()
    dtest.rescan()
    assert dtest.check_files() == 0, "dtest.check_files"
    print " checking regexp file listing"
    c = disorder.client()
    f = c.files("%s/Joe Bloggs/First Album" % dtest.tracks, "second")
    assert len(f) == 1, "checking for one match"
    assert f[
        0] == "%s/Joe Bloggs/First Album/02:Second track.ogg" % dtest.tracks
    print " and again to exercise cache"
    f = c.files("%s/Joe Bloggs/First Album" % dtest.tracks, "second")
    assert len(f) == 1, "checking for one match"
    assert f[
        0] == "%s/Joe Bloggs/First Album/02:Second track.ogg" % dtest.tracks
    print " checking unicode regexp file listing"
    f = c.files("%s/Joe Bloggs/First Album" % dtest.tracks, "first")
    assert len(f) == 0, "checking for 0 matches"
    print " and again to exercise cache"
    f = c.files("%s/Joe Bloggs/First Album" % dtest.tracks, "first")
    assert len(f) == 0, "checking for 0 matches"
    # This is rather unsatisfactory but it is the current behavior.  We could
    # for instance go to NFD for regexp matching but we'd have to do the same
    # to the regexp, including replacing single characters with (possibly
    # bracketed) decomposed forms.  Really the answer has to be a more
    # Unicode-aware regexp library.
    f = c.files("%s/Joe Bloggs/First Album" % dtest.tracks, "fi\\p{Mn}*rst")
    assert len(f) == 0, "checking for 0 matches"
示例#3
0
def test():
    """Exercise alias logic"""
    dtest.start_daemon()
    dtest.create_user()
    dtest.rescan()
    c = disorder.client()

    print " creating an alias in new directory"
    track = "%s/misc/blahblahblah.ogg" % dtest.tracks
    c.set(track,
          "trackname_display_artist",
          "Fred Smith")
    c.set(track,
          "trackname_display_album",
          "wibble")

    print " checking it shows up in the right place"
    alias = "%s/Fred Smith/wibble/blahblahblah.ogg" % dtest.tracks
    files = c.files("%s/Fred Smith/wibble" % dtest.tracks)
    assert files == [alias]

    print " checking part calculation"
    artist = c.part(track, "display", "artist")
    assert artist == "Fred Smith", "checking artist part"
    album = c.part(track, "display", "album")
    assert album == "wibble", "checking album part"
    title = c.part(track, "display", "title")
    assert title == "blahblahblah", "checking title part"

    print " checking part calculation on alias"
    artist = c.part(alias, "display", "artist")
    assert artist == "Fred Smith", "checking artist part"
    album = c.part(alias, "display", "album")
    assert album == "wibble", "checking album part"
    title = c.part(alias, "display", "title")
    assert title == "blahblahblah", "checking title part"

    # See defect #20
    print " checking that prefs always belong to the canonical name"
    c.set(alias, "wibble", "spong")
    value = c.get(track, "wibble")
    assert value == "spong", "checking pref ended up on resolved track"
    c.set(track, "foo", "bar")
    value = c.get(alias, "foo")
    assert value == "bar", "checking pref visible via alias"
示例#4
0
def test():
    """Test encoding conversion"""
    if sys.platform == "darwin":
        print "Sorry, cannot run this test on Darwin"
        # ...because local fs is always UTF-8
        sys.exit(77)
    dtest.start_daemon()
    dtest.create_user()
    dtest.rescan()
    dtest.check_files()
    dtest.stop_daemon()
    print " recoding as ISO-8859-1"
    recoded = recode(dtest.tracks, "UTF-8", "ISO-8859-1")
    print " ...recoded %d filenames" % recoded
    print " regenerating config"
    dtest.default_config(encoding="ISO-8859-1")
    print " checking recoded files"
    dtest.start_daemon()
    dtest.rescan()
    dtest.check_files()
    dtest.stop_daemon()
    print " recoding as UTF-8"
    recoded = recode(dtest.tracks, "ISO-8859-1", "UTF-8")
    print " ...recoded %d filenames" % recoded
    print " regenerating config"
    dtest.default_config(encoding="UTF-8")
    print " checking recoded files"
    dtest.start_daemon()
    dtest.rescan()
    dtest.check_files()
示例#5
0
def test():
    """Authentication hash tests"""
    created = False
    for h in [
            'sha1', 'SHA1', 'sha256', 'SHA256', 'sha384', 'SHA384', 'sha512',
            "SHA512"
    ]:
        print " setting authorization hash to %s" % h
        set_auth_algo(h)
        dtest.start_daemon()
        if not created:
            dtest.create_user()
            created = True
        print " exercising C implementation"
        dtest.command([
            "disorder", "--config", disorder._configfile,
            "--no-per-user-config", "--user", "root", "version"
        ])
        print " exercising Python implementation"
        c = disorder.client()
        c.version()
        dtest.stop_daemon()
示例#6
0
def test():
    """Play some tracks"""
    dtest.start_daemon()
    dtest.create_user()
    dtest.rescan()  # ensure all files are scanned
    c = disorder.client()
    c.random_disable()
    assert c.random_enabled() == False
    track = u"%s/Joe Bloggs/First Album/02:Second track.ogg" % dtest.tracks
    track2 = u"%s/Joe Bloggs/First Album/04:Fourth track.ogg" % dtest.tracks
    track3 = u"%s/Joe Bloggs/First Album/05:Fifth track.ogg" % dtest.tracks
    print " adding track to queue"
    c.disable()
    assert c.enabled() == False
    c.play(track)
    print " checking track turned up in queue"
    q = c.queue()
    ts = filter(lambda t: t['track'] == track and 'submitter' in t, q)
    assert len(ts) == 1, "checking track appears exactly once in queue"
    t = ts[0]
    assert t['submitter'] == u'fred', "check queue submitter"
    i = t['id']
    print " waiting for track"
    c.enable()
    assert c.enabled() == True
    p = c.playing()
    r = c.recent()
    limit = 60
    while not (
        (p is not None and p['id'] == i) or
        (len(filter(lambda t: t['track'] == track and 'submitter' in t, r)) >
         0)) and limit > 0:
        time.sleep(1)
        p = c.playing()
        r = c.recent()
        limit -= 1
    assert limit > 0, "check track did complete in a reasonable time"
    print " checking track turned up in recent list"
    while (p is not None and p['id'] == i):
        time.sleep(1)
        p = c.playing()
    r = c.recent()
    ts = filter(lambda t: t['track'] == track and 'submitter' in t, r)
    assert len(ts) == 1, "check track appears exactly once in recent"
    t = ts[0]
    assert t['submitter'] == u'fred', "check recent entry submitter"

    print " ensuring queue is clear"
    c.disable()
    while c.playing() is not None:
        time.sleep(1)
    q = c.queue()
    for qe in q:
        c.remove(qe["id"])

    print " testing playafter"
    print "  adding to empty queue"
    c.playafter(None, [track])
    q = c.queue()
    print '\n'.join(
        map(lambda n: "%d: %s" % (n, q[n]["track"]), range(0, len(q))))
    assert len(q) == 1
    assert q[0]['track'] == track
    print "  insert at start of queue"
    c.playafter(None, [track2])
    q = c.queue()
    print '\n'.join(
        map(lambda n: "%d: %s" % (n, q[n]["track"]), range(0, len(q))))
    assert len(q) == 2
    assert q[0]['track'] == track2
    assert q[1]['track'] == track
    print "  insert in middle of queue"
    c.playafter(q[0]['id'], [track3])
    q = c.queue()
    print '\n'.join(
        map(lambda n: "%d: %s" % (n, q[n]["track"]), range(0, len(q))))
    assert len(q) == 3
    assert q[0]['track'] == track2
    assert q[1]['track'] == track3
    assert q[2]['track'] == track
    print "  insert multiple tracks at end of queue"
    c.playafter(q[2]['id'], [track2, track])
    q = c.queue()
    print '\n'.join(
        map(lambda n: "%d: %s" % (n, q[n]["track"]), range(0, len(q))))
    assert len(q) == 5
    assert q[0]['track'] == track2
    assert q[1]['track'] == track3
    assert q[2]['track'] == track
    assert q[3]['track'] == track2
    assert q[4]['track'] == track

    print " clearing queue"
    for qe in q:
        c.remove(qe["id"])

    print " testing scratches"
    retry = False
    scratchlimit = 5
    while scratchlimit > 0:
        scratchlimit -= 1
        c.disable()
        print " starting a track"
        c.play(track)
        c.enable()
        p = c.playing()
        if p is None:
            print " track played too quickly, trying again..."
            continue
        print " scratching track"
        i = p['id']
        c.scratch(i)
        print " waiting for track to finish"
        p = c.playing()
        limit = 60
        while (p is not None and p['id'] == i) and limit > 0:
            time.sleep(1)
            p = c.playing()
            limit -= 1
        assert limit > 0, "check track finishes in a reasonable period"
        print " checking scratched track turned up in recent list"
        r = c.recent()
        ts = filter(lambda t: t['id'] == i, r)
        assert len(
            ts) == 1, "check scratched track appears exactly once in recent"
        if ts[0]['state'] == 'ok':
            print " track played too quickly, trying again..."
            continue
        assert ts[0]['state'] == 'scratched', "checking track scratched"
        break
    if scratchlimit == 0:
        # TODO this is really not a great approach!
        print " didn't complete in a reasonable time"
        sys.exit(77)
    print " waiting for scratch to complete"
    p = c.recent()
    while p is not None:
        time.sleep(1)
        p = c.playing()
    assert p is None, "checking nothing is playing"
    assert c.enabled() == True
    c.random_enable()
    assert c.random_enabled() == True
示例#7
0
def test():
    """Exercise database dumper"""
    dtest.start_daemon()
    dtest.create_user()
    dtest.rescan()
    c = disorder.client()
    track = "%s/Joe Bloggs/First Album/02:Second track.ogg" % dtest.tracks
    dump = "%s/dumpfile" % dtest.testroot
    print " setting a track pref"
    c.set(track, "foo", "before")
    assert c.get(track, "foo") == "before", "checking track foo=before"
    print " setting a global pref"
    c.setglobal("foo", "before")
    assert c.getglobal("foo") == "before", "checking global foo=before"
    print " adding a tag"
    # Exercise the tags-changed code
    c.set(track, "tags", "  first   tag, Another Tag")
    assert dtest.lists_have_same_contents(c.tags(),
                                          [u"another tag", u"first tag"]),\
           "checking tag list(1)"
    c.set(track, "tags", "wibble,   another tag   ")
    assert dtest.lists_have_same_contents(c.tags(),
                                          [u"another tag", u"wibble"]),\
           "checking tag list(2)"
    print " checking track appears in tag search"
    tracks = c.search(["tag:wibble"])
    assert len(tracks) == 1, "checking there is exactly one search result(1)"
    assert tracks[0] == track, "checking for right search result(1)"
    tracks = c.search(["tag:  another    tAg  "])
    assert len(tracks) == 1, "checking there is exactly one search result(2)"
    assert tracks[0] == track, "checking for right search result(2)"
    print " dumping database"
    print dtest.command(
        ["disorder-dump", "--config", disorder._configfile, "--dump", dump])
    print " changing track pref"
    c.set(track, "foo", "after dump")
    assert c.get(track, "foo") == "after dump", "checking track foo=after dump"
    print " changing global pref"
    c.setglobal("foo", "after dump")
    assert c.getglobal("foo") == "after dump", "checking global foo=after dump"
    print " adding fresh track pref"
    c.set(track, "bar", "after dump")
    print " adding fresh global pref"
    c.setglobal("bar", "after dump")
    dtest.stop_daemon()
    print "restoring database"
    print dtest.command(
        ["disorder-dump", "--config", disorder._configfile, "--undump", dump])
    dtest.start_daemon()
    c = disorder.client()
    print " checking track pref"
    assert c.get(track,
                 "foo") == "before", "checking track foo=before after undump"
    print " checking global pref"
    assert c.getglobal(
        "foo") == "before", "checking global foo=before after undump"
    print " checking fresh track pref"
    assert c.get(track, "bar") is None, "checking fresh track pref has gone"
    print " checking fresh global pref"
    assert c.getglobal("bar") is None, "checking fresh global pref has gone"
    print " checking tag search still works"
    tracks = c.search(["tag:wibble"])
    assert len(tracks) == 1, "checking there is exactly one search result"
    assert tracks[0] == track, "checking for right search result(3)"
    assert dtest.lists_have_same_contents(c.tags(),
                                          [u"another tag", u"wibble"]),\
           "checking tag list(3)"
示例#8
0
def test():
    """Check the queue is padded to the (default) configured length"""
    dtest.start_daemon()
    dtest.create_user()
    c = disorder.client()
    print " disabling play"
    c.disable()
    print " waiting for queue to be populated..."
    q = c.queue()
    while len(q) < 5:
        print "  queue at %d tracks" % len(q)
        wait_monitor().run()
        q = c.queue()
    print " getting queue via disorder(1)"
    q = dtest.command([
        "disorder", "--config", disorder._configfile, "--no-per-user-config",
        "queue"
    ])
    tracks = filter(lambda s: re.match("^track", s), q)
    assert len(tracks) == 5, "queue is at proper length"
    print " disabling random play"
    c.random_disable()
    print " emptying queue"
    for t in c.queue():
        c.remove(t['id'])
    print " checking queue is now empty"
    q = c.queue()
    assert q == [], "checking queue is empty"
    print " enabling random play"
    c.random_enable()
    print " waiting for queue to refill..."
    q = c.queue()
    while len(q) < 5:
        print "  queue at %d tracks" % len(q)
        wait_monitor().run()
        q = c.queue()
    print " disabling all play"
    c.random_disable()
    c.disable()
    print " emptying queue"
    for t in c.queue():
        c.remove(t['id'])
    t1 = "%s/Joe Bloggs/Third Album/01:First_track.ogg" % dtest.tracks
    t2 = "%s/Joe Bloggs/Third Album/02:Second_track.ogg" % dtest.tracks
    t3 = "%s/Joe Bloggs/Third Album/02:Second_track.ogg" % dtest.tracks
    print " adding tracks"
    i1 = c.play(t1)
    i2 = c.play(t2)
    i3 = c.play(t3)
    q = c.queue()
    assert map(lambda e: e['id'], q) == [i1, i2, i3], "checking queue order(1)"
    print " moving last track to start"
    c.moveafter(None, [i3])
    q = c.queue()
    assert map(lambda e: e['id'], q) == [i3, i1, i2], "checking queue order(2)"
    print " moving two tracks"
    c.moveafter(i1, [i2, i3])
    q = c.queue()
    assert map(lambda e: e['id'], q) == [i1, i2, i3], "checking queue order(3)"
    print " removing a track"
    c.remove(i2)
    q = c.queue()
    assert map(lambda e: e['id'], q) == [i1, i3], "checking queue order(4)"
示例#9
0
def test():
    """Check that the search produces the right results"""
    dtest.start_daemon()
    dtest.create_user()
    dtest.rescan()
    global client
    client = disorder.client()
    first = [
        "Joe Bloggs/First Album/01:F\xC3\x8Crst track.ogg",
        "Joe Bloggs/First Album/02:Second track.ogg",
        "Joe Bloggs/First Album/03:ThI\xCC\x81rd track.ogg",
        "Joe Bloggs/First Album/04:Fourth track.ogg",
        "Joe Bloggs/First Album/05:Fifth track.ogg",
        "Joe Bloggs/Second Album/01:First track.ogg",
        "Joe Bloggs/Third Album/01:First_track.ogg"
    ]
    second = [
        "Joe Bloggs/First Album/02:Second track.ogg",
        "Joe Bloggs/Second Album/01:First track.ogg",
        "Joe Bloggs/Second Album/02:Second track.ogg",
        "Joe Bloggs/Second Album/03:Third track.ogg",
        "Joe Bloggs/Second Album/04:Fourth track.ogg",
        "Joe Bloggs/Second Album/05:Fifth track.ogg",
        "Joe Bloggs/Third Album/02:Second_track.ogg"
    ]
    third = [
        "Joe Bloggs/First Album/03:ThI\xCC\x81rd track.ogg",
        "Joe Bloggs/Second Album/03:Third track.ogg",
        "Joe Bloggs/Third Album/01:First_track.ogg",
        "Joe Bloggs/Third Album/02:Second_track.ogg",
        "Joe Bloggs/Third Album/03:Third_track.ogg",
        "Joe Bloggs/Third Album/04:Fourth_track.ogg",
        "Joe Bloggs/Third Album/05:Fifth_track.ogg"
    ]
    first_and_second = filter(lambda s: s in second, first)
    # ASCII matches
    check_search_results(["first"], first)
    check_search_results(["Second"], second)
    check_search_results(["THIRD"], third)
    # ASCII Conjunctions
    check_search_results(["FIRST", "SECOND"], first_and_second)
    # Non-ASCII Characters
    # 00CC is LATIN CAPITAL LETTER I WITH GRAVE
    # 00EC is LATIN SMALL LETTER I WITH GRAVE
    check_search_results([u"F\u00CCRST"], first)
    check_search_results([u"f\u00ECrst"], first)
    # 00CD is LATIN CAPITAL LETTER I WITH ACUTE
    # 00ED is LATIN SMALL LETTER I WITH ACUTE
    check_search_results([u"TH\u00CDRD"], third)
    check_search_results([u"th\u00EDrd"], third)
    # ...and again in denormalized form
    # 0300 is COMBINING GRAVE ACCENT
    # 0301 is COMBINING ACUTE ACCENT
    check_search_results([u"FI\u0300RST"], first)
    check_search_results([u"fi\u0300rst"], first)
    check_search_results([u"THI\u0301RD"], third)
    check_search_results([u"thI\u0301rd"], third)
    # stopwords shouldn't show up
    check_search_results(["01"], [])

    if failures > 0:
        sys.exit(1)
示例#10
0
def test():
    """Test user database"""
    dtest.start_daemon()
    dtest.create_user()
    print " checking user creation"
    c = disorder.client()
    c.adduser("bob", "bobpass")
    users = c.users()
    assert dtest.lists_have_same_contents(users, ["fred", "bob", "root"])
    rights = c.userinfo("bob", "rights")
    print " new user rights are: %s" % rights
    print " checking new user can log in"
    c = disorder.client(user="******", password="******")
    c.version()
    print " checking bob can set their email address"
    c.edituser("bob", "email", "foo@bar")
    email = c.userinfo("bob", "email")
    assert email == "foo@bar", "checking bob's email address"
    print " checking user deletion"
    c = disorder.client()
    c.deluser("bob")
    print " checking new user can no longer log in"
    c = disorder.client(user="******", password="******")
    try:
        c.version()
        print "*** should not be able to log in after deletion ***"
        assert False
    except disorder.operationError:
        pass  # good
    print " deleted user could no longer log in."
    c = disorder.client()
    users = c.users()
    assert dtest.lists_have_same_contents(users, ["fred", "root"])
    print " creating the guest user"
    dtest.command([
        "disorder", "--config", disorder._configfile, "--no-per-user-config",
        "--user", "root", "setup-guest"
    ])
    print " logging in as guest user"
    gc = disorder.client(user="******", password="")
    gc.version()
    print " testing user registration"
    cs = gc.register("joe", "joepass", "*****@*****.**")
    print " confirmation string is %s" % cs
    print " checking unconfirmed user cannot log in"
    jc = disorder.client(user="******", password="******")
    try:
        jc.version()
        print "*** should not be able to log in before confirmation ***"
        assert False
    except disorder.operationError:
        pass  # good
    print " confirming user"
    gc = disorder.client(user="******", password="")
    gc.confirm(cs)
    print " checking confirmed user can log in"
    jc = disorder.client(user="******", password="******")
    jc.version()
    print " checking new user's email address"
    assert c.userinfo("joe", "email") == "*****@*****.**"
    print " checking can change user email address"
    c.edituser("joe", "email", "*****@*****.**")
    assert c.userinfo("joe", "email") == "*****@*****.**"
    print " checking bad email address rejected"
    try:
        c.edituser("joe", "email", "invalid")
        print "*** should not be able to set invalid email address ***"
        assert False
    except disorder.operationError:
        pass  # good
    assert c.userinfo("joe", "email") == "*****@*****.**"
    print " checking removal of email address"
    c.edituser("joe", "email", "")
    assert c.userinfo("joe", "email") == None
示例#11
0
def test():
    """Playlist testing"""
    dtest.start_daemon()
    dtest.create_user()
    c = disorder.client()
    c.random_disable()
    #
    print " checking initial playlist set is empty"
    l = c.playlists()
    assert l == [], "checking initial playlist set is empty"
    #
    print " creating a shared playlist"
    c.playlist_lock("wibble")
    c.playlist_set("wibble", ["one", "two", "three"])
    c.playlist_unlock()
    print " checking new playlist appears in list"
    l = c.playlists()
    assert l == ["wibble"], "checking new playlists"
    print " checking new playlist contents is as assigned"
    l = c.playlist_get("wibble")
    assert l == ["one", "two", "three"], "checking playlist contents"
    #
    print " checking new playlist is shared"
    s = c.playlist_get_share("wibble")
    assert s == "shared", "checking playlist is shared"
    #
    print " checking cannot unshare un-owned playlist"
    try:
        c.playlist_set_share("wibble", "private")
        print "*** should not be able to adjust shared playlist's sharing ***"
        assert False
    except disorder.operationError:
        pass                            # good
    #
    print " modifying shared playlist"
    c.playlist_lock("wibble")
    c.playlist_set("wibble", ["three", "two", "one"])
    c.playlist_unlock()
    print " checking updated playlist contents is as assigned"
    l = c.playlist_get("wibble")
    assert l == ["three", "two", "one"], "checking modified playlist contents"
    #
    print " creating a private playlist"
    c.playlist_lock("fred.spong")
    c.playlist_set("fred.spong", ["a", "b", "c"])
    c.playlist_unlock()
    s = c.playlist_get_share("fred.spong")
    assert s == "private", "owned playlists are private by default"
    #
    print " creating a public playlist"
    c.playlist_lock("fred.foo")
    c.playlist_set("fred.foo", ["p", "q", "r"])
    c.playlist_set_share("fred.foo", "public")
    c.playlist_unlock()
    s = c.playlist_get_share("fred.foo")
    assert s == "public", "new playlist is now public"
    #
    print " checking fred can see all playlists"
    l = c.playlists()
    assert dtest.lists_have_same_contents(l,
                                          ["fred.spong", "fred.foo", "wibble"]), "playlist list is as expected"
    #
    print " adding a second user"
    c.adduser("bob", "bobpass")
    d = disorder.client(user="******", password="******")
    print " checking bob cannot see fred's private playlist"
    l = d.playlists()
    assert dtest.lists_have_same_contents(l,
                                          ["fred.foo", "wibble"]), "playlist list is as expected"
    #
    print " checking bob can read shared and public playlists"
    d.playlist_get("wibble")
    d.playlist_get("fred.foo")
    print " checking bob cannot read private playlist"
    try:
        d.playlist_get("fred.spong")
        print "*** should not be able to read private playlist ***"
        assert False
    except disorder.operationError:
        pass                            # good
    #
    print " checking bob cannot modify fred's playlists"
    try:
        d.playlist_lock("fred.foo")
        print "*** should not be able to lock fred's public playlist ***"
        assert False
    except disorder.operationError:
        pass                            # good
    try:
        d.playlist_lock("fred.spong")
        print "*** should not be able to lock fred's private playlist ***"
        assert False
    except disorder.operationError:
        pass                            # good
    print " checking unlocked playlists cannot be modified"
    #
    try:
        c.playlist_set("wibble", ["a"])
        print "*** should not be able to modify unlocked playlists ***"
        assert False
    except disorder.operationError:
        pass                            # good
    #
    print " deleting playlists"
    c.playlist_delete("fred.spong")
    l = c.playlists()
    assert dtest.lists_have_same_contents(l,
                                          ["fred.foo", "wibble"])
    try:
        d.playlist_delete("fred.foo")
        print "*** should not be to delete fred's playlist ***"
        assert False
    except disorder.operationError:
        pass                            # good
    d.playlist_delete("wibble")
    l = c.playlists()
    assert l == ["fred.foo"]
    c.playlist_delete("fred.foo")
    l = c.playlists()
    assert l == []
    try:
        c.playlist_delete("nonesuch")
        print "*** should not be to delete nonexistent playlist ***"
        assert False
    except disorder.operationError:
        pass                            # good
示例#12
0
def test():
    """Create a daemon and fail"""
    dtest.start_daemon()
    dtest.create_user()
    assert True == False, "forcing failure"
示例#13
0
def test():
    """Exercise schedule support"""
    dtest.start_daemon()
    dtest.create_user()
    c = disorder.client()
    c.random_disable()
    dtest.rescan()
    # Wait until there's no track playing
    print " waiting for nothing to be playing"
    while c.playing() is not None:
        time.sleep(1)
        print "  ."
    track = "%s/Joe Bloggs/First Album/05:Fifth track.ogg" % dtest.tracks
    print " scheduling a track for the future"
    when = now() + 3
    c.schedule_add(when, "normal", "play", track)
    print " disorder schedule-list output:"
    print string.join(dtest.command(["disorder",
                                     "--config", disorder._configfile,
                                     "--no-per-user-config",
                                     "schedule-list"]), ""),
    p = next_playing(c)
    assert p["track"] == track, "checking right track played"
    print " when=%d expected at least %d" % (int(p["when"]), when)
    assert int(p["when"]) >= when, "checking track played at right time"
    assert c.schedule_list() == [], "checking schedule is empty"
    wait_idle(c)
    print " scheduling an enable-random for the future"
    c.schedule_add(now() + 3, "junk", "set-global", "random-play", "yes")
    print " disorder schedule-list output:"
    print string.join(dtest.command(["disorder",
                                     "--config", disorder._configfile,
                                     "--no-per-user-config",
                                     "schedule-list"]), ""),
    next_playing(c)
    print " disabling random play"
    c.random_disable()
    wait_idle(c)
    print " scheduling track to play later via command line"
    when = now() + 3
    dtest.command(["disorder",
                   "--config", disorder._configfile,
                   "--no-per-user-config",
                   "schedule-play",
                   time.strftime("%Y-%m-%d %H:%M:%S",
                                 time.localtime(when)),
                   "normal",
                   track])
    print " disorder schedule-list output:"
    print string.join(dtest.command(["disorder",
                                     "--config", disorder._configfile,
                                     "--no-per-user-config",
                                     "schedule-list"]), ""),
    p = next_playing(c)
    assert p["track"] == track, "checking right track played"
    assert p["when"] >= when, "checking track played at right time"
    assert c.schedule_list() == [], "checking schedule is empty"
    wait_idle(c)
    print " scheduling an enable-random for later via command line"
    dtest.command(["disorder",
                   "--config", disorder._configfile,
                   "--no-per-user-config",
                   "schedule-set-global",
                   time.strftime("%Y-%m-%d %H:%M:%S",
                                 time.localtime(now() + 3)),
                   "normal",
                   "random-play",
                   "yes"])
    print " disorder schedule-list output:"
    print string.join(dtest.command(["disorder",
                                     "--config", disorder._configfile,
                                     "--no-per-user-config",
                                     "schedule-list"]), ""),
    p = next_playing(c)
    print " disabling random play"
    c.random_disable()
    print " waiting for nothing to be playing"
    while c.playing() is not None:
        time.sleep(1)
        print "  ."
    print " scheduling a track for the future"
    c.schedule_add(now() + 3, "normal", "play", track)
    print " schedule via python:"
    s = c.schedule_list()
    for event in s:
        e = c.schedule_get(event)
        print "item %s: %s" % (event, e)
    print " deleting item %s" % s[0]
    c.schedule_del(s[0])
    print " checking it's really gone"
    s = c.schedule_list()
    assert s == [], "checking schedule is empty"
    waited = 0
    p = c.playing()
    while p is None and waited < 5:
        time.sleep(1)
        print "  ."
        waited += 1
        p = c.playing()
    assert p is None, "checking deleted scheduled event did not run"
    print " checking you can't schedule events for the past"
    try:
        c.schedule_add(now() - 4, "normal", "play", track)
        assert False, "checking schedule_add failed"
    except disorder.operationError:
      pass                              # good
    print " checking scheduled events survive restarts"
    when = now() + 3
    c.schedule_add(when, "normal", "play", track)
    dtest.stop_daemon()
    print " dumping database"
    dump = "%s/dumpfile" % dtest.testroot
    print dtest.command(["disorder-dump", "--config", disorder._configfile,
                         "--dump", dump])
    print "restoring database"
    print dtest.command(["disorder-dump", "--config", disorder._configfile,
                         "--undump", dump])
    dtest.start_daemon()
    c = disorder.client()
    p = next_playing(c)
    print " waiting for track to play"
    assert p["track"] == track, "checking right track played"
    assert p["when"] >= when, "checking track played at right time"
    assert c.schedule_list() == [], "checking schedule is empty"
    print " checking junk events do not survive restarts"
    c.schedule_add(now() + 2, "junk", "play", track)
    s = c.schedule_list()
    print s
    dtest.stop_daemon()
    time.sleep(3)
    dtest.start_daemon()
    c = disorder.client()
    print " checking schedule is empty"
    s = c.schedule_list()
    print s
    assert s == [], "checking schedule is empty"