Skip to content

Commit e56bb29

Browse files
authored
Merge pull request #453 from pkkid/tests
Tests
2 parents 3a95f55 + a1b9cc2 commit e56bb29

File tree

13 files changed

+272
-183
lines changed

13 files changed

+272
-183
lines changed

plexapi/client.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# -*- coding: utf-8 -*-
22
import time
3-
import requests
43

5-
from requests.status_codes import _codes as codes
6-
from plexapi import BASE_HEADERS, CONFIG, TIMEOUT
7-
from plexapi import log, logfilter, utils
4+
import requests
5+
from plexapi import BASE_HEADERS, CONFIG, TIMEOUT, log, logfilter, utils
86
from plexapi.base import PlexObject
97
from plexapi.compat import ElementTree
108
from plexapi.exceptions import BadRequest, Unauthorized, Unsupported
119
from plexapi.playqueue import PlayQueue
12-
10+
from requests.status_codes import _codes as codes
1311

1412
DEFAULT_MTYPE = 'video'
1513

@@ -548,9 +546,9 @@ def setStreams(self, audioStreamID=None, subtitleStreamID=None, videoStreamID=No
548546

549547
# -------------------
550548
# Timeline Commands
551-
def timeline(self):
549+
def timeline(self, wait=1):
552550
""" Poll the current timeline and return the XML response. """
553-
return self.sendCommand('timeline/poll', wait=1)
551+
return self.sendCommand('timeline/poll', wait=wait)
554552

555553
def isPlayingMedia(self, includePaused=False):
556554
""" Returns True if any media is currently playing.
@@ -559,7 +557,7 @@ def isPlayingMedia(self, includePaused=False):
559557
includePaused (bool): Set True to treat currently paused items
560558
as playing (optional; default True).
561559
"""
562-
for mediatype in self.timeline():
560+
for mediatype in self.timeline(wait=0):
563561
if mediatype.get('state') == 'playing':
564562
return True
565563
if includePaused and mediatype.get('state') == 'paused':

plexapi/library.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# -*- coding: utf-8 -*-
22
from plexapi import X_PLEX_CONTAINER_SIZE, log, utils
33
from plexapi.base import PlexObject
4-
from plexapi.compat import unquote, urlencode, quote_plus
5-
from plexapi.media import MediaTag
4+
from plexapi.compat import quote_plus, unquote, urlencode
65
from plexapi.exceptions import BadRequest, NotFound
6+
from plexapi.media import MediaTag
77
from plexapi.settings import Setting
88

99

@@ -366,6 +366,9 @@ def delete(self):
366366
log.error(msg)
367367
raise
368368

369+
def reload(self, key=None):
370+
return self._server.library.section(self.title)
371+
369372
def edit(self, agent=None, **kwargs):
370373
""" Edit a library (Note: agent is required). See :class:`~plexapi.library.Library` for example usage.
371374
@@ -1013,9 +1016,11 @@ class Collections(PlexObject):
10131016

10141017
TAG = 'Directory'
10151018
TYPE = 'collection'
1019+
_include = "?includeExternalMedia=1&includePreferences=1"
10161020

10171021
def _loadData(self, data):
10181022
self.ratingKey = utils.cast(int, data.attrib.get('ratingKey'))
1023+
self._details_key = "/library/metadata/%s%s" % (self.ratingKey, self._include)
10191024
self.key = data.attrib.get('key')
10201025
self.type = data.attrib.get('type')
10211026
self.title = data.attrib.get('title')

plexapi/media.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import xml
44

5-
from plexapi import compat, log, utils, settings
5+
from plexapi import compat, log, settings, utils
66
from plexapi.base import PlexObject
77
from plexapi.exceptions import BadRequest
88
from plexapi.utils import cast

plexapi/utils.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
import logging
33
import os
44
import re
5-
import requests
65
import time
76
import zipfile
87
from datetime import datetime
98
from getpass import getpass
10-
from threading import Thread, Event
11-
from tqdm import tqdm
9+
from threading import Event, Thread
10+
11+
import requests
1212
from plexapi import compat
1313
from plexapi.exceptions import NotFound
14+
from tqdm import tqdm
1415

1516
log = logging.getLogger('plexapi')
1617

@@ -67,10 +68,13 @@ def cast(func, value):
6768
"""
6869
if value is not None:
6970
if func == bool:
70-
try:
71-
return bool(int(value))
72-
except ValueError:
73-
return bool(value)
71+
if value in (1, True, "1", "true"):
72+
return True
73+
elif value in (0, False, "0", "false"):
74+
return False
75+
else:
76+
raise ValueError(value)
77+
7478
elif func in (int, float):
7579
try:
7680
return func(value)

tests/conftest.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
# -*- coding: utf-8 -*-
2-
import plexapi
3-
import pytest
4-
import requests
52
import time
63
from datetime import datetime
74
from functools import partial
85
from os import environ
6+
7+
import plexapi
8+
import pytest
9+
import requests
10+
from plexapi import compat
11+
from plexapi.client import PlexClient
12+
from plexapi.compat import MagicMock, patch
913
from plexapi.myplex import MyPlexAccount
14+
from plexapi.server import PlexServer
1015

1116
try:
1217
from unittest.mock import patch, MagicMock, mock_open
1318
except ImportError:
1419
from mock import patch, MagicMock, mock_open
1520

16-
from plexapi import compat
17-
from plexapi.compat import patch, MagicMock
18-
from plexapi.client import PlexClient
19-
from plexapi.server import PlexServer
2021

2122
SERVER_BASEURL = plexapi.CONFIG.get('auth.server_baseurl')
2223
MYPLEX_USERNAME = plexapi.CONFIG.get('auth.myplex_username')
@@ -147,13 +148,13 @@ def fresh_plex():
147148

148149

149150
@pytest.fixture()
150-
def plex2():
151+
def plex2(plex):
151152
return plex()
152153

153154

154155
@pytest.fixture()
155-
def client(request):
156-
return PlexClient(plex(), baseurl=CLIENT_BASEURL, token=CLIENT_TOKEN)
156+
def client(request, plex):
157+
return PlexClient(plex, baseurl=CLIENT_BASEURL, token=CLIENT_TOKEN)
157158

158159

159160
@pytest.fixture()
@@ -185,13 +186,12 @@ def movie(movies):
185186
def collection(plex, movie):
186187

187188
try:
188-
plex.library.section('Movies').collection()[0]
189+
return plex.library.section('Movies').collection()[0]
189190
except IndexError:
190191
movie.addCollection(["marvel"])
191192

192-
sec = plex.library.section('Movies').reload()
193-
194-
return sec.collection()[0]
193+
n = plex.library.section('Movies').reload()
194+
return n.collection()[0]
195195

196196

197197
@pytest.fixture()
@@ -225,7 +225,8 @@ def photoalbum(photos):
225225
return photos.get('Cats')
226226
except Exception:
227227
return photos.get('photo_album1')
228-
228+
229+
229230
@pytest.fixture()
230231
def subtitle():
231232
mopen = mock_open()

tests/test_audio.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from datetime import datetime
3+
34
from . import conftest as utils
45

56

@@ -34,7 +35,7 @@ def test_audio_Artist_get(artist, music):
3435

3536
def test_audio_Artist_history(artist):
3637
history = artist.history()
37-
assert len(history)
38+
assert isinstance(history, list)
3839

3940

4041
def test_audio_Artist_track(artist):
@@ -87,12 +88,12 @@ def test_audio_Album_attrs(album):
8788

8889
def test_audio_Album_history(album):
8990
history = album.history()
90-
assert len(history)
91+
assert isinstance(history, list)
9192

9293

9394
def test_audio_Track_history(track):
9495
history = track.history()
95-
assert len(history)
96+
assert isinstance(history, list)
9697

9798

9899
def test_audio_Album_tracks(album):
@@ -228,7 +229,7 @@ def test_audio_Track_attrs(album):
228229
assert track.parentTitle == 'Unmastered Impulses'
229230
assert track.playlistItemID is None
230231
assert track.primaryExtraKey is None
231-
# assert track.ratingCount == 9
232+
#assert utils.is_int(track.ratingCount)
232233
assert utils.is_int(track.ratingKey)
233234
assert track._server._baseurl == utils.SERVER_BASEURL
234235
assert track.sessionKey is None

0 commit comments

Comments
 (0)