mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 22:24:12 +00:00
add more tests to inc cov.
This commit is contained in:
parent
f8e594ff3f
commit
807b6ebc3c
4 changed files with 57 additions and 10 deletions
|
@ -150,10 +150,10 @@ class MyPlexAccount(PlexObject):
|
|||
log.debug('%s %s %s', method.__name__.upper(), url, kwargs.get('json', ''))
|
||||
headers = self._headers(**headers or {})
|
||||
response = method(url, headers=headers, timeout=timeout, **kwargs)
|
||||
if response.status_code not in (200, 201, 204):
|
||||
if response.status_code not in (200, 201, 204): # pragma: no cover
|
||||
codename = codes.get(response.status_code)[0]
|
||||
errtext = response.text.replace('\n', ' ')
|
||||
log.warn('BadRequest (%s) %s %s; %s' % (response.status_code, codename, response.url, errtext))
|
||||
log.warning('BadRequest (%s) %s %s; %s' % (response.status_code, codename, response.url, errtext))
|
||||
raise BadRequest('(%s) %s %s; %s' % (response.status_code, codename, response.url, errtext))
|
||||
data = response.text.encode('utf8')
|
||||
return ElementTree.fromstring(data) if data.strip() else None
|
||||
|
|
|
@ -46,7 +46,6 @@ class Photoalbum(PlexPartialObject):
|
|||
self.type = data.attrib.get('type')
|
||||
self.updatedAt = utils.toDatetime(data.attrib.get('updatedAt'))
|
||||
|
||||
|
||||
def albums(self, **kwargs):
|
||||
""" Returns a list of :class:`~plexapi.photo.Photoalbum` objects in this album. """
|
||||
key = '/library/metadata/%s/children' % self.ratingKey
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
from plexapi.exceptions import BadRequest
|
||||
|
||||
|
||||
def test_myplex_accounts(account, plex):
|
||||
|
@ -16,7 +18,7 @@ def test_myplex_accounts(account, plex):
|
|||
account = plex.account()
|
||||
print('Local PlexServer.account():')
|
||||
print('username: %s' % account.username)
|
||||
print('authToken: %s' % account.authToken)
|
||||
#print('authToken: %s' % account.authToken)
|
||||
print('signInState: %s' % account.signInState)
|
||||
assert account.username, 'Account has no username'
|
||||
assert account.authToken, 'Account has no authToken'
|
||||
|
@ -51,6 +53,10 @@ def test_myplex_devices(account):
|
|||
assert devices, 'No devices found for account: %s' % account.name
|
||||
|
||||
|
||||
def test_myplex_device(account):
|
||||
assert account.device('pkkid-plexapi')
|
||||
|
||||
|
||||
def _test_myplex_connect_to_device(account):
|
||||
devices = account.devices()
|
||||
for device in devices:
|
||||
|
@ -67,3 +73,47 @@ def test_myplex_users(account):
|
|||
user = account.user(users[0].title)
|
||||
print('Found user: %s' % user)
|
||||
assert user, 'Could not find user %s' % users[0].title
|
||||
|
||||
|
||||
def test_myplex_resource(account):
|
||||
assert account.resource('pkkid-plexapi')
|
||||
|
||||
|
||||
def test_myplex_webhooks(account):
|
||||
with pytest.raises(BadRequest):
|
||||
account.webhooks()
|
||||
|
||||
|
||||
def test_myplex_addwebhooks(account):
|
||||
with pytest.raises(BadRequest):
|
||||
account.addWebhook('http://site.com')
|
||||
|
||||
|
||||
def test_myplex_deletewebhooks(account):
|
||||
with pytest.raises(BadRequest):
|
||||
account.deleteWebhook('http://site.com')
|
||||
|
||||
|
||||
def test_myplex_optout(account):
|
||||
def enabled():
|
||||
ele = account.query('https://plex.tv/api/v2/user/privacy')
|
||||
lib = ele.attrib.get('optOutLibraryStats')
|
||||
play = ele.attrib.get('optOutPlayback')
|
||||
return bool(int(lib)), bool(int(play))
|
||||
|
||||
# This should be False False
|
||||
library_enabled, playback_enabled = enabled()
|
||||
|
||||
account.optOut(library=True, playback=True)
|
||||
|
||||
assert all(enabled())
|
||||
|
||||
account.optOut(library=False, playback=False)
|
||||
|
||||
assert not all(enabled())
|
||||
|
||||
|
||||
|
||||
|
||||
reloaded_account = account.reload()
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import pytest, time
|
||||
import time
|
||||
import pytest
|
||||
|
||||
|
||||
def test_create_playlist(plex, show):
|
||||
|
@ -99,14 +100,11 @@ def test_playqueues(plex):
|
|||
|
||||
|
||||
def test_copyToUser(plex, show, fresh_plex):
|
||||
# Skip out if we do not have plexpass
|
||||
if not plex.myPlexSubscription:
|
||||
pytest.skip('PlexPass subscription required for test.')
|
||||
episodes = show.episodes()
|
||||
playlist = plex.createPlaylist('shared_from_test_plexapi', episodes)
|
||||
try:
|
||||
playlist.copyToUser('plexapi2')
|
||||
user = plex.myPlexAccount().user('plexapi2')
|
||||
playlist.copyToUser('PKKid')
|
||||
user = plex.myPlexAccount().user('PKKid')
|
||||
user_plex = fresh_plex(plex._baseurl, user.get_token(plex.machineIdentifier))
|
||||
assert playlist.title in [p.title for p in user_plex.playlists()]
|
||||
finally:
|
||||
|
|
Loading…
Reference in a new issue