From db3b729360cfa0cae98af0fe447c411ddd90f7bd Mon Sep 17 00:00:00 2001 From: Hellowlol Date: Mon, 27 Feb 2017 23:16:02 +0100 Subject: [PATCH] one step closer with the test. --- plexapi/base.py | 9 +++++---- plexapi/library.py | 15 ++++++++++++--- tests/test_library.py | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/plexapi/base.py b/plexapi/base.py index 23df80bf..8fd2c452 100644 --- a/plexapi/base.py +++ b/plexapi/base.py @@ -177,12 +177,13 @@ class PlexObject(object): results.append(elem.attrib.get(attr)) return results - def reload(self): + def reload(self, key=None): """ Reload the data for this object from self.key. """ - if not self.key: + key = key or self.key + if not key: raise Unsupported('Cannot reload an object not built from a URL.') - self._initpath = self.key - data = self._server.query(self.key) + self._initpath = key + data = self._server.query(key) self._loadData(data[0]) return self diff --git a/plexapi/library.py b/plexapi/library.py index 862b363f..9e7bc5fc 100644 --- a/plexapi/library.py +++ b/plexapi/library.py @@ -144,7 +144,7 @@ class Library(PlexObject): for section in self.sections(): section.deleteMediaPreviews() - def add(self, name='', media_type='', agent='', scanner='', location='', language='en', *args, **kwargs): + def add(self, name='', type='', agent='', scanner='', location='', language='en', *args, **kwargs): """ Simplified add for the most common options. name (str): Name of the library @@ -227,9 +227,13 @@ class LibrarySection(PlexObject): def edit(self, **kwargs): """Edit a library - See addLibrary for example usage. + See :class:`~plexapi.library.Library for example usage. + Note: agent is required. + kwargs (dict): Dict of settings to edit. Some values might need to be quoted. + Value of scanner, name and location is quoted automatically. + """ # We might need to quote more, but lets start with what we know. kw = {} @@ -239,7 +243,12 @@ class LibrarySection(PlexObject): kw[k] = v part = '/library/sections/%s?%s' % (self.key, urlencode(kw)) - return self._server.query(part, method=self._server._session.put) + self._server.query(part, method=self._server._session.put) + # Reload this way since the self.key dont have a full path, but is simply a id. + for s in self._server.library.sections(): + if s.key == self.key: + return s + def get(self, title): """ Returns the media item with the specified title. diff --git a/tests/test_library.py b/tests/test_library.py index 99f2bdfa..9e7efbcf 100644 --- a/tests/test_library.py +++ b/tests/test_library.py @@ -76,6 +76,22 @@ def test_library_search(pms): m = pms.library.search('16 blocks')[0] assert m.title == '16 Blocks' +def test_library_add_edit_delete(pms): + d = dict(name='zomg strange11', type='movie', agent='com.plexapp.agents.imdb', + scanner='Plex Movie Scanner', language='en') + + rn = dict(name='a renamed lib', type='movie', agent='com.plexapp.agents.imdb') + + # We dont want to add a location because we dont want to start scanning. + pms.library.add(**d) + + assert pms.library.section('zomg strange11') + + edited_library = pms.library.section('zomg strange11').edit(**rn) + assert edited_library.title == 'a renamed lib' + + pms.library.section('a renamed lib').delete() + def test_library_Library_cleanBundle(pms): pms.library.cleanBundles()