2017-01-09 04:40:39 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-10-25 19:53:52 +00:00
|
|
|
import pytest
|
2017-10-28 20:58:47 +00:00
|
|
|
from plexapi.exceptions import BadRequest, NotFound
|
2017-10-26 23:09:17 +00:00
|
|
|
from . import conftest as utils
|
2017-01-09 04:40:39 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
|
|
|
|
def test_myplex_accounts(account, plex):
|
2017-01-09 04:40:39 +00:00
|
|
|
assert account, 'Must specify username, password & resource to run this test.'
|
2017-02-02 04:10:12 +00:00
|
|
|
print('MyPlexAccount:')
|
|
|
|
print('username: %s' % account.username)
|
|
|
|
print('email: %s' % account.email)
|
|
|
|
print('home: %s' % account.home)
|
|
|
|
print('queueEmail: %s' % account.queueEmail)
|
2017-01-09 04:40:39 +00:00
|
|
|
assert account.username, 'Account has no username'
|
|
|
|
assert account.authenticationToken, 'Account has no authenticationToken'
|
|
|
|
assert account.email, 'Account has no email'
|
|
|
|
assert account.home is not None, 'Account has no home'
|
|
|
|
assert account.queueEmail, 'Account has no queueEmail'
|
2017-04-15 00:47:59 +00:00
|
|
|
account = plex.account()
|
2017-02-02 04:10:12 +00:00
|
|
|
print('Local PlexServer.account():')
|
|
|
|
print('username: %s' % account.username)
|
2017-10-25 19:53:52 +00:00
|
|
|
#print('authToken: %s' % account.authToken)
|
2017-02-02 04:10:12 +00:00
|
|
|
print('signInState: %s' % account.signInState)
|
2017-01-09 04:40:39 +00:00
|
|
|
assert account.username, 'Account has no username'
|
|
|
|
assert account.authToken, 'Account has no authToken'
|
|
|
|
assert account.signInState, 'Account has no signInState'
|
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_myplex_resources(account):
|
2017-01-09 04:40:39 +00:00
|
|
|
assert account, 'Must specify username, password & resource to run this test.'
|
|
|
|
resources = account.resources()
|
|
|
|
for resource in resources:
|
|
|
|
name = resource.name or 'Unknown'
|
|
|
|
connections = [c.uri for c in resource.connections]
|
|
|
|
connections = ', '.join(connections) if connections else 'None'
|
2017-02-02 04:10:12 +00:00
|
|
|
print('%s (%s): %s' % (name, resource.product, connections))
|
2017-01-09 04:40:39 +00:00
|
|
|
assert resources, 'No resources found for account: %s' % account.name
|
|
|
|
|
2017-02-02 04:10:12 +00:00
|
|
|
|
2017-04-24 02:59:22 +00:00
|
|
|
def test_myplex_connect_to_resource(plex, account):
|
|
|
|
servername = plex.friendlyName
|
2017-04-15 00:47:59 +00:00
|
|
|
for resource in account.resources():
|
2017-04-24 02:59:22 +00:00
|
|
|
if resource.name == servername:
|
2017-02-02 04:10:12 +00:00
|
|
|
break
|
2017-04-24 02:59:22 +00:00
|
|
|
assert resource.connect(timeout=10)
|
2017-02-02 04:10:12 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_myplex_devices(account):
|
2017-01-09 04:40:39 +00:00
|
|
|
devices = account.devices()
|
|
|
|
for device in devices:
|
|
|
|
name = device.name or 'Unknown'
|
|
|
|
connections = ', '.join(device.connections) if device.connections else 'None'
|
2017-02-02 04:10:12 +00:00
|
|
|
print('%s (%s): %s' % (name, device.product, connections))
|
2017-01-09 04:40:39 +00:00
|
|
|
assert devices, 'No devices found for account: %s' % account.name
|
|
|
|
|
|
|
|
|
2017-10-25 19:53:52 +00:00
|
|
|
def test_myplex_device(account):
|
|
|
|
assert account.device('pkkid-plexapi')
|
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def _test_myplex_connect_to_device(account):
|
2017-01-09 04:40:39 +00:00
|
|
|
devices = account.devices()
|
|
|
|
for device in devices:
|
2017-02-02 04:10:12 +00:00
|
|
|
if device.name == 'some client name' and len(device.connections):
|
2017-01-09 04:40:39 +00:00
|
|
|
break
|
|
|
|
client = device.connect()
|
|
|
|
assert client, 'Unable to connect to device'
|
2017-02-02 04:10:12 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_myplex_users(account):
|
2017-02-02 04:10:12 +00:00
|
|
|
users = account.users()
|
|
|
|
assert users, 'Found no users on account: %s' % account.name
|
|
|
|
print('Found %s users.' % len(users))
|
2017-04-15 00:47:59 +00:00
|
|
|
user = account.user(users[0].title)
|
2017-02-02 04:10:12 +00:00
|
|
|
print('Found user: %s' % user)
|
2017-04-15 00:47:59 +00:00
|
|
|
assert user, 'Could not find user %s' % users[0].title
|
2017-10-25 19:53:52 +00:00
|
|
|
|
2018-01-01 23:15:40 +00:00
|
|
|
assert len(users[0].servers[0].sections()) == 10, "Could'nt info about the shared libraries"
|
2017-10-25 20:07:06 +00:00
|
|
|
|
2017-10-25 19:53:52 +00:00
|
|
|
|
|
|
|
def test_myplex_resource(account):
|
|
|
|
assert account.resource('pkkid-plexapi')
|
|
|
|
|
|
|
|
|
|
|
|
def test_myplex_webhooks(account):
|
2017-10-28 20:58:47 +00:00
|
|
|
# Webhooks are a plex pass feature to this will fail
|
2017-10-25 19:53:52 +00:00
|
|
|
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())
|
|
|
|
|
2017-10-26 23:09:17 +00:00
|
|
|
|
|
|
|
def test_myplex_inviteFriend_remove(account, plex, mocker):
|
|
|
|
inv_user = 'hellowlol'
|
|
|
|
vid_filter = {'contentRating': ['G'], 'label': ['foo']}
|
|
|
|
secs = plex.library.sections()
|
|
|
|
|
|
|
|
ids = account._getSectionIds(plex.machineIdentifier, secs)
|
|
|
|
with mocker.patch.object(account, '_getSectionIds', return_value=ids):
|
2017-10-28 20:58:47 +00:00
|
|
|
with utils.callable_http_patch():
|
2017-10-26 23:09:17 +00:00
|
|
|
|
|
|
|
account.inviteFriend(inv_user, plex, secs, allowSync=True, allowCameraUpload=True,
|
2017-10-28 20:58:47 +00:00
|
|
|
allowChannels=False, filterMovies=vid_filter, filterTelevision=vid_filter,
|
|
|
|
filterMusic={'label': ['foo']})
|
2017-10-26 23:09:17 +00:00
|
|
|
|
|
|
|
assert inv_user not in [u.title for u in account.users()]
|
|
|
|
|
2017-10-28 20:58:47 +00:00
|
|
|
with pytest.raises(NotFound):
|
|
|
|
with utils.callable_http_patch():
|
|
|
|
account.removeFriend(inv_user)
|
|
|
|
|
|
|
|
|
|
|
|
def test_myplex_updateFriend(account, plex, mocker):
|
|
|
|
edit_user = 'PKKid'
|
|
|
|
vid_filter = {'contentRating': ['G'], 'label': ['foo']}
|
|
|
|
secs = plex.library.sections()
|
|
|
|
user = account.user(edit_user)
|
|
|
|
|
|
|
|
ids = account._getSectionIds(plex.machineIdentifier, secs)
|
|
|
|
with mocker.patch.object(account, '_getSectionIds', return_value=ids):
|
|
|
|
with mocker.patch.object(account, 'user', return_value=user):
|
|
|
|
with utils.callable_http_patch():
|
|
|
|
|
|
|
|
account.updateFriend(edit_user, plex, secs, allowSync=True, removeSections=True,
|
|
|
|
allowCameraUpload=True, allowChannels=False, filterMovies=vid_filter,
|
|
|
|
filterTelevision=vid_filter, filterMusic={'label': ['foo']})
|
|
|
|
|