python-plexapi/tests/test_playlist.py

121 lines
4.6 KiB
Python
Raw Normal View History

2017-01-09 14:21:54 +00:00
# -*- coding: utf-8 -*-
2017-10-25 19:53:52 +00:00
import time
2020-04-29 21:23:22 +00:00
2017-10-25 19:53:52 +00:00
import pytest
2020-12-24 17:21:29 +00:00
from plexapi.exceptions import NotFound
2017-01-09 14:21:54 +00:00
2017-04-16 15:58:21 +00:00
def test_create_playlist(plex, show):
2017-01-09 14:21:54 +00:00
# create the playlist
2017-04-16 15:58:21 +00:00
title = 'test_create_playlist_show'
2017-01-09 14:21:54 +00:00
#print('Creating playlist %s..' % title)
2017-04-16 15:58:21 +00:00
episodes = show.episodes()
playlist = plex.createPlaylist(title, episodes[:3])
2017-01-09 14:21:54 +00:00
try:
items = playlist.items()
2017-04-16 15:58:21 +00:00
# Test create playlist
2017-01-09 14:21:54 +00:00
assert playlist.title == title, 'Playlist not created successfully.'
assert len(items) == 3, 'Playlist does not contain 3 items.'
assert items[0].ratingKey == episodes[0].ratingKey, 'Items not in proper order [0a].'
assert items[1].ratingKey == episodes[1].ratingKey, 'Items not in proper order [1a].'
assert items[2].ratingKey == episodes[2].ratingKey, 'Items not in proper order [2a].'
2017-04-16 15:58:21 +00:00
# Test move items around (b)
2017-01-09 14:21:54 +00:00
playlist.moveItem(items[1])
items = playlist.items()
assert items[0].ratingKey == episodes[1].ratingKey, 'Items not in proper order [0b].'
assert items[1].ratingKey == episodes[0].ratingKey, 'Items not in proper order [1b].'
assert items[2].ratingKey == episodes[2].ratingKey, 'Items not in proper order [2b].'
2017-04-16 15:58:21 +00:00
# Test move items around (c)
2017-01-09 14:21:54 +00:00
playlist.moveItem(items[0], items[1])
items = playlist.items()
assert items[0].ratingKey == episodes[0].ratingKey, 'Items not in proper order [0c].'
assert items[1].ratingKey == episodes[1].ratingKey, 'Items not in proper order [1c].'
assert items[2].ratingKey == episodes[2].ratingKey, 'Items not in proper order [2c].'
2017-04-16 15:58:21 +00:00
# Test add item
2017-01-09 14:21:54 +00:00
playlist.addItems(episodes[3])
items = playlist.items()
assert items[3].ratingKey == episodes[3].ratingKey, 'Missing added item: %s' % episodes[3]
2017-04-16 15:58:21 +00:00
# Test add two items
2017-01-09 14:21:54 +00:00
playlist.addItems(episodes[4:6])
items = playlist.items()
assert items[4].ratingKey == episodes[4].ratingKey, 'Missing added item: %s' % episodes[4]
assert items[5].ratingKey == episodes[5].ratingKey, 'Missing added item: %s' % episodes[5]
assert len(items) == 6, 'Playlist should have 6 items, %s found' % len(items)
2017-04-16 15:58:21 +00:00
# Test remove item
2017-01-09 14:21:54 +00:00
toremove = items[3]
playlist.removeItem(toremove)
items = playlist.items()
assert toremove not in items, 'Removed item still in playlist: %s' % items[3]
assert len(items) == 5, 'Playlist should have 5 items, %s found' % len(items)
finally:
playlist.delete()
2020-12-24 07:03:08 +00:00
def test_playlist_item(plex, show):
2020-12-24 17:21:29 +00:00
title = 'test_playlist_item'
2020-12-24 07:03:08 +00:00
episodes = show.episodes()
try:
playlist = plex.createPlaylist(title, episodes[:3])
item1 = playlist.item("Winter Is Coming")
assert item1 in playlist.items()
item2 = playlist.get("Winter Is Coming")
assert item2 in playlist.items()
assert item1 == item2
2020-12-24 17:21:29 +00:00
with pytest.raises(NotFound):
playlist.item("Does not exist")
2020-12-24 07:03:08 +00:00
finally:
playlist.delete()
2017-04-29 05:47:21 +00:00
@pytest.mark.client
def test_playlist_play(plex, client, artist, album):
2017-01-09 14:21:54 +00:00
try:
2017-04-16 15:58:21 +00:00
playlist_name = 'test_play_playlist'
playlist = plex.createPlaylist(playlist_name, album)
2017-01-09 14:21:54 +00:00
client.playMedia(playlist); time.sleep(5)
client.stop('music'); time.sleep(1)
finally:
playlist.delete()
2017-04-16 15:58:21 +00:00
assert playlist_name not in [i.title for i in plex.playlists()]
2017-01-09 14:21:54 +00:00
2017-04-16 15:58:21 +00:00
def test_playlist_photos(plex, photoalbum):
album = photoalbum
2017-01-09 14:21:54 +00:00
photos = album.photos()
try:
2017-04-16 15:58:21 +00:00
playlist_name = 'test_playlist_photos'
playlist = plex.createPlaylist(playlist_name, photos)
assert len(playlist.items()) >= 1
2017-01-09 14:21:54 +00:00
finally:
playlist.delete()
2017-04-16 15:58:21 +00:00
assert playlist_name not in [i.title for i in plex.playlists()]
2017-01-09 14:21:54 +00:00
2017-04-29 05:47:21 +00:00
@pytest.mark.client
def test_play_photos(plex, client, photoalbum):
photos = photoalbum.photos()
2017-01-09 14:21:54 +00:00
for photo in photos[:4]:
client.playMedia(photo)
time.sleep(2)
Improvements in tests process (#297) * lets begin * skip plexpass tests if there is not plexpass on account * test new myplex attrubutes * bootstrap: proper photos organisation * fix rest of photos tests * fix myplex new attributes test * fix music bootstrap by setting agent to lastfm * fix sync tests * increase bootstrap timeout * remove timeout from .travis.yml * do not create playlist-style photoalbums in plex-bootstraptest.py * allow negative filtering in LibrarySection.search() * fix sync tests once again * use sendCrashReports in test_settings * fix test_settings * fix test_video * do not accept eula in bootstrap * fix PlexServer.isLatest() * add test against old version of PlexServer * fix MyPlexAccount.OutOut * add flag for one-time testing in Travis * fix test_library onDeck tests * fix more tests * use tqdm in plex-bootstraptest for media scanning progress * create sections one-by-one * update docs on AlertListener for timeline entries * fix plex-bootstraptest for server version 1.3.2 * display skip/xpass/xfail reasons * fix tests on 1.3 * wait for music to be fully processed in plex-bootstraptest * fix misplaced TEST_ACCOUNT_ONCE * fix test_myplex_users, not sure if in proper-way * add pytest-rerunfailures; mark test_myplex_optout as flaky * fix comment * Revert "add pytest-rerunfailures; mark test_myplex_optout as flaky" This reverts commit 580e4c95a758c92329d757eb2f3fc3bf44b26f09. * restart plex container on failure * add conftest.wait_until() and used where some retries are required * add more wait_until() usage in test_sync * fix managed user search * fix updating managed users in myplex * allow to add new servers to existent users * add new server to a shared user while bootstrapping * add some docs on testing process * perform few attemps when unable to get the claim token * unlock websocket-client in requirements_dev * fix docblock in tools/plex-teardowntest * do not hardcode mediapart size in test_video * remove cache:pip from travis * Revert "unlock websocket-client in requirements_dev" This reverts commit 0d536bd06dbdc4a4b869a1686f8cd008898859fe. * remove debug from server.py * improve webhook tests * fix type() check to isinstance() * remove excessive `else` branch due to Hellowlol advice * add `unknown` as allowed `myPlexMappingState` in test_server
2018-09-14 18:03:23 +00:00
def test_copyToUser(plex, show, fresh_plex, shared_username):
2017-07-17 14:11:03 +00:00
episodes = show.episodes()
playlist = plex.createPlaylist('shared_from_test_plexapi', episodes)
try:
Improvements in tests process (#297) * lets begin * skip plexpass tests if there is not plexpass on account * test new myplex attrubutes * bootstrap: proper photos organisation * fix rest of photos tests * fix myplex new attributes test * fix music bootstrap by setting agent to lastfm * fix sync tests * increase bootstrap timeout * remove timeout from .travis.yml * do not create playlist-style photoalbums in plex-bootstraptest.py * allow negative filtering in LibrarySection.search() * fix sync tests once again * use sendCrashReports in test_settings * fix test_settings * fix test_video * do not accept eula in bootstrap * fix PlexServer.isLatest() * add test against old version of PlexServer * fix MyPlexAccount.OutOut * add flag for one-time testing in Travis * fix test_library onDeck tests * fix more tests * use tqdm in plex-bootstraptest for media scanning progress * create sections one-by-one * update docs on AlertListener for timeline entries * fix plex-bootstraptest for server version 1.3.2 * display skip/xpass/xfail reasons * fix tests on 1.3 * wait for music to be fully processed in plex-bootstraptest * fix misplaced TEST_ACCOUNT_ONCE * fix test_myplex_users, not sure if in proper-way * add pytest-rerunfailures; mark test_myplex_optout as flaky * fix comment * Revert "add pytest-rerunfailures; mark test_myplex_optout as flaky" This reverts commit 580e4c95a758c92329d757eb2f3fc3bf44b26f09. * restart plex container on failure * add conftest.wait_until() and used where some retries are required * add more wait_until() usage in test_sync * fix managed user search * fix updating managed users in myplex * allow to add new servers to existent users * add new server to a shared user while bootstrapping * add some docs on testing process * perform few attemps when unable to get the claim token * unlock websocket-client in requirements_dev * fix docblock in tools/plex-teardowntest * do not hardcode mediapart size in test_video * remove cache:pip from travis * Revert "unlock websocket-client in requirements_dev" This reverts commit 0d536bd06dbdc4a4b869a1686f8cd008898859fe. * remove debug from server.py * improve webhook tests * fix type() check to isinstance() * remove excessive `else` branch due to Hellowlol advice * add `unknown` as allowed `myPlexMappingState` in test_server
2018-09-14 18:03:23 +00:00
playlist.copyToUser(shared_username)
user = plex.myPlexAccount().user(shared_username)
2017-07-17 14:11:03 +00:00
user_plex = fresh_plex(plex._baseurl, user.get_token(plex.machineIdentifier))
assert playlist.title in [p.title for p in user_plex.playlists()]
finally:
playlist.delete()
2018-11-16 23:20:21 +00:00
def test_smart_playlist(plex, movies):
try:
pl = plex.createPlaylist(title='smart_playlist', smart=True, limit=1, section=movies, year=2008)
assert len(pl.items()) == 1
assert pl.smart
finally:
pl.delete()