chiark / gitweb /
Initial playlist tests and consequent fixes.
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 3 Aug 2008 17:08:51 +0000 (18:08 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 3 Aug 2008 17:08:51 +0000 (18:08 +0100)
lib/trackdb-playlists.c
python/disorder.py.in
server/server.c
tests/Makefile.am
tests/playlists.py [new file with mode: 0755]

index 77f7c132dcbd14a1a951d28f0fae195ae4eaeadd..fb01d20ec01c2931aa7432c0000396476d764488 100644 (file)
@@ -100,7 +100,7 @@ static int playlist_may_read(const char *name,
                              const char *share) {
   char *owner;
   
-  if(!playlist_parse_name(name, &owner, 0))
+  if(playlist_parse_name(name, &owner, 0))
     return 0;
   /* Anyone can read shared playlists */
   if(!owner)
@@ -125,7 +125,7 @@ static int playlist_may_write(const char *name,
                               const char attribute((unused)) *share) {
   char *owner;
   
-  if(!playlist_parse_name(name, &owner, 0))
+  if(playlist_parse_name(name, &owner, 0))
     return 0;
   /* Anyone can modify shared playlists */
   if(!owner)
@@ -158,7 +158,7 @@ int trackdb_playlist_get(const char *name,
                          char **sharep) {
   int e;
 
-  if(!playlist_parse_name(name, 0, 0)) {
+  if(playlist_parse_name(name, 0, 0)) {
     error(0, "invalid playlist name '%s'", name);
     return EINVAL;
   }
@@ -257,7 +257,7 @@ int trackdb_playlist_set(const char *name,
   int e;
   char *owner;
   
-  if(!playlist_parse_name(name, &owner, 0)) {
+  if(playlist_parse_name(name, &owner, 0)) {
     error(0, "invalid playlist name '%s'", name);
     return EINVAL;
   }
@@ -324,7 +324,7 @@ static int trackdb_playlist_set_tid(const char *name,
     return 0;
   /* Set the new values */
   if(share)
-    kvp_set(&k, "share", share);
+    kvp_set(&k, "sharing", share);
   if(tracks) {
     char b[16];
     int oldcount, n;
@@ -386,13 +386,17 @@ static int trackdb_playlist_list_tid(const char *who,
   while(!(e = c->c_get(c, k, prepare_data(d), DB_NEXT))) {
     char *name = xstrndup(k->data, k->size), *owner;
     const char *share = kvp_get(kvp_urldecode(d->data, d->size),
-                                "share");
+                                "sharing");
 
     /* Extract owner; malformed names are skipped */
     if(playlist_parse_name(name, &owner, 0)) {
       error(0, "invalid playlist name '%s' found in database", name);
       continue;
     }
+    if(!share) {
+      error(0, "playlist '%s' has no 'sharing' key", name);
+      continue;
+    }
     /* Always list public and shared playlists
      * Only list private ones to their owner
      * Don't list anything else
@@ -403,6 +407,7 @@ static int trackdb_playlist_list_tid(const char *who,
            && owner && !strcmp(owner, who)))
       vector_append(v, name);
   }
+  trackdb_closecursor(c);
   switch(e) {
   case DB_NOTFOUND:
     break;
@@ -435,7 +440,7 @@ int trackdb_playlist_delete(const char *name,
   int e;
   char *owner;
   
-  if(!playlist_parse_name(name, &owner, 0)) {
+  if(playlist_parse_name(name, &owner, 0)) {
     error(0, "invalid playlist name '%s'", name);
     return EINVAL;
   }
index 16685f5f4b7fa137c23f5a3de70e29be2feb5e39..56395c99f11837645ebc349ba99e0f91a8242c1c 100644 (file)
@@ -937,7 +937,7 @@ class client:
     Arguments:
     playlist -- Playlist to set
     tracks -- Array of tracks"""
-    self._simple_body("playlist-set", tracks, playlist)
+    self._simple_body(tracks, "playlist-set", playlist)
 
   def playlist_set_share(self, playlist, share):
     """Set the sharing status of a playlist"""
@@ -950,6 +950,11 @@ class client:
       return None
     return _split(details)[0]
 
+  def playlists(self):
+    """Returns the list of visible playlists"""
+    self._simple("playlists")
+    return self._body()
+
   ########################################################################
   # I/O infrastructure
 
index 10225f37d849af1d9561a55a3133079ed8b31b6b..64d29e0ad1ca0449e1a45513baefd025600111aa 100644 (file)
@@ -1664,6 +1664,11 @@ static int c_playlist_set_body(struct conn *c,
   const char *playlist = u;
   int err;
 
+  if(!c->locked_playlist
+     || strcmp(playlist, c->locked_playlist)) {
+    sink_writes(ev_writer_sink(c->w), "550 Playlist is not locked\n");
+    return 1;
+  }
   if(!(err = trackdb_playlist_set(playlist, c->who,
                                   body, nbody, 0))) {
     sink_printf(ev_writer_sink(c->w), "250 OK\n");
index e8e8507dedbc04e1a4854ea76fc2ac1a01078938..1ee9af9a8dd044407c8d9de4e5d284af6725525f 100644 (file)
@@ -28,7 +28,7 @@ disorder_udplog_DEPENDENCIES=../lib/libdisorder.a
 
 TESTS=cookie.py dbversion.py dump.py files.py play.py queue.py \
        recode.py search.py user-upgrade.py user.py aliases.py  \
-       schedule.py
+       schedule.py playlists.py
 
 TESTS_ENVIRONMENT=${PYTHON} -u
 
diff --git a/tests/playlists.py b/tests/playlists.py
new file mode 100755 (executable)
index 0000000..600991a
--- /dev/null
@@ -0,0 +1,44 @@
+#! /usr/bin/env python
+#
+# This file is part of DisOrder.
+# Copyright (C) 2008 Richard Kettlewell
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+#
+import dtest,disorder
+
+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"
+
+if __name__ == '__main__':
+    dtest.run()