From 440af55d72c65f5c149718dc52abd00f512ffb71 Mon Sep 17 00:00:00 2001 Message-Id: <440af55d72c65f5c149718dc52abd00f512ffb71.1713249975.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 3 Aug 2008 18:08:51 +0100 Subject: [PATCH] Initial playlist tests and consequent fixes. Organization: Straylight/Edgeware From: Richard Kettlewell --- lib/trackdb-playlists.c | 19 +++++++++++------- python/disorder.py.in | 7 ++++++- server/server.c | 5 +++++ tests/Makefile.am | 2 +- tests/playlists.py | 44 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 9 deletions(-) create mode 100755 tests/playlists.py diff --git a/lib/trackdb-playlists.c b/lib/trackdb-playlists.c index 77f7c13..fb01d20 100644 --- a/lib/trackdb-playlists.c +++ b/lib/trackdb-playlists.c @@ -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; } diff --git a/python/disorder.py.in b/python/disorder.py.in index 16685f5..56395c9 100644 --- a/python/disorder.py.in +++ b/python/disorder.py.in @@ -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 diff --git a/server/server.c b/server/server.c index 10225f3..64d29e0 100644 --- a/server/server.c +++ b/server/server.c @@ -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"); diff --git a/tests/Makefile.am b/tests/Makefile.am index e8e8507..1ee9af9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 0000000..600991a --- /dev/null +++ b/tests/playlists.py @@ -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() -- [mdw]