mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-21 19:23:05 +00:00
Clean formatting
This commit is contained in:
parent
b648933963
commit
622c2490a0
12 changed files with 144 additions and 209 deletions
|
@ -1,11 +1,8 @@
|
|||
from functools import partial
|
||||
import os
|
||||
import betamax
|
||||
# -*- coding: utf-8 -*-
|
||||
import betamax, os, plexapi
|
||||
import pytest, requests
|
||||
from betamax_serializers import pretty_json
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
import plexapi
|
||||
from functools import partial
|
||||
|
||||
token = os.environ.get('PLEX_TOKEN')
|
||||
test_token = os.environ.get('PLEX_TEST_TOKEN')
|
||||
|
@ -16,25 +13,18 @@ test_password = os.environ.get('PLEX_TEST_PASSWORD')
|
|||
@pytest.fixture(scope='session')
|
||||
def pms(request):
|
||||
from plexapi.server import PlexServer
|
||||
|
||||
sess = requests.Session()
|
||||
|
||||
"""
|
||||
CASSETTE_LIBRARY_DIR = 'response/'
|
||||
|
||||
betamax.Betamax.register_serializer(pretty_json.PrettyJSONSerializer)
|
||||
config = betamax.Betamax.configure()
|
||||
config.define_cassette_placeholder('MASKED', token)
|
||||
config.define_cassette_placeholder('MASKED', test_token)
|
||||
|
||||
recorder = betamax.Betamax(sess, cassette_library_dir=CASSETTE_LIBRARY_DIR)
|
||||
recorder.use_cassette('http_responses', serialize_with='prettyjson') # record='new_episodes'
|
||||
recorder.start()
|
||||
"""
|
||||
# CASSETTE_LIBRARY_DIR = 'response/'
|
||||
# betamax.Betamax.register_serializer(pretty_json.PrettyJSONSerializer)
|
||||
# config = betamax.Betamax.configure()
|
||||
# config.define_cassette_placeholder('MASKED', token)
|
||||
# config.define_cassette_placeholder('MASKED', test_token)
|
||||
# recorder = betamax.Betamax(sess, cassette_library_dir=CASSETTE_LIBRARY_DIR)
|
||||
# recorder.use_cassette('http_responses', serialize_with='prettyjson') # record='new_episodes'
|
||||
# recorder.start()
|
||||
url = 'http://138.68.157.5:32400'
|
||||
assert test_token
|
||||
assert url
|
||||
|
||||
pms = PlexServer(url, test_token, session=sess)
|
||||
#request.addfinalizer(recorder.stop)
|
||||
return pms
|
||||
|
@ -43,13 +33,10 @@ def pms(request):
|
|||
@pytest.fixture()
|
||||
def freshpms():
|
||||
from plexapi.server import PlexServer
|
||||
|
||||
sess = requests.Session()
|
||||
|
||||
url = 'http://138.68.157.5:32400'
|
||||
assert test_token
|
||||
assert url
|
||||
|
||||
pms = PlexServer(url, test_token, session=sess)
|
||||
return pms
|
||||
|
||||
|
@ -83,7 +70,6 @@ def a_movie(pms):
|
|||
return m[0]
|
||||
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def a_tv_section(pms):
|
||||
sec = pms.library.section('TV Shows')
|
||||
|
@ -146,7 +132,6 @@ def a_episode(a_show):
|
|||
return ep
|
||||
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def a_photo_album(pms):
|
||||
sec = pms.library.section('Photos')
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
def test_mark_movie_watched(a_movie):
|
||||
a_movie.markUnwatched()
|
||||
print('Marking movie watched: %s' % a_movie)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
def test_audio_Artist_attr(a_artist):
|
||||
m = a_artist
|
||||
m.reload()
|
||||
|
@ -50,10 +49,6 @@ def test_audio_Artist_albums(a_artist):
|
|||
assert len(albums) == 1 and albums[0].title == 'Unmastered Impulses'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def test_audio_Album_attrs(a_music_album):
|
||||
m = a_music_album
|
||||
assert str(m.addedAt.date()) == '2017-01-17'
|
||||
|
@ -113,11 +108,9 @@ def test_audio_Album_tracks(a_music_album):
|
|||
assert tracks[0].viewOffset == 0
|
||||
|
||||
|
||||
|
||||
def test_audio_Album_track(a_music_album):
|
||||
# this is not reloaded. its not that much info missing.
|
||||
track = a_music_album.track('Holy Moment')
|
||||
|
||||
assert str(track.addedAt.date()) == '2017-01-17'
|
||||
assert track.duration == 298606
|
||||
assert track.grandparentKey == '/library/metadata/20'
|
||||
|
@ -176,12 +169,11 @@ def test_audio_Album_track(a_music_album):
|
|||
assert par0.size == 14360402
|
||||
|
||||
|
||||
|
||||
|
||||
def test_audio_Album_get():
|
||||
""" just a alias for track, lets skip it"""
|
||||
""" Just a alias for track(); skip it. """
|
||||
pass
|
||||
|
||||
|
||||
def test_audio_Album_artist(a_music_album):
|
||||
artist = a_music_album.artist()
|
||||
artist.title == 'Infinite State'
|
||||
|
@ -190,7 +182,6 @@ def test_audio_Album_artist(a_music_album):
|
|||
def test_audio_Track_attrs(a_music_album):
|
||||
track = a_music_album.get('Holy Moment')
|
||||
track.reload()
|
||||
|
||||
assert str(track.addedAt.date()) == '2017-01-17'
|
||||
assert str(track.art) == '__NA__'
|
||||
assert str(track.chapterSource) == '__NA__'
|
||||
|
@ -286,10 +277,10 @@ def test_audio_Track_attrs(a_music_album):
|
|||
assert str0.type == 2
|
||||
|
||||
|
||||
|
||||
def test_audio_Track_album(a_music_album):
|
||||
assert a_music_album.tracks()[0].album() == a_music_album
|
||||
|
||||
|
||||
def test_audio_Track_artist(a_music_album, a_artist):
|
||||
assert a_music_album.tracks()[0].artist() == a_artist
|
||||
|
||||
|
@ -298,7 +289,6 @@ def test_audio_Audio_section(a_artist, a_music_album, a_track):
|
|||
assert a_artist.section()
|
||||
assert a_music_album.section()
|
||||
assert a_track.section()
|
||||
|
||||
assert a_track.section() == a_music_album.section() == a_artist.section()
|
||||
|
||||
|
||||
|
@ -315,16 +305,3 @@ def test_audio_album_download(monkeydownload, a_music_album, tmpdir):
|
|||
def test_audio_Artist_download(monkeydownload, a_artist, tmpdir):
|
||||
f = a_artist.download(savepath=str(tmpdir))
|
||||
assert len(f) == 14
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,173 +1,217 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient__loadData(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_connect(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_contextMenu(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_goBack(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_goToHome(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_goToMedia(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_goToMusic(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_headers(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_isPlayingMedia(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_moveDown(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_moveLeft(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_moveRight(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_moveUp(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_nextLetter(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_pageDown(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_pageUp(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_pause(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_play(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_playMedia(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_previousLetter(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_proxyThroughServer(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_query(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_refreshPlayQueue(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_seekTo(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_select(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_sendCommand(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_setAudioStream(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_setParameters(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_setRepeat(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_setShuffle(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_setStreams(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_setSubtitleStream(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_setVideoStream(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_setVolume(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_skipNext(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_skipPrevious(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_skipTo(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_stepBack(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_stepForward(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_stop(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_timeline(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_toggleOSD(pms):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def _test_client_PlexClient_url(pms):
|
||||
pass
|
||||
|
|
|
@ -1,20 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
|
||||
from plexapi.exceptions import NotFound
|
||||
|
||||
# func naming should follow:
|
||||
# tests_file_class_method_some_description
|
||||
|
||||
|
||||
def test_library_Library_section(pms):
|
||||
sections = pms.library.sections()
|
||||
assert len(sections) == 4
|
||||
|
||||
lfs = 'TV Shows'
|
||||
section_name = pms.library.section(lfs)
|
||||
assert section_name.title == lfs
|
||||
|
||||
with pytest.raises(NotFound):
|
||||
assert pms.library.section('gfdsas')
|
||||
|
||||
|
@ -23,11 +17,9 @@ def test_library_Library_sectionByID_is_equal_section(pms, freshpms):
|
|||
# test that sctionmyID refreshes the section if the key is missing
|
||||
# this is needed if there isnt any cached sections
|
||||
assert freshpms.library.sectionByID('1')
|
||||
|
||||
assert pms.library.sectionByID('1').uuid == pms.library.section('Movies').uuid
|
||||
|
||||
|
||||
|
||||
def test_library_sectionByID_with_attrs(pms):
|
||||
m = pms.library.sectionByID('1')
|
||||
assert m.agent == 'com.plexapp.agents.imdb'
|
||||
|
@ -72,6 +64,7 @@ def test_library_get(pms):
|
|||
m = pms.library.get('16 blocks')
|
||||
assert m.title == '16 Blocks'
|
||||
|
||||
|
||||
def test_library_Library_cleanBundle(pms):
|
||||
pms.library.cleanBundles()
|
||||
|
||||
|
@ -79,9 +72,11 @@ def test_library_Library_cleanBundle(pms):
|
|||
def test_library_Library_optimize(pms):
|
||||
pms.library.optimize()
|
||||
|
||||
|
||||
def test_library_Library_emptyTrash(pms):
|
||||
pms.library.emptyTrash()
|
||||
|
||||
|
||||
def _test_library_Library_refresh(pms):
|
||||
pms.library.refresh() # fix mangle and proof the sections attrs
|
||||
|
||||
|
@ -134,18 +129,11 @@ def test_library_PhotoSection_searchAlbums(a_photo_section):
|
|||
print([i.TYPE for i in albums])
|
||||
|
||||
|
||||
|
||||
def test_library_PhotoSection_searchPhotos(a_photo_section):
|
||||
assert len(a_photo_section.searchPhotos('lolcat2'))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#### Start on library search
|
||||
|
||||
# Start on library search
|
||||
def test_library_and_section_search_for_movie(pms):
|
||||
find = '16 blocks'
|
||||
l_search = pms.library.search(find)
|
||||
|
@ -157,7 +145,6 @@ def test_search_with_apostrophe(pms):
|
|||
show_title = "Marvel's Daredevil" # Test ' in show title
|
||||
result_server = pms.search(show_title)
|
||||
result_shows = pms.library.section('TV Shows').search(show_title)
|
||||
|
||||
assert result_server
|
||||
assert result_shows
|
||||
assert result_server == result_shows
|
||||
|
@ -166,7 +153,6 @@ def test_search_with_apostrophe(pms):
|
|||
def test_crazy_search(pms, a_movie):
|
||||
movie = a_movie
|
||||
movies = pms.library.section('Movies')
|
||||
|
||||
assert movie in pms.library.search(genre=29, libtype='movie')
|
||||
assert movie in movies.search(actor=movie.actors[0], sort='titleSort'), 'Unable to search movie by actor.'
|
||||
assert movie in movies.search(director=movie.directors[0]), 'Unable to search movie by director.'
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
|
||||
|
||||
def test_myplex_accounts(plex_account, pms):
|
||||
account = plex_account
|
||||
assert account, 'Must specify username, password & resource to run this test.'
|
||||
print('MyPlexAccount:')
|
||||
print('username: %s' % account.username)
|
||||
#print('authenticationToken: %s' % account.authenticationToken)
|
||||
print('email: %s' % account.email)
|
||||
print('home: %s' % account.home)
|
||||
print('queueEmail: %s' % account.queueEmail)
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def test_navigate_around_show(plex_account, pms):
|
||||
show = pms.library.section('TV Shows').get('The 100')
|
||||
seasons = show.seasons()
|
||||
season = show.season('Season 1')
|
||||
|
||||
episodes = show.episodes()
|
||||
episode = show.episode('Pilot')
|
||||
|
||||
assert 'Season 1' in [s.title for s in seasons], 'Unable to list season:'
|
||||
assert 'Pilot' in [e.title for e in episodes], 'Unable to list episode:'
|
||||
assert show.season(1) == season
|
||||
|
@ -21,22 +16,22 @@ def test_navigate_around_show(plex_account, pms):
|
|||
assert episode.season() == season, 'episode.season() doesnt match expected season.'
|
||||
|
||||
|
||||
def _test_navigate_around_artist(plex_account, pms):
|
||||
artist = pms.library.section(CONFIG.audio_section).get(CONFIG.audio_artist)
|
||||
def test_navigate_around_artist(plex_account, pms):
|
||||
artist = pms.library.section('Music').get('Infinite State')
|
||||
albums = artist.albums()
|
||||
album = artist.album(CONFIG.audio_album)
|
||||
album = artist.album('Unmastered Impulses')
|
||||
tracks = artist.tracks()
|
||||
track = artist.track(CONFIG.audio_track)
|
||||
track = artist.track('Mantra')
|
||||
print('Navigating around artist: %s' % artist)
|
||||
print('Albums: %s...' % albums[:3])
|
||||
print('Album: %s' % album)
|
||||
print('Tracks: %s...' % tracks[:3])
|
||||
print('Track: %s' % track)
|
||||
assert CONFIG.audio_album in [a.title for a in albums], 'Unable to list album: %s' % CONFIG.audio_album
|
||||
assert CONFIG.audio_track in [e.title for e in tracks], 'Unable to list track: %s' % CONFIG.audio_track
|
||||
assert artist.album(CONFIG.audio_album) == album, 'Unable to get artist album: %s' % CONFIG.audio_album
|
||||
assert artist.track(CONFIG.audio_track) == track, 'Unable to get artist track: %s' % CONFIG.audio_track
|
||||
assert album.track(CONFIG.audio_track) == track, 'Unable to get album track: %s' % CONFIG.audio_track
|
||||
assert 'Unmastered Impulses' in [a.title for a in albums], 'Unable to list album.'
|
||||
assert 'Mantra' in [e.title for e in tracks], 'Unable to list track.'
|
||||
assert artist.album('Unmastered Impulses') == album, 'Unable to get artist album.'
|
||||
assert artist.track('Mantra') == track, 'Unable to get artist track.'
|
||||
assert album.track('Mantra') == track, 'Unable to get album track.'
|
||||
assert album.artist() == artist, 'album.artist() doesnt match expected artist.'
|
||||
assert track.artist() == artist, 'track.artist() doesnt match expected artist.'
|
||||
assert track.album() == album, 'track.album() doesnt match expected album.'
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
import pytest
|
||||
|
||||
|
||||
|
||||
import pytest, time
|
||||
|
||||
|
||||
def test_create_playlist(pms, a_show):
|
||||
|
@ -68,13 +64,10 @@ def test_playlist_play(pms):
|
|||
pl_name = 'test_play_playlist'
|
||||
playlist = plex.createPlaylist(pl_name, album)
|
||||
try:
|
||||
#print('Playing playlist: %s' % playlist)
|
||||
client.playMedia(playlist); time.sleep(5)
|
||||
#print('stop..')
|
||||
client.stop('music'); time.sleep(1)
|
||||
finally:
|
||||
playlist.delete()
|
||||
|
||||
assert pl_name not in [i.title for i in pms.playlists()]
|
||||
|
||||
|
||||
|
@ -83,12 +76,10 @@ def test_playlist_photos(pms, a_photo_album):
|
|||
photos = album.photos()
|
||||
pl_name = 'test_playlist_photos'
|
||||
playlist = pms.createPlaylist(pl_name, photos)
|
||||
|
||||
try:
|
||||
assert len(playlist.items()) == 4
|
||||
finally:
|
||||
playlist.delete()
|
||||
|
||||
assert pl_name not in [i.title for i in pms.playlists()]
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
# test search.
|
||||
|
||||
# Many more tests is for search later.
|
||||
# -*- coding: utf-8 -*-
|
||||
# TODO: Many more tests is for search later.
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import pytest
|
||||
import os
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
import os, pytest
|
||||
from plexapi.exceptions import BadRequest, NotFound
|
||||
from plexapi.utils import download
|
||||
|
||||
|
@ -38,28 +37,23 @@ def test_server_url(pms):
|
|||
|
||||
def test_server_transcodeImage(tmpdir, pms, a_show):
|
||||
# Ideally we should also test the black white but this has to do for now.
|
||||
height = 500
|
||||
width = 500
|
||||
from PIL import Image
|
||||
width, height = 500, 500
|
||||
img_url_resize = pms.transcodeImage(a_show.banner, height, width)
|
||||
gray = img_url_resize = pms.transcodeImage(a_show.banner, height, width, saturation=0)
|
||||
|
||||
resized_image = download(img_url_resize, savepath=str(tmpdir), filename='resize_image')
|
||||
org_image = download(a_show.server.url(a_show.banner), savepath=str(tmpdir), filename='org_image')
|
||||
gray_image = download(gray, savepath=str(tmpdir), filename='gray_image')
|
||||
|
||||
|
||||
from PIL import Image, ImageStat
|
||||
|
||||
with Image.open(resized_image) as im:
|
||||
assert width, height == im.size
|
||||
|
||||
with Image.open(org_image) as im:
|
||||
assert width, height != im.size
|
||||
assert _detect_color_image(gray_image, thumb_size=150) == 'grayscale'
|
||||
|
||||
|
||||
|
||||
def detect_color_image(file, thumb_size=150, MSE_cutoff=22, adjust_color_bias=True):
|
||||
#from http://stackoverflow.com/questions/20068945/detect-if-image-is-color-grayscale-or-black-and-white-with-python-pil
|
||||
def _detect_color_image(file, thumb_size=150, MSE_cutoff=22, adjust_color_bias=True):
|
||||
# from http://stackoverflow.com/questions/20068945/detect-if-image-is-color-grayscale-or-black-and-white-with-python-pil
|
||||
from PIL import Image, ImageStat
|
||||
pil_img = Image.open(file)
|
||||
bands = pil_img.getbands()
|
||||
if bands == ('R', 'G', 'B') or bands == ('R', 'G', 'B', 'A'):
|
||||
|
@ -79,21 +73,16 @@ def test_server_transcodeImage(tmpdir, pms, a_show):
|
|||
elif len(bands) == 1:
|
||||
return 'blackandwhite'
|
||||
|
||||
assert detect_color_image(gray_image, thumb_size=150) == 'grayscale'
|
||||
|
||||
|
||||
|
||||
def test_server_search(pms):
|
||||
# basic search. see test_search.py
|
||||
assert pms.search('16 Blocks')
|
||||
|
||||
assert pms.search('16 blocks', mediatype='movie')
|
||||
|
||||
|
||||
def test_server_playlist(pms):
|
||||
pl = pms.playlist('some_playlist')
|
||||
assert pl.title == 'some_playlist'
|
||||
|
||||
with pytest.raises(NotFound):
|
||||
pms.playlist('124xxx11y')
|
||||
|
||||
|
@ -110,19 +99,15 @@ def test_server_history(pms):
|
|||
|
||||
def test_server_Server_query(pms):
|
||||
assert pms.query('/')
|
||||
|
||||
from plexapi.server import PlexServer
|
||||
|
||||
with pytest.raises(BadRequest):
|
||||
assert pms.query('/asdasdsada/12123127/aaaa', headers={'random_headers': '1337'})
|
||||
|
||||
with pytest.raises(NotFound):
|
||||
# This is really requests.exceptions.HTTPError:
|
||||
# 401 Client Error: Unauthorized for url:
|
||||
PlexServer('http://138.68.157.5:32400', '1234')
|
||||
|
||||
|
||||
|
||||
def test_server_Server_session():
|
||||
from requests import Session
|
||||
from plexapi.server import PlexServer
|
||||
|
@ -133,17 +118,12 @@ def test_server_Server_session():
|
|||
self.plexapi_session_test = True
|
||||
|
||||
plex = PlexServer('http://138.68.157.5:32400',
|
||||
os.environ.get('PLEX_TEST_TOKEN'),
|
||||
session=MySession())
|
||||
|
||||
os.environ.get('PLEX_TEST_TOKEN'), session=MySession())
|
||||
assert hasattr(plex.session, 'plexapi_session_test')
|
||||
|
||||
pl = plex.playlists()
|
||||
assert hasattr(pl[0].server.session, 'plexapi_session_test')
|
||||
|
||||
# check client
|
||||
# check myplex.
|
||||
|
||||
# TODO: Check client in test_server_Server_session.
|
||||
# TODO: Check myplex in test_server_Server_session.
|
||||
|
||||
|
||||
def test_server_token_in_headers(pms):
|
||||
|
@ -155,6 +135,7 @@ def _test_server_createPlayQueue():
|
|||
# see test_playlists.py
|
||||
pass
|
||||
|
||||
|
||||
def _test_server_createPlaylist():
|
||||
# see test_playlists.py
|
||||
pass
|
||||
|
@ -162,13 +143,14 @@ def _test_server_createPlaylist():
|
|||
|
||||
def test_server_client_not_found(pms):
|
||||
with pytest.raises(NotFound):
|
||||
pms.client('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
||||
pms.client('<This-client-should-not-be-found>')
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def test_server_client(pms):
|
||||
assert pms.client('Plex Web (Chrome)')
|
||||
|
||||
|
||||
def test_server_Server_sessions(pms):
|
||||
assert len(pms.sessions()) == 0
|
||||
|
||||
|
@ -189,7 +171,6 @@ def test_server_clients(pms):
|
|||
assert m.protocolCapabilities == ['timeline', 'playback', 'navigation', 'mirror', 'playqueues']
|
||||
assert m.protocolVersion == '1'
|
||||
assert m.server.baseurl == 'http://138.68.157.5:32400'
|
||||
#assert m.session == <requests.sessions.Session object at 0x02945E10>
|
||||
assert m.state is None
|
||||
assert m.title == 'Plex Web (Chrome)'
|
||||
assert m.token is None
|
||||
|
@ -200,7 +181,8 @@ def test_server_clients(pms):
|
|||
def test_server_account(pms):
|
||||
acc = pms.account()
|
||||
assert acc.authToken
|
||||
#assert acc.mappingError == 'publisherror' # this is missing from time to time.. why?
|
||||
# TODO: Figure out why this is missing from time to time.
|
||||
#assert acc.mappingError == 'publisherror'
|
||||
assert acc.mappingErrorMessage is None
|
||||
assert acc.mappingState == 'mapped'
|
||||
assert acc.privateAddress == '138.68.157.5'
|
||||
|
@ -212,5 +194,3 @@ def test_server_account(pms):
|
|||
assert acc.subscriptionFeatures is None
|
||||
assert acc.subscriptionState == 'Unknown'
|
||||
assert acc.username == 'testplexapi@gmail.com'
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
|
||||
|
||||
import plexapi.utils as utils
|
||||
from plexapi.exceptions import NotFound
|
||||
|
||||
|
@ -10,24 +9,28 @@ def test_utils_toDatetime():
|
|||
assert str(utils.toDatetime('0'))[:-9] == '1970-01-01'
|
||||
# should this handle args as '0' # no need element attrs are strings.
|
||||
|
||||
|
||||
def _test_utils_threaded():
|
||||
# TODO: Implement test_utils_threaded
|
||||
pass
|
||||
|
||||
|
||||
def test_utils_searchType():
|
||||
st = utils.searchType('movie')
|
||||
assert st == 1
|
||||
|
||||
movie = utils.searchType(1)
|
||||
assert movie == '1'
|
||||
|
||||
with pytest.raises(NotFound):
|
||||
utils.searchType('kekekekeke')
|
||||
|
||||
|
||||
def _test_utils_listItems():
|
||||
# TODO: Implement test_utils_listItems
|
||||
pass
|
||||
|
||||
|
||||
def _test_utils_listChoices(pms):
|
||||
# TODO: Implement test_utils_listChoices
|
||||
pass
|
||||
|
||||
|
||||
|
@ -41,27 +44,35 @@ def test_utils_isInt():
|
|||
assert utils.isInt('got_you') is False
|
||||
assert utils.isInt('1337') is True
|
||||
|
||||
|
||||
def _test_utils_findUsername():
|
||||
# TODO: Implement test_utils_findUsername
|
||||
pass
|
||||
|
||||
|
||||
def _test_utils_findStreams():
|
||||
# TODO: Implement test_utils_findStreams
|
||||
pass
|
||||
|
||||
|
||||
def _test_utils_findPlayer():
|
||||
# TODO: Implement test_utils_findPlayer
|
||||
pass
|
||||
|
||||
|
||||
def _test_utils_findLocations():
|
||||
# TODO: Implement test_utils_findLocations
|
||||
pass
|
||||
|
||||
|
||||
def _test_utils_findItem():
|
||||
# TODO: Implement test_utils_findItem
|
||||
pass
|
||||
|
||||
|
||||
def test_utils_findKey(pms):
|
||||
with pytest.raises(NotFound):
|
||||
assert utils.findKey(pms, '9999999')
|
||||
|
||||
assert utils.findKey(pms, '1')
|
||||
|
||||
|
||||
|
@ -79,22 +90,18 @@ def test_utils_cast():
|
|||
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..
|
||||
without_session = utils.download(a_episode.getStreamURL(), filename=a_episode.location, mocked=True)
|
||||
without_session = utils.download(a_episode.getStreamURL(),
|
||||
filename=a_episode.location, mocked=True)
|
||||
assert without_session
|
||||
|
||||
with_session = utils.download(a_episode.getStreamURL(),
|
||||
filename=a_episode.location,
|
||||
session=a_episode.server.session,
|
||||
filename=a_episode.location, session=a_episode.server.session,
|
||||
mocked=True)
|
||||
assert with_session
|
||||
|
||||
img = utils.download(a_episode.thumbUrl, filename=a_episode.title, mocked=True)
|
||||
assert img
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#test_the_file_class_method
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
import os, pytest
|
||||
from plexapi.exceptions import NotFound
|
||||
|
||||
|
||||
|
@ -12,21 +7,21 @@ def test_video_Movie(a_movie_section):
|
|||
m = a_movie_section.get('Cars')
|
||||
assert m.title == 'Cars'
|
||||
|
||||
|
||||
def test_video_Movie_getStreamURL(a_movie):
|
||||
assert a_movie.getStreamURL() == "http://138.68.157.5:32400/video/:/transcode/universal/start.m3u8?X-Plex-Platform=Chrome©ts=1&mediaIndex=0&offset=0&path=%2Flibrary%2Fmetadata%2F1&X-Plex-Token={0}".format(os.environ.get('PLEX_TEST_TOKEN'))
|
||||
assert a_movie.getStreamURL(videoResolution='800x600') == "http://138.68.157.5:32400/video/:/transcode/universal/start.m3u8?X-Plex-Platform=Chrome©ts=1&mediaIndex=0&offset=0&path=%2Flibrary%2Fmetadata%2F1&videoResolution=800x600&X-Plex-Token={0}".format(os.environ.get('PLEX_TEST_TOKEN'))
|
||||
|
||||
|
||||
def test_video_Movie_isFullObject_and_reload(pms):
|
||||
movie = pms.library.section('Movies').get('16 Blocks')
|
||||
assert movie.isFullObject() is False
|
||||
movie.reload()
|
||||
assert movie.isFullObject() is True
|
||||
|
||||
movie_via_search = pms.library.search('16 Blocks')[0]
|
||||
assert movie_via_search.isFullObject() is False
|
||||
movie_via_search.reload()
|
||||
assert movie_via_search.isFullObject() is True
|
||||
|
||||
movie_via_section_search = pms.library.section('Movies').search('16 Blocks')[0]
|
||||
assert movie_via_section_search.isFullObject() is False
|
||||
movie_via_section_search.reload()
|
||||
|
@ -42,19 +37,16 @@ def test_video_Movie_isPartialObject(a_movie):
|
|||
def test_video_Movie_iterParts(a_movie):
|
||||
assert len(list(a_movie.iterParts())) == 1
|
||||
|
||||
|
||||
def test_video_Movie_download(monkeydownload, tmpdir, a_movie):
|
||||
downloaded_movie = a_movie.download(savepath=str(tmpdir))
|
||||
assert len(downloaded_movie) == 1
|
||||
|
||||
downloaded_movie2 = a_movie.download(savepath=str(tmpdir), **{'videoResolution': '500x300'})
|
||||
assert len(downloaded_movie2) == 1
|
||||
|
||||
|
||||
|
||||
|
||||
def test_video_Movie_attrs_as_much_as_possible(a_movie_section):
|
||||
m = a_movie_section.get('Cars')
|
||||
|
||||
assert m.location == '/media/movies/cars/cars.mp4'
|
||||
assert str(m.addedAt.date()) == '2017-01-17'
|
||||
assert m.art == '/library/metadata/2/art/1484690715'
|
||||
|
@ -239,7 +231,6 @@ def test_video_Movie_attrs_as_much_as_possible(a_movie_section):
|
|||
assert str1.type == 2
|
||||
|
||||
|
||||
|
||||
def test_video_Show(a_show):
|
||||
assert a_show.title == 'The 100'
|
||||
|
||||
|
@ -286,9 +277,11 @@ def test_video_Show_watched(a_show):
|
|||
watched = a_show.watched()
|
||||
assert len(watched) == 1 and watched[0].title == 'Pilot'
|
||||
|
||||
|
||||
def test_video_Show_unwatched(a_show):
|
||||
assert len(a_show.unwatched()) == 8
|
||||
|
||||
|
||||
def test_video_Show_location(pms):
|
||||
# This should be a part of test test_video_Show_attrs
|
||||
# But is excluded because of https://github.com/mjs7231/python-plexapi/issues/97
|
||||
|
@ -305,13 +298,13 @@ def test_video_Show_reload(pms):
|
|||
assert len(s.roles) > 3
|
||||
|
||||
|
||||
|
||||
def test_video_Show_episodes(a_show):
|
||||
inc_watched = a_show.episodes()
|
||||
ex_watched = a_show.episodes(watched=False)
|
||||
assert len(inc_watched) == 9
|
||||
assert len(ex_watched) == 8
|
||||
|
||||
|
||||
def test_video_Show_download(monkeydownload, tmpdir, a_show):
|
||||
f = a_show.download(savepath=str(tmpdir))
|
||||
assert len(f) == 9
|
||||
|
@ -319,27 +312,26 @@ def test_video_Show_download(monkeydownload, tmpdir, a_show):
|
|||
|
||||
def test_video_Season_download(monkeydownload, tmpdir, a_show):
|
||||
sn = a_show.season('Season 1')
|
||||
|
||||
f = sn.download(savepath=str(tmpdir))
|
||||
assert len(f) == 8
|
||||
|
||||
|
||||
def test_video_Episode_download(monkeydownload, tmpdir, a_episode):
|
||||
f = a_episode.download(savepath=str(tmpdir))
|
||||
assert len(f) == 1
|
||||
|
||||
with_sceen_size = a_episode.download(savepath=str(tmpdir), **{'videoResolution': '500x300'})
|
||||
assert len(with_sceen_size) == 1
|
||||
|
||||
|
||||
|
||||
|
||||
def test_video_Show_thumbUrl(a_show):
|
||||
assert 'http://138.68.157.5:32400/library/metadata/12/thumb/' in a_show.thumbUrl
|
||||
|
||||
|
||||
@pytest.mark.xfail
|
||||
def test_video_Show_analyze(a_show):
|
||||
show = a_show.analyze() # this isnt possble.. should it even be available?
|
||||
|
||||
|
||||
def test_video_Show_markWatched(a_tv_section):
|
||||
show = a_tv_section.get("Marvel's Daredevil")
|
||||
show.markWatched()
|
||||
|
@ -373,13 +365,12 @@ def test_video_Show_section(a_show): # BROKEN!
|
|||
def test_video_Episode(a_show):
|
||||
pilot = a_show.episode('Pilot')
|
||||
assert pilot == a_show.episode(season=1, episode=1)
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
a_show.episode()
|
||||
|
||||
with pytest.raises(NotFound):
|
||||
a_show.episode(season=1337, episode=1337)
|
||||
|
||||
|
||||
def test_video_Episode_analyze(a_tv_section):
|
||||
ep = a_tv_section.get("Marvel's Daredevil").episode(season=1, episode=1)
|
||||
ep.analyze()
|
||||
|
@ -520,52 +511,33 @@ def test_video_Season_episodes(a_show):
|
|||
assert len(sn_eps) == 1
|
||||
|
||||
|
||||
|
||||
#### MISC
|
||||
def test_that_reload_return_the_same_object(pms):
|
||||
# we want to check this that all the urls are correct
|
||||
movie_library_search = pms.library.section('Movies').search('16 Blocks')[0]
|
||||
movie_search = pms.search('16 Blocks')[0]
|
||||
movie_section_get = pms.library.section('Movies').get('16 Blocks')
|
||||
|
||||
movie_library_search_key = movie_library_search.key
|
||||
movie_search_key = movie_search.key
|
||||
movie_section_get_key = movie_section_get.key
|
||||
|
||||
assert movie_library_search_key == movie_library_search.reload().key == movie_search_key == movie_search.reload().key == movie_section_get_key == movie_section_get.reload().key
|
||||
|
||||
tvshow_library_search = pms.library.section('TV Shows').search('The 100')[0]
|
||||
tvshow_search = pms.search('The 100')[0]
|
||||
tvshow_section_get = pms.library.section('TV Shows').get('The 100')
|
||||
|
||||
tvshow_library_search_key = tvshow_library_search.key
|
||||
tvshow_search_key = tvshow_search.key
|
||||
tvshow_section_get_key = tvshow_section_get.key
|
||||
|
||||
assert tvshow_library_search_key == tvshow_library_search.reload().key == tvshow_search_key == tvshow_search.reload().key == tvshow_section_get_key == tvshow_section_get.reload().key
|
||||
|
||||
season_library_search = tvshow_library_search.season(1)
|
||||
season_search = tvshow_search.season(1)
|
||||
season_section_get = tvshow_section_get.season(1)
|
||||
|
||||
season_library_search_key = season_library_search.key
|
||||
season_search_key = season_search.key
|
||||
season_section_get_key = season_section_get.key
|
||||
|
||||
assert season_library_search_key == season_library_search.reload().key == season_search_key == season_search.reload().key == season_section_get_key == season_section_get.reload().key
|
||||
|
||||
episode_library_search = tvshow_library_search.episode(season=1, episode=1)
|
||||
episode_search = tvshow_search.episode(season=1, episode=1)
|
||||
episode_section_get = tvshow_section_get.episode(season=1, episode=1)
|
||||
|
||||
episode_library_search_key = episode_library_search.key
|
||||
episode_search_key = episode_search.key
|
||||
episode_section_get_key = episode_section_get.key
|
||||
|
||||
assert episode_library_search_key == episode_library_search.reload().key == episode_search_key == episode_search.reload().key == episode_section_get_key == episode_section_get.reload().key
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue