fix invite and add editfriend.

This commit is contained in:
Hellowlol 2017-10-28 22:58:47 +02:00
parent fba0824ddd
commit 0f16ea9cb7
4 changed files with 50 additions and 20 deletions

View file

@ -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):

View file

@ -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,12 +162,11 @@ 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,
text='<xml><child></child></xml>'))
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):
@ -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()
# ---------------------------------

View file

@ -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,13 +124,31 @@ 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,
filterMusic={'label': ['foo']})
allowChannels=False, filterMovies=vid_filter, filterTelevision=vid_filter,
filterMusic={'label': ['foo']})
assert inv_user not in [u.title for u in account.users()]
with utils.callable_http_patch(mocker):
account.removeFriend(inv_user)
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']})

View file

@ -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()