Skip to content

Commit 0594f24

Browse files
committed
mock delete properly
1 parent 9509683 commit 0594f24

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

plexapi/media.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def _loadData(self, data):
148148
self.type = cast(int, data.attrib.get('streamType'))
149149

150150
@staticmethod
151-
def parse(server, data, initpath):
151+
def parse(server, data, initpath): # pragma: no cover seems to be dead code.
152152
""" Factory method returns a new MediaPartStream from xml data. """
153153
STREAMCLS = {1: VideoStream, 2: AudioStream, 3: SubtitleStream}
154154
stype = cast(int, data.attrib.get('streamType'))

tests/conftest.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,27 @@ def monkeydownload(request, monkeypatch):
150150
monkeypatch.undo()
151151

152152

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>'))
159+
160+
@pytest.fixture()
161+
def empty_response(mocker):
162+
response = mocker.MagicMock(status_code=200, text='<xml><child></child></xml>')
163+
return response
164+
165+
@pytest.fixture()
166+
def patched_http_call(mocker):
167+
return callable_http_patch(mocker)
168+
169+
170+
153171
# ---------------------------------
154172
# Utility Functions
155173
# ---------------------------------
156-
157174
def is_datetime(value):
158175
return value > MIN_DATETIME
159176

tests/test_video.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ def test_video_ne(movies):
1717
assert len(movies.fetchItems('/library/sections/7/all', title__ne='Sintel')) == 3
1818

1919

20-
def test_video_Movie_delete(monkeypatch, movie):
21-
monkeypatch.delattr('requests.sessions.Session.request')
22-
with pytest.raises(AttributeError):
23-
movie.delete()
20+
def test_video_Movie_delete(movie, patched_http_call):
21+
movie.delete()
22+
2423

2524
def test_video_Movie_addCollection(movie):
2625
labelname = 'Random_label'
@@ -61,6 +60,15 @@ def test_video_Movie_isPartialObject(movie):
6160
assert movie.isPartialObject()
6261

6362

63+
def test_video_Movie_delete_part(movie, mocker):
64+
# we need to reload this as there is a bug in part.delete
65+
# See https://github.com/pkkid/python-plexapi/issues/201
66+
m = movie.reload()
67+
for part in m.iterParts():
68+
with utils.callable_http_patch(mocker):
69+
part.delete()
70+
71+
6472
def test_video_Movie_iterParts(movie):
6573
assert len(list(movie.iterParts())) >= 1
6674

0 commit comments

Comments
 (0)