2017-02-02 04:47:22 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-01-09 14:21:54 +00:00
|
|
|
import pytest
|
|
|
|
import plexapi.utils as utils
|
|
|
|
from plexapi.exceptions import NotFound
|
|
|
|
|
|
|
|
|
|
|
|
def test_utils_toDatetime():
|
|
|
|
assert str(utils.toDatetime('2006-03-03', format='%Y-%m-%d')) == '2006-03-03 00:00:00'
|
|
|
|
assert str(utils.toDatetime('0'))[:-9] == '1970-01-01'
|
|
|
|
# should this handle args as '0' # no need element attrs are strings.
|
|
|
|
|
2017-02-02 04:47:22 +00:00
|
|
|
|
2017-01-09 14:21:54 +00:00
|
|
|
def _test_utils_threaded():
|
2017-02-02 04:47:22 +00:00
|
|
|
# TODO: Implement test_utils_threaded
|
2017-01-09 14:21:54 +00:00
|
|
|
pass
|
|
|
|
|
2017-02-02 04:47:22 +00:00
|
|
|
|
2017-01-09 14:21:54 +00:00
|
|
|
def test_utils_searchType():
|
|
|
|
st = utils.searchType('movie')
|
|
|
|
assert st == 1
|
2017-01-29 21:22:48 +00:00
|
|
|
movie = utils.searchType(1)
|
|
|
|
assert movie == '1'
|
2017-01-09 14:21:54 +00:00
|
|
|
with pytest.raises(NotFound):
|
|
|
|
utils.searchType('kekekekeke')
|
|
|
|
|
|
|
|
|
|
|
|
def _test_utils_listItems():
|
2017-02-02 04:47:22 +00:00
|
|
|
# TODO: Implement test_utils_listItems
|
2017-01-09 14:21:54 +00:00
|
|
|
pass
|
|
|
|
|
2017-02-02 04:47:22 +00:00
|
|
|
|
2017-01-09 14:21:54 +00:00
|
|
|
def _test_utils_listChoices(pms):
|
2017-02-02 04:47:22 +00:00
|
|
|
# TODO: Implement test_utils_listChoices
|
2017-01-09 14:21:54 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def test_utils_joinArgs():
|
|
|
|
test_dict = {'genre': 'action', 'type': 1337}
|
|
|
|
assert utils.joinArgs(test_dict) == '?genre=action&type=1337'
|
|
|
|
|
|
|
|
|
|
|
|
def test_utils_isInt():
|
|
|
|
assert utils.isInt(1) is True
|
|
|
|
assert utils.isInt('got_you') is False
|
|
|
|
assert utils.isInt('1337') is True
|
|
|
|
|
2017-02-02 04:47:22 +00:00
|
|
|
|
2017-01-09 14:21:54 +00:00
|
|
|
def _test_utils_findUsername():
|
2017-02-02 04:47:22 +00:00
|
|
|
# TODO: Implement test_utils_findUsername
|
2017-01-09 14:21:54 +00:00
|
|
|
pass
|
|
|
|
|
2017-02-02 04:47:22 +00:00
|
|
|
|
2017-01-09 14:21:54 +00:00
|
|
|
def _test_utils_findStreams():
|
2017-02-02 04:47:22 +00:00
|
|
|
# TODO: Implement test_utils_findStreams
|
2017-01-09 14:21:54 +00:00
|
|
|
pass
|
|
|
|
|
2017-02-02 04:47:22 +00:00
|
|
|
|
2017-01-09 14:21:54 +00:00
|
|
|
def _test_utils_findPlayer():
|
2017-02-02 04:47:22 +00:00
|
|
|
# TODO: Implement test_utils_findPlayer
|
2017-01-09 14:21:54 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def _test_utils_findLocations():
|
2017-02-02 04:47:22 +00:00
|
|
|
# TODO: Implement test_utils_findLocations
|
2017-01-09 14:21:54 +00:00
|
|
|
pass
|
|
|
|
|
2017-02-02 04:47:22 +00:00
|
|
|
|
2017-01-09 14:21:54 +00:00
|
|
|
def _test_utils_findItem():
|
2017-02-02 04:47:22 +00:00
|
|
|
# TODO: Implement test_utils_findItem
|
2017-01-09 14:21:54 +00:00
|
|
|
pass
|
|
|
|
|
2017-01-29 21:22:48 +00:00
|
|
|
|
|
|
|
def test_utils_findKey(pms):
|
|
|
|
with pytest.raises(NotFound):
|
|
|
|
assert utils.findKey(pms, '9999999')
|
|
|
|
assert utils.findKey(pms, '1')
|
|
|
|
|
2017-01-09 14:21:54 +00:00
|
|
|
|
|
|
|
def test_utils_cast():
|
|
|
|
t_int_int = utils.cast(int, 1)
|
|
|
|
t_int_str_int = utils.cast(int, '1')
|
|
|
|
t_bool_str_int = utils.cast(bool, '1')
|
|
|
|
t_bool_int = utils.cast(bool, 1)
|
|
|
|
t_float_int = utils.cast(float, 1)
|
|
|
|
t_float_float = utils.cast(float, 1)
|
|
|
|
t_float_str = utils.cast(float, 'kek')
|
|
|
|
assert t_int_int == 1 and isinstance(t_int_int, int)
|
|
|
|
assert t_int_str_int == 1 and isinstance(t_int_str_int, int)
|
|
|
|
assert t_bool_str_int is True
|
|
|
|
assert t_bool_int is True
|
|
|
|
assert t_float_float == 1.0 and isinstance(t_float_float, float)
|
|
|
|
assert t_float_str != t_float_str # nan is never equal
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
t_bool_str = utils.cast(bool, 'kek') # should we catch this in cast?
|
|
|
|
|
|
|
|
|
|
|
|
def test_utils_download(a_episode):
|
|
|
|
# this files is really getting downloaded..
|
2017-02-02 04:47:22 +00:00
|
|
|
without_session = utils.download(a_episode.getStreamURL(),
|
|
|
|
filename=a_episode.location, mocked=True)
|
2017-01-09 14:21:54 +00:00
|
|
|
assert without_session
|
|
|
|
with_session = utils.download(a_episode.getStreamURL(),
|
2017-02-02 04:47:22 +00:00
|
|
|
filename=a_episode.location, session=a_episode.server.session,
|
|
|
|
mocked=True)
|
2017-01-09 14:21:54 +00:00
|
|
|
assert with_session
|
|
|
|
img = utils.download(a_episode.thumbUrl, filename=a_episode.title, mocked=True)
|
|
|
|
assert img
|