Esempio n. 1
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"
Esempio n. 2
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"
Esempio n. 3
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()
Esempio n. 4
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
Esempio n. 5
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)"
Esempio n. 6
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)
Esempio n. 7
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"