Skip to content

Commit 0f16ea9

Browse files
committed
fix invite and add editfriend.
1 parent fba0824 commit 0f16ea9

File tree

4 files changed

+50
-20
lines changed

4 files changed

+50
-20
lines changed

plexapi/myplex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ def _loadData(self, data):
428428
self.recommendationsPlaylistId = data.attrib.get('recommendationsPlaylistId')
429429
self.restricted = data.attrib.get('restricted')
430430
self.thumb = data.attrib.get('thumb')
431-
self.title = data.attrib.get('title')
432-
self.username = data.attrib.get('username')
431+
self.title = data.attrib.get('title', '')
432+
self.username = data.attrib.get('username', '')
433433
self.servers = self.findItems(data, MyPlexServerShare)
434434

435435
def get_token(self, machineIdentifier):

tests/conftest.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,24 @@
1515
# 3. A Photos section containing the photoalbums:
1616
# Cats (with cute cat photos inside)
1717
# 4. A TV Shows section containing at least two seasons of The 100.
18-
import plexapi, pytest, requests
18+
from datetime import datetime
19+
from functools import partial
20+
21+
import pytest
22+
import requests
23+
24+
try:
25+
from unittest.mock import patch, MagicMock
26+
except ImportError:
27+
from mock import patch, MagicMock
28+
29+
30+
import plexapi
1931
from plexapi import compat
2032
from plexapi.client import PlexClient
21-
from datetime import datetime
33+
2234
from plexapi.server import PlexServer
23-
from functools import partial
35+
2436

2537
SERVER_BASEURL = plexapi.CONFIG.get('auth.server_baseurl')
2638
SERVER_TOKEN = plexapi.CONFIG.get('auth.server_token')
@@ -150,12 +162,11 @@ def monkeydownload(request, monkeypatch):
150162
monkeypatch.undo()
151163

152164

153-
def callable_http_patch(mocker):
154-
# mocker is a fixture
155-
# but this is a normal func so we can do http calls inside the tests
156-
return mocker.patch('plexapi.server.requests.sessions.Session.send',
157-
return_value=mocker.MagicMock(status_code=200,
158-
text='<xml><child></child></xml>'))
165+
def callable_http_patch():
166+
return patch('plexapi.server.requests.sessions.Session.send',
167+
return_value=MagicMock(status_code=200,
168+
text='<xml><child></child></xml>'))
169+
159170

160171
@pytest.fixture()
161172
def empty_response(mocker):
@@ -164,8 +175,8 @@ def empty_response(mocker):
164175

165176

166177
@pytest.fixture()
167-
def patched_http_call(mocker):
168-
return callable_http_patch(mocker)
178+
def patched_http_call():
179+
return callable_http_patch()
169180

170181

171182
# ---------------------------------

tests/test_myplex.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import pytest
3-
from plexapi.exceptions import BadRequest
3+
from plexapi.exceptions import BadRequest, NotFound
44
from . import conftest as utils
55

66

@@ -83,6 +83,7 @@ def test_myplex_resource(account):
8383

8484

8585
def test_myplex_webhooks(account):
86+
# Webhooks are a plex pass feature to this will fail
8687
with pytest.raises(BadRequest):
8788
account.webhooks()
8889

@@ -123,13 +124,31 @@ def test_myplex_inviteFriend_remove(account, plex, mocker):
123124

124125
ids = account._getSectionIds(plex.machineIdentifier, secs)
125126
with mocker.patch.object(account, '_getSectionIds', return_value=ids):
126-
with utils.callable_http_patch(mocker):
127+
with utils.callable_http_patch():
127128

128129
account.inviteFriend(inv_user, plex, secs, allowSync=True, allowCameraUpload=True,
129-
allowChannels=False, filterMovies=vid_filter, filterTelevision=vid_filter,
130-
filterMusic={'label': ['foo']})
130+
allowChannels=False, filterMovies=vid_filter, filterTelevision=vid_filter,
131+
filterMusic={'label': ['foo']})
131132

132133
assert inv_user not in [u.title for u in account.users()]
133134

134-
with utils.callable_http_patch(mocker):
135-
account.removeFriend(inv_user)
135+
with pytest.raises(NotFound):
136+
with utils.callable_http_patch():
137+
account.removeFriend(inv_user)
138+
139+
140+
def test_myplex_updateFriend(account, plex, mocker):
141+
edit_user = 'PKKid'
142+
vid_filter = {'contentRating': ['G'], 'label': ['foo']}
143+
secs = plex.library.sections()
144+
user = account.user(edit_user)
145+
146+
ids = account._getSectionIds(plex.machineIdentifier, secs)
147+
with mocker.patch.object(account, '_getSectionIds', return_value=ids):
148+
with mocker.patch.object(account, 'user', return_value=user):
149+
with utils.callable_http_patch():
150+
151+
account.updateFriend(edit_user, plex, secs, allowSync=True, removeSections=True,
152+
allowCameraUpload=True, allowChannels=False, filterMovies=vid_filter,
153+
filterTelevision=vid_filter, filterMusic={'label': ['foo']})
154+

tests/test_video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_video_Movie_delete_part(movie, mocker):
6565
# See https://github.com/pkkid/python-plexapi/issues/201
6666
m = movie.reload()
6767
for part in m.iterParts():
68-
with utils.callable_http_patch(mocker):
68+
with utils.callable_http_patch():
6969
part.delete()
7070

7171

0 commit comments

Comments
 (0)