This commit is contained in:
Hellowlol 2017-01-29 22:22:48 +01:00
parent 19506e272d
commit a72dd6256a
6 changed files with 51 additions and 40 deletions

View file

@ -2,5 +2,8 @@
exclude_lines =
pragma: no cover
raise NotImplementedError
raise Unsupported
except ImportError
def __repr__
def __bool__
if __name__ == .__main__.:

View file

@ -23,3 +23,6 @@ class Unsupported(PlexApiException):
class Unauthorized(PlexApiException):
""" Invalid username or password. """
pass
class NotImplementedError(PlexApiException):
pass

View file

@ -6,6 +6,7 @@ from plexapi.compat import quote, urlencode, string_type
import requests
from plexapi.exceptions import NotFound, UnknownType, Unsupported
from plexapi.exceptions import NotFound, NotImplementedError, UnknownType, Unsupported
from threading import Thread
@ -101,7 +102,7 @@ class PlexPartialObject(object):
self.__dict__[attr] = value
def _loadData(self, data):
raise Exception('Abstract method not implemented.')
raise NotImplementedError('Abstract method not implemented.')
def isFullObject(self):
""" Retruns True if this is already a full object. A full object means all attributes
@ -405,8 +406,13 @@ def joinArgs(args):
return '?%s' % '&'.join(arglist)
<<<<<<< HEAD
def listChoices(server, path):
""" Returns a dict of {title:key} for all simple choices in a search filter.
=======
def listChoices(server, path): # pragma: no cover # Dont think its is used
"""ListChoices is by _cleanSort etc.
>>>>>>> more cov
Parameters:
server (:class:`~plexapi.server.PlexServer`): PlexServer object this is from.
@ -441,6 +447,7 @@ def listItems(server, path, libtype=None, watched=None, bytag=False):
return items
<<<<<<< HEAD
def rget(obj, attrstr, default=None, delim='.'):
""" Returns the value at the specified attrstr location within a nexted tree of
dicts, lists, tuples, functions, classes, etc. The lookup is done recursivley
@ -453,6 +460,9 @@ def rget(obj, attrstr, default=None, delim='.'):
default (any): Default value to return if not found.
delim (str): Delimiter separating keys in attrstr.
"""
=======
def rget(obj, attrstr, default=None, delim='.'): # pragma: no cover # Dont think its is used
>>>>>>> more cov
try:
parts = attrstr.split(delim, 1)
attr = parts[0]
@ -554,7 +564,7 @@ def download(url, filename=None, savepath=None, session=None, chunksize=4024, mo
try:
os.makedirs(savepath)
except OSError:
if not os.path.isdir(savepath):
if not os.path.isdir(savepath): # pragma: no cover
raise
filename = os.path.basename(filename)
@ -589,5 +599,5 @@ def download(url, filename=None, savepath=None, session=None, chunksize=4024, mo
return fullpath
except Exception as e:
except Exception as e: # pragma: no cover
log.exception('Failed to download %s to %s %s' % (url, fullpath, e))

View file

@ -538,35 +538,3 @@ class Episode(Video, Playable):
def _prettyfilename(self):
return '%s.S%sE%s' % (self.grandparentTitle.replace(' ', '.'), str(self.seasonNumber).zfill(2), str(self.index).zfill(2))
'''
def download(self, savepath=None, keep_orginal_name=False, **kwargs):
"""Download a episode. If kwargs are passed your can download a trancoded file.
Args:
savepath (str): Abs path to savefolder
keep_orginal_name (bool): Use the mediafiles orginal name
kwargs:
See getStreamURL docs.
"""
downloaded = []
locs = [i for i in self.iterParts() if i]
for loc in locs:
if keep_orginal_name is False:
name = '%s.%s' % (self._prettyfilename(), loc.container)
else:
name = loc.file
# So this seems to be a alot slower but allows transcode.
if kwargs:
download_url = self.getStreamURL(**kwargs)
else:
download_url = self.server.url('%s?download=1' % loc.key)
dl = utils.download(download_url, filename=name, savepath=savepath, session=self.server.session)
if dl:
downloaded.append(dl)
return downloaded
'''

View file

@ -17,6 +17,9 @@ def test_utils_searchType():
st = utils.searchType('movie')
assert st == 1
movie = utils.searchType(1)
assert movie == '1'
with pytest.raises(NotFound):
utils.searchType('kekekekeke')
@ -54,8 +57,13 @@ def _test_utils_findLocations():
def _test_utils_findItem():
pass
def _test_utils_findKey():
pass
def test_utils_findKey(pms):
with pytest.raises(NotFound):
assert utils.findKey(pms, '9999999')
assert utils.findKey(pms, '1')
def test_utils_cast():
t_int_int = utils.cast(int, 1)

View file

@ -5,6 +5,8 @@ import os
import pytest
from plexapi.exceptions import NotFound
def test_video_Movie(a_movie_section):
m = a_movie_section.get('Cars')
@ -265,6 +267,7 @@ def test_video_Show_attrs(a_show):
assert m.rating == 8.1
assert m.ratingKey == 12
assert [i.tag for i in m.roles][:3] == ['Richard Harmon', 'Alycia Debnam-Carey', 'Lindsey Morgan']
assert [i.tag for i in m.actors][:3] == ['Richard Harmon', 'Alycia Debnam-Carey', 'Lindsey Morgan']
assert m.server.baseurl == 'http://138.68.157.5:32400'
assert m.studio == 'The CW'
assert m.summary == u"When nuclear Armageddon destroys civilization on Earth, the only survivors are those on the 12 international space stations in orbit at the time. Three generations later, the 4,000 survivors living on a space ark of linked stations see their resources dwindle and face draconian measures established to ensure humanity's future. Desperately looking for a solution, the ark's leaders send 100 juvenile prisoners back to the planet to test its habitability. Having always lived in space, the exiles find the planet fascinating and terrifying, but with the fate of the human race in their hands, they must forge a path into the unknown."
@ -278,6 +281,14 @@ def test_video_Show_attrs(a_show):
assert m.viewedLeafCount == 1
assert m.year == 2014
def test_video_Show_watched(a_show):
watched = a_show.watched()
assert len(watched) == 1 and watched[0].title == 'Pilot'
def test_video_Show_unwatched(a_show):
assert len(a_show.unwatched()) == 8
def test_video_Show_location(pms):
# This should be a part of test test_video_Show_attrs
# But is excluded because of https://github.com/mjs7231/python-plexapi/issues/97
@ -363,6 +374,12 @@ def test_video_Episode(a_show):
pilot = a_show.episode('Pilot')
assert pilot == a_show.episode(season=1, episode=1)
with pytest.raises(TypeError):
a_show.episode()
with pytest.raises(NotFound):
a_show.episode(season=1337, episode=1337)
def test_video_Episode_analyze(a_tv_section):
ep = a_tv_section.get("Marvel's Daredevil").episode(season=1, episode=1)
ep.analyze()
@ -430,6 +447,7 @@ def test_video_Episode_attrs(a_episode):
#assert par0.media == <Media:Pilot>
assert par0.server.baseurl == 'http://138.68.157.5:32400'
assert par0.size == 31491130
assert ep.isWatched is True
def test_video_Season(a_show):
@ -462,6 +480,7 @@ def test_video_Season_attrs(a_show):
assert str(m.updatedAt.date()) == '2017-01-22'
assert m.viewCount == 1
assert m.viewedLeafCount == 1
assert m.seasonNumber == 1
def test_video_Season_show(a_show):