mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-26 05:30:20 +00:00
fix invite and add editfriend.
This commit is contained in:
parent
fba0824ddd
commit
0f16ea9cb7
4 changed files with 50 additions and 20 deletions
|
@ -428,8 +428,8 @@ class MyPlexUser(PlexObject):
|
|||
self.recommendationsPlaylistId = data.attrib.get('recommendationsPlaylistId')
|
||||
self.restricted = data.attrib.get('restricted')
|
||||
self.thumb = data.attrib.get('thumb')
|
||||
self.title = data.attrib.get('title')
|
||||
self.username = data.attrib.get('username')
|
||||
self.title = data.attrib.get('title', '')
|
||||
self.username = data.attrib.get('username', '')
|
||||
self.servers = self.findItems(data, MyPlexServerShare)
|
||||
|
||||
def get_token(self, machineIdentifier):
|
||||
|
|
|
@ -15,12 +15,24 @@
|
|||
# 3. A Photos section containing the photoalbums:
|
||||
# Cats (with cute cat photos inside)
|
||||
# 4. A TV Shows section containing at least two seasons of The 100.
|
||||
import plexapi, pytest, requests
|
||||
from datetime import datetime
|
||||
from functools import partial
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
try:
|
||||
from unittest.mock import patch, MagicMock
|
||||
except ImportError:
|
||||
from mock import patch, MagicMock
|
||||
|
||||
|
||||
import plexapi
|
||||
from plexapi import compat
|
||||
from plexapi.client import PlexClient
|
||||
from datetime import datetime
|
||||
|
||||
from plexapi.server import PlexServer
|
||||
from functools import partial
|
||||
|
||||
|
||||
SERVER_BASEURL = plexapi.CONFIG.get('auth.server_baseurl')
|
||||
SERVER_TOKEN = plexapi.CONFIG.get('auth.server_token')
|
||||
|
@ -150,13 +162,12 @@ def monkeydownload(request, monkeypatch):
|
|||
monkeypatch.undo()
|
||||
|
||||
|
||||
def callable_http_patch(mocker):
|
||||
# mocker is a fixture
|
||||
# but this is a normal func so we can do http calls inside the tests
|
||||
return mocker.patch('plexapi.server.requests.sessions.Session.send',
|
||||
return_value=mocker.MagicMock(status_code=200,
|
||||
def callable_http_patch():
|
||||
return patch('plexapi.server.requests.sessions.Session.send',
|
||||
return_value=MagicMock(status_code=200,
|
||||
text='<xml><child></child></xml>'))
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def empty_response(mocker):
|
||||
response = mocker.MagicMock(status_code=200, text='<xml><child></child></xml>')
|
||||
|
@ -164,8 +175,8 @@ def empty_response(mocker):
|
|||
|
||||
|
||||
@pytest.fixture()
|
||||
def patched_http_call(mocker):
|
||||
return callable_http_patch(mocker)
|
||||
def patched_http_call():
|
||||
return callable_http_patch()
|
||||
|
||||
|
||||
# ---------------------------------
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
from plexapi.exceptions import BadRequest
|
||||
from plexapi.exceptions import BadRequest, NotFound
|
||||
from . import conftest as utils
|
||||
|
||||
|
||||
|
@ -83,6 +83,7 @@ def test_myplex_resource(account):
|
|||
|
||||
|
||||
def test_myplex_webhooks(account):
|
||||
# Webhooks are a plex pass feature to this will fail
|
||||
with pytest.raises(BadRequest):
|
||||
account.webhooks()
|
||||
|
||||
|
@ -123,7 +124,7 @@ def test_myplex_inviteFriend_remove(account, plex, mocker):
|
|||
|
||||
ids = account._getSectionIds(plex.machineIdentifier, secs)
|
||||
with mocker.patch.object(account, '_getSectionIds', return_value=ids):
|
||||
with utils.callable_http_patch(mocker):
|
||||
with utils.callable_http_patch():
|
||||
|
||||
account.inviteFriend(inv_user, plex, secs, allowSync=True, allowCameraUpload=True,
|
||||
allowChannels=False, filterMovies=vid_filter, filterTelevision=vid_filter,
|
||||
|
@ -131,5 +132,23 @@ def test_myplex_inviteFriend_remove(account, plex, mocker):
|
|||
|
||||
assert inv_user not in [u.title for u in account.users()]
|
||||
|
||||
with utils.callable_http_patch(mocker):
|
||||
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']})
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ def test_video_Movie_delete_part(movie, mocker):
|
|||
# See https://github.com/pkkid/python-plexapi/issues/201
|
||||
m = movie.reload()
|
||||
for part in m.iterParts():
|
||||
with utils.callable_http_patch(mocker):
|
||||
with utils.callable_http_patch():
|
||||
part.delete()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue