mirror of
https://github.com/pkkid/python-plexapi
synced 2024-12-02 00:19:11 +00:00
mock delete properly
This commit is contained in:
parent
9509683d28
commit
0594f24f8b
3 changed files with 31 additions and 6 deletions
|
@ -148,7 +148,7 @@ class MediaPartStream(PlexObject):
|
||||||
self.type = cast(int, data.attrib.get('streamType'))
|
self.type = cast(int, data.attrib.get('streamType'))
|
||||||
|
|
||||||
@staticmethod
|
@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. """
|
""" Factory method returns a new MediaPartStream from xml data. """
|
||||||
STREAMCLS = {1: VideoStream, 2: AudioStream, 3: SubtitleStream}
|
STREAMCLS = {1: VideoStream, 2: AudioStream, 3: SubtitleStream}
|
||||||
stype = cast(int, data.attrib.get('streamType'))
|
stype = cast(int, data.attrib.get('streamType'))
|
||||||
|
|
|
@ -150,10 +150,27 @@ def monkeydownload(request, monkeypatch):
|
||||||
monkeypatch.undo()
|
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
|
# Utility Functions
|
||||||
# ---------------------------------
|
# ---------------------------------
|
||||||
|
|
||||||
def is_datetime(value):
|
def is_datetime(value):
|
||||||
return value > MIN_DATETIME
|
return value > MIN_DATETIME
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,10 @@ def test_video_ne(movies):
|
||||||
assert len(movies.fetchItems('/library/sections/7/all', title__ne='Sintel')) == 3
|
assert len(movies.fetchItems('/library/sections/7/all', title__ne='Sintel')) == 3
|
||||||
|
|
||||||
|
|
||||||
def test_video_Movie_delete(monkeypatch, movie):
|
def test_video_Movie_delete(movie, patched_http_call):
|
||||||
monkeypatch.delattr('requests.sessions.Session.request')
|
|
||||||
with pytest.raises(AttributeError):
|
|
||||||
movie.delete()
|
movie.delete()
|
||||||
|
|
||||||
|
|
||||||
def test_video_Movie_addCollection(movie):
|
def test_video_Movie_addCollection(movie):
|
||||||
labelname = 'Random_label'
|
labelname = 'Random_label'
|
||||||
org_collection = [tag.tag for tag in movie.collections if tag]
|
org_collection = [tag.tag for tag in movie.collections if tag]
|
||||||
|
@ -61,6 +60,15 @@ def test_video_Movie_isPartialObject(movie):
|
||||||
assert movie.isPartialObject()
|
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):
|
def test_video_Movie_iterParts(movie):
|
||||||
assert len(list(movie.iterParts())) >= 1
|
assert len(list(movie.iterParts())) >= 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue