mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-29 07:00:19 +00:00
Update collection tests
This commit is contained in:
parent
ccc6091bb4
commit
40e4413dde
2 changed files with 149 additions and 28 deletions
|
@ -39,6 +39,23 @@ def test_Collection_attrs(collection):
|
||||||
assert utils.is_datetime(collection.updatedAt)
|
assert utils.is_datetime(collection.updatedAt)
|
||||||
|
|
||||||
|
|
||||||
|
def test_Collection_section(collection, movies):
|
||||||
|
assert collection.section() == movies
|
||||||
|
|
||||||
|
|
||||||
|
def test_Collection_item(collection):
|
||||||
|
item1 = collection.item("Elephants Dream")
|
||||||
|
assert item1.title == "Elephants Dream"
|
||||||
|
item2 = collection.get("Elephants Dream")
|
||||||
|
assert item2.title == "Elephants Dream"
|
||||||
|
assert item1 == item2
|
||||||
|
|
||||||
|
|
||||||
|
def test_Collection_items(collection):
|
||||||
|
items = collection.items()
|
||||||
|
assert len(items) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_Collection_modeUpdate(collection):
|
def test_Collection_modeUpdate(collection):
|
||||||
mode_dict = {"default": -1, "hide": 0, "hideItems": 1, "showItems": 2}
|
mode_dict = {"default": -1, "hide": 0, "hideItems": 1, "showItems": 2}
|
||||||
for key, value in mode_dict.items():
|
for key, value in mode_dict.items():
|
||||||
|
@ -61,40 +78,131 @@ def test_Collection_sortUpdate(collection):
|
||||||
collection.sortUpdate("release")
|
collection.sortUpdate("release")
|
||||||
|
|
||||||
|
|
||||||
def test_Collection_edit(collection):
|
def test_Collection_add_remove(collection, movies, show):
|
||||||
edits = {"titleSort.value": "New Title Sort", "titleSort.locked": 1}
|
movie = movies.get("Big Buck Bunny")
|
||||||
collectionTitleSort = collection.titleSort
|
assert movie not in collection
|
||||||
collection.edit(**edits)
|
collection.addItems(movie)
|
||||||
collection.reload()
|
collection.reload()
|
||||||
for field in collection.fields:
|
assert movie in collection
|
||||||
if field.name == "titleSort":
|
collection.removeItems(movie)
|
||||||
assert collection.titleSort == "New Title Sort"
|
collection.reload()
|
||||||
assert field.locked is True
|
assert movie not in collection
|
||||||
collection.edit(**{"titleSort.value": collectionTitleSort, "titleSort.locked": 0})
|
with pytest.raises(BadRequest):
|
||||||
|
collection.addItems(show)
|
||||||
|
|
||||||
|
|
||||||
def test_Collection_delete(movies):
|
def test_Collection_edit(collection, movies):
|
||||||
delete_collection = "delete_collection"
|
fields = {"title", "titleSort", "contentRating", "summary"}
|
||||||
movie = movies.get("Sintel")
|
title = collection.title
|
||||||
movie.addCollection(delete_collection)
|
titleSort = collection.titleSort
|
||||||
collections = movies.collections(title=delete_collection)
|
contentRating = collection.contentRating
|
||||||
assert len(collections) == 1
|
summary = collection.summary
|
||||||
collections[0].delete()
|
|
||||||
collections = movies.collections(title=delete_collection)
|
newTitle = "New Title"
|
||||||
assert len(collections) == 0
|
newTitleSort = "New Title Sort"
|
||||||
|
newContentRating = "New Content Rating"
|
||||||
|
newSummary = "New Summary"
|
||||||
|
collection.edit(
|
||||||
|
title=newTitle,
|
||||||
|
titleSort=newTitleSort,
|
||||||
|
contentRating=newContentRating,
|
||||||
|
summary=newSummary
|
||||||
|
)
|
||||||
|
collection.reload()
|
||||||
|
assert collection.title == newTitle
|
||||||
|
assert collection.titleSort == newTitleSort
|
||||||
|
assert collection.contentRating == newContentRating
|
||||||
|
assert collection.summary == newSummary
|
||||||
|
lockedFields = [f.locked for f in collection.fields if f.name in fields]
|
||||||
|
assert all(lockedFields)
|
||||||
|
|
||||||
|
collection.edit(
|
||||||
|
title=title,
|
||||||
|
titleSort=titleSort,
|
||||||
|
contentRating=contentRating or "",
|
||||||
|
summary=summary,
|
||||||
|
**{
|
||||||
|
"title.locked": 0,
|
||||||
|
"titleSort.locked": 0,
|
||||||
|
"contentRating.locked": 0,
|
||||||
|
"summary.locked": 0
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# Cannot use collection.reload() since PlexObject.__setattr__()
|
||||||
|
# will not overwrite contentRating with None
|
||||||
|
collection = movies.collection("Test Collection")
|
||||||
|
assert collection.title == title
|
||||||
|
assert collection.titleSort == titleSort
|
||||||
|
assert collection.contentRating is None
|
||||||
|
assert collection.summary == summary
|
||||||
|
lockedFields = [f.locked for f in collection.fields if f.name in fields]
|
||||||
|
assert not any(lockedFields)
|
||||||
|
|
||||||
|
|
||||||
def test_Collection_item(collection):
|
def test_Collection_create(plex, tvshows):
|
||||||
item1 = collection.item("Elephants Dream")
|
title = "test_Collection_create"
|
||||||
assert item1.title == "Elephants Dream"
|
try:
|
||||||
item2 = collection.get("Elephants Dream")
|
collection = plex.createCollection(
|
||||||
assert item2.title == "Elephants Dream"
|
title=title,
|
||||||
assert item1 == item2
|
section=tvshows,
|
||||||
|
items=tvshows.all()
|
||||||
|
)
|
||||||
|
assert collection in tvshows.collections()
|
||||||
|
assert collection.smart is False
|
||||||
|
finally:
|
||||||
|
collection.delete()
|
||||||
|
|
||||||
|
|
||||||
def test_Collection_items(collection):
|
def test_Collection_createSmart(plex, tvshows):
|
||||||
items = collection.items()
|
title = "test_Collection_createSmart"
|
||||||
assert len(items) == 1
|
try:
|
||||||
|
collection = plex.createCollection(
|
||||||
|
title=title,
|
||||||
|
section=tvshows,
|
||||||
|
smart=True,
|
||||||
|
limit=3,
|
||||||
|
libtype="episode",
|
||||||
|
sort="episode.index:desc",
|
||||||
|
filters={"show.title": "Game of Thrones"}
|
||||||
|
)
|
||||||
|
assert collection in tvshows.collections()
|
||||||
|
assert collection.smart is True
|
||||||
|
assert len(collection.items()) == 3
|
||||||
|
assert all([e.type == "episode" for e in collection.items()])
|
||||||
|
assert all([e.grandparentTitle == "Game of Thrones" for e in collection.items()])
|
||||||
|
assert collection.items() == sorted(collection.items(), key=lambda e: e.index, reverse=True)
|
||||||
|
collection.updateFilters(limit=5, libtype="episode", filters={"show.title": "The 100"})
|
||||||
|
collection.reload()
|
||||||
|
assert len(collection.items()) == 5
|
||||||
|
assert all([e.grandparentTitle == "The 100" for e in collection.items()])
|
||||||
|
finally:
|
||||||
|
collection.delete()
|
||||||
|
|
||||||
|
|
||||||
|
def test_Collection_exceptions(plex, movies, movie, artist):
|
||||||
|
title = 'test_Collection_exceptions'
|
||||||
|
try:
|
||||||
|
collection = plex.createCollection(title, movies, movie)
|
||||||
|
with pytest.raises(BadRequest):
|
||||||
|
collection.updateFilters()
|
||||||
|
with pytest.raises(BadRequest):
|
||||||
|
collection.addItems(artist)
|
||||||
|
finally:
|
||||||
|
collection.delete()
|
||||||
|
|
||||||
|
with pytest.raises(BadRequest):
|
||||||
|
plex.createCollection(title, movies, items=[])
|
||||||
|
with pytest.raises(BadRequest):
|
||||||
|
plex.createCollection(title, movies, items=[movie, artist])
|
||||||
|
|
||||||
|
try:
|
||||||
|
collection = plex.createCollection(title, smart=True, section=movies, **{'year>>': 2000})
|
||||||
|
with pytest.raises(BadRequest):
|
||||||
|
collection.addItems(movie)
|
||||||
|
with pytest.raises(BadRequest):
|
||||||
|
collection.removeItems(movie)
|
||||||
|
finally:
|
||||||
|
collection.delete()
|
||||||
|
|
||||||
|
|
||||||
def test_Collection_posters(collection):
|
def test_Collection_posters(collection):
|
||||||
|
@ -104,7 +212,7 @@ def test_Collection_posters(collection):
|
||||||
|
|
||||||
def test_Collection_art(collection):
|
def test_Collection_art(collection):
|
||||||
arts = collection.arts()
|
arts = collection.arts()
|
||||||
assert not arts # Collection has no default art
|
assert arts
|
||||||
|
|
||||||
|
|
||||||
def test_Collection_mixins_images(collection):
|
def test_Collection_mixins_images(collection):
|
||||||
|
|
|
@ -141,6 +141,19 @@ def test_create_playqueue_from_playlist(plex, album):
|
||||||
playlist.delete()
|
playlist.delete()
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_playqueue_from_collection(plex, music, album):
|
||||||
|
try:
|
||||||
|
collection = plex.createCollection("test_collection", music, album)
|
||||||
|
pq = collection.playQueue(shuffle=1)
|
||||||
|
assert pq.playQueueShuffled is True
|
||||||
|
assert len(collection) == len(album.tracks())
|
||||||
|
assert len(pq) == len(collection)
|
||||||
|
pq.addItem(collection.items()[0])
|
||||||
|
assert len(pq) == len(collection) + 1
|
||||||
|
finally:
|
||||||
|
collection.delete()
|
||||||
|
|
||||||
|
|
||||||
def test_lookup_playqueue(plex, movie):
|
def test_lookup_playqueue(plex, movie):
|
||||||
pq = PlayQueue.create(plex, movie)
|
pq = PlayQueue.create(plex, movie)
|
||||||
pq_id = pq.playQueueID
|
pq_id = pq.playQueueID
|
||||||
|
|
Loading…
Reference in a new issue