mock delete properly

This commit is contained in:
Hellowlol 2017-10-26 23:55:59 +02:00
parent 9509683d28
commit 0594f24f8b
3 changed files with 31 additions and 6 deletions

View file

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

View file

@ -150,10 +150,27 @@ 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>'))
@pytest.fixture()
def empty_response(mocker):
response = mocker.MagicMock(status_code=200, text='<xml><child></child></xml>')
return response
@pytest.fixture()
def patched_http_call(mocker):
return callable_http_patch(mocker)
# ---------------------------------
# Utility Functions
# ---------------------------------
def is_datetime(value):
return value > MIN_DATETIME

View file

@ -17,11 +17,10 @@ def test_video_ne(movies):
assert len(movies.fetchItems('/library/sections/7/all', title__ne='Sintel')) == 3
def test_video_Movie_delete(monkeypatch, movie):
monkeypatch.delattr('requests.sessions.Session.request')
with pytest.raises(AttributeError):
def test_video_Movie_delete(movie, patched_http_call):
movie.delete()
def test_video_Movie_addCollection(movie):
labelname = 'Random_label'
org_collection = [tag.tag for tag in movie.collections if tag]
@ -61,6 +60,15 @@ def test_video_Movie_isPartialObject(movie):
assert movie.isPartialObject()
def test_video_Movie_delete_part(movie, mocker):
# we need to reload this as there is a bug in part.delete
# See https://github.com/pkkid/python-plexapi/issues/201
m = movie.reload()
for part in m.iterParts():
with utils.callable_http_patch(mocker):
part.delete()
def test_video_Movie_iterParts(movie):
assert len(list(movie.iterParts())) >= 1