2021-02-15 06:33:38 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2021-08-04 21:02:01 +00:00
|
|
|
from urllib.parse import quote_plus
|
|
|
|
|
2021-02-15 06:54:31 +00:00
|
|
|
import pytest
|
2021-05-30 02:26:12 +00:00
|
|
|
from plexapi.exceptions import BadRequest, NotFound
|
2021-02-15 06:54:31 +00:00
|
|
|
|
2021-02-15 06:33:38 +00:00
|
|
|
from . import conftest as utils
|
|
|
|
from . import test_mixins
|
|
|
|
|
|
|
|
|
|
|
|
def test_Collection_attrs(collection):
|
|
|
|
assert utils.is_datetime(collection.addedAt)
|
|
|
|
assert collection.art is None
|
|
|
|
assert collection.artBlurHash is None
|
|
|
|
assert collection.childCount == 1
|
2022-02-27 06:50:04 +00:00
|
|
|
assert collection.collectionFilterBasedOnUser == 0
|
2021-02-15 06:33:38 +00:00
|
|
|
assert collection.collectionMode == -1
|
2021-04-23 20:59:02 +00:00
|
|
|
assert collection.collectionPublished is False
|
2021-02-15 06:33:38 +00:00
|
|
|
assert collection.collectionSort == 0
|
2021-04-23 20:59:02 +00:00
|
|
|
assert collection.content is None
|
2021-05-28 05:39:00 +00:00
|
|
|
assert collection.contentRating is None
|
2021-02-15 06:33:38 +00:00
|
|
|
assert not collection.fields
|
|
|
|
assert collection.guid.startswith("collection://")
|
|
|
|
assert utils.is_int(collection.index)
|
|
|
|
assert collection.key.startswith("/library/collections/")
|
|
|
|
assert not collection.labels
|
|
|
|
assert utils.is_int(collection.librarySectionID)
|
2022-08-28 05:56:01 +00:00
|
|
|
assert collection.librarySectionKey == f"/library/sections/{collection.librarySectionID}"
|
2021-02-15 06:33:38 +00:00
|
|
|
assert collection.librarySectionTitle == "Movies"
|
2021-02-15 06:43:44 +00:00
|
|
|
assert utils.is_int(collection.maxYear)
|
|
|
|
assert utils.is_int(collection.minYear)
|
2021-04-23 20:59:02 +00:00
|
|
|
assert utils.is_int(collection.ratingCount)
|
2021-02-15 06:33:38 +00:00
|
|
|
assert utils.is_int(collection.ratingKey)
|
2021-04-23 20:59:02 +00:00
|
|
|
assert collection.smart is False
|
2021-02-15 06:33:38 +00:00
|
|
|
assert collection.subtype == "movie"
|
|
|
|
assert collection.summary == ""
|
2022-02-27 05:05:43 +00:00
|
|
|
assert collection.theme is None
|
2022-08-28 05:56:01 +00:00
|
|
|
assert collection.thumb.startswith(f"/library/collections/{collection.ratingKey}/composite")
|
2021-02-15 06:33:38 +00:00
|
|
|
assert collection.thumbBlurHash is None
|
2021-05-28 05:39:00 +00:00
|
|
|
assert collection.title == "Test Collection"
|
2021-02-15 06:33:38 +00:00
|
|
|
assert collection.titleSort == collection.title
|
|
|
|
assert collection.type == "collection"
|
|
|
|
assert utils.is_datetime(collection.updatedAt)
|
2021-05-30 02:26:12 +00:00
|
|
|
assert collection.listType == "video"
|
|
|
|
assert collection.metadataType == collection.subtype
|
|
|
|
assert collection.isVideo is True
|
|
|
|
assert collection.isAudio is False
|
|
|
|
assert collection.isPhoto is False
|
2021-02-15 06:33:38 +00:00
|
|
|
|
|
|
|
|
2021-05-29 22:17:47 +00:00
|
|
|
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
|
2021-05-30 02:26:12 +00:00
|
|
|
with pytest.raises(NotFound):
|
|
|
|
collection.item("Does not exist")
|
2021-05-29 22:17:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_Collection_items(collection):
|
|
|
|
items = collection.items()
|
|
|
|
assert len(items) == 1
|
2021-02-15 06:33:38 +00:00
|
|
|
|
|
|
|
|
2022-02-27 06:50:04 +00:00
|
|
|
def test_Collection_filterUserUpdate(plex, movies):
|
|
|
|
title = "test_Collection_filterUserUpdate"
|
|
|
|
try:
|
|
|
|
collection = plex.createCollection(
|
|
|
|
title=title,
|
|
|
|
section=movies,
|
|
|
|
smart=True
|
|
|
|
)
|
|
|
|
|
|
|
|
mode_dict = {"admin": 0, "user": 1}
|
|
|
|
for key, value in mode_dict.items():
|
|
|
|
collection.filterUserUpdate(user=key)
|
|
|
|
collection.reload()
|
|
|
|
assert collection.collectionFilterBasedOnUser == value
|
|
|
|
with pytest.raises(BadRequest):
|
|
|
|
collection.filterUserUpdate(user="bad-user")
|
|
|
|
collection.filterUserUpdate("admin")
|
|
|
|
finally:
|
|
|
|
collection.delete()
|
|
|
|
|
|
|
|
|
2021-02-15 06:33:38 +00:00
|
|
|
def test_Collection_modeUpdate(collection):
|
2021-02-15 06:43:44 +00:00
|
|
|
mode_dict = {"default": -1, "hide": 0, "hideItems": 1, "showItems": 2}
|
2021-02-15 06:33:38 +00:00
|
|
|
for key, value in mode_dict.items():
|
2021-02-15 06:54:31 +00:00
|
|
|
collection.modeUpdate(mode=key)
|
2021-02-15 06:33:38 +00:00
|
|
|
collection.reload()
|
|
|
|
assert collection.collectionMode == value
|
2021-02-15 06:54:31 +00:00
|
|
|
with pytest.raises(BadRequest):
|
|
|
|
collection.modeUpdate(mode="bad-mode")
|
2021-02-15 07:48:58 +00:00
|
|
|
collection.modeUpdate("default")
|
2021-02-15 06:33:38 +00:00
|
|
|
|
|
|
|
|
2021-02-15 07:48:58 +00:00
|
|
|
def test_Collection_sortUpdate(collection):
|
2021-05-30 02:26:12 +00:00
|
|
|
sort_dict = {"release": 0, "alpha": 1}
|
2021-02-15 06:54:31 +00:00
|
|
|
for key, value in sort_dict.items():
|
2021-02-15 07:06:34 +00:00
|
|
|
collection.sortUpdate(sort=key)
|
2021-02-15 06:54:31 +00:00
|
|
|
collection.reload()
|
|
|
|
assert collection.collectionSort == value
|
|
|
|
with pytest.raises(BadRequest):
|
|
|
|
collection.sortUpdate(sort="bad-sort")
|
2021-02-15 07:48:58 +00:00
|
|
|
collection.sortUpdate("release")
|
2021-02-15 06:33:38 +00:00
|
|
|
|
|
|
|
|
2022-08-26 17:43:47 +00:00
|
|
|
@pytest.mark.authenticated
|
|
|
|
def test_Collection_visibility(collection):
|
|
|
|
visibility = collection.visibility()
|
|
|
|
with pytest.raises(BadRequest):
|
|
|
|
visibility.move()
|
|
|
|
with pytest.raises(BadRequest):
|
|
|
|
visibility.remove()
|
|
|
|
visibility.updateVisibility(recommended=True, home=True, shared=True)
|
|
|
|
assert visibility.promotedToRecommended is True
|
|
|
|
assert visibility.promotedToOwnHome is True
|
|
|
|
assert visibility.promotedToSharedHome is True
|
|
|
|
visibility.updateVisibility(recommended=False, home=False, shared=False)
|
|
|
|
assert visibility.promotedToRecommended is False
|
|
|
|
assert visibility.promotedToOwnHome is False
|
|
|
|
assert visibility.promotedToSharedHome is False
|
|
|
|
visibility.move()
|
|
|
|
visibility.remove()
|
|
|
|
with pytest.raises(BadRequest):
|
|
|
|
visibility.move()
|
|
|
|
with pytest.raises(NotFound):
|
|
|
|
visibility.remove()
|
|
|
|
|
|
|
|
|
2021-07-05 05:06:23 +00:00
|
|
|
@pytest.mark.authenticated
|
|
|
|
def test_Collection_sortUpdate_custom(collection):
|
|
|
|
collection.sortUpdate(sort="custom")
|
|
|
|
collection.reload()
|
|
|
|
assert collection.collectionSort == 2
|
|
|
|
collection.sortUpdate("release")
|
|
|
|
|
|
|
|
|
|
|
|
def test_Collection_add_move_remove(collection, movies):
|
2021-05-29 22:17:47 +00:00
|
|
|
movie = movies.get("Big Buck Bunny")
|
|
|
|
assert movie not in collection
|
|
|
|
collection.addItems(movie)
|
2021-02-15 06:33:38 +00:00
|
|
|
collection.reload()
|
2021-05-29 22:17:47 +00:00
|
|
|
assert movie in collection
|
2021-06-30 03:08:39 +00:00
|
|
|
items = collection.items()
|
|
|
|
collection.moveItem(items[1])
|
|
|
|
items_moved = collection.reload().items()
|
|
|
|
assert items_moved[0] == items[1]
|
|
|
|
assert items_moved[1] == items[0]
|
|
|
|
collection.moveItem(items[1], after=items[0])
|
|
|
|
items_moved = collection.reload().items()
|
|
|
|
assert items_moved[0] == items[0]
|
|
|
|
assert items_moved[1] == items[1]
|
2021-05-29 22:17:47 +00:00
|
|
|
collection.removeItems(movie)
|
|
|
|
collection.reload()
|
|
|
|
assert movie not in collection
|
2021-07-05 04:45:34 +00:00
|
|
|
# Reset collection sort due to bug with corrupted XML response
|
|
|
|
# for movies that have been moved in a collection and have
|
2022-08-26 19:14:24 +00:00
|
|
|
# progress (updateProgress) or marked as played (markPlayed)
|
2021-07-05 04:45:34 +00:00
|
|
|
collection.sortUpdate("release")
|
2021-05-29 22:17:47 +00:00
|
|
|
|
|
|
|
|
2022-02-27 05:40:51 +00:00
|
|
|
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
|
2021-05-29 22:17:47 +00:00
|
|
|
def test_Collection_edit(collection, movies):
|
|
|
|
fields = {"title", "titleSort", "contentRating", "summary"}
|
|
|
|
title = collection.title
|
|
|
|
titleSort = collection.titleSort
|
|
|
|
contentRating = collection.contentRating
|
|
|
|
summary = collection.summary
|
|
|
|
|
|
|
|
newTitle = "New Title"
|
|
|
|
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
|
|
|
|
}
|
|
|
|
)
|
2021-06-06 21:38:36 +00:00
|
|
|
collection.reload()
|
2021-05-29 22:17:47 +00:00
|
|
|
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_create(plex, tvshows):
|
|
|
|
title = "test_Collection_create"
|
|
|
|
try:
|
|
|
|
collection = plex.createCollection(
|
|
|
|
title=title,
|
|
|
|
section=tvshows,
|
|
|
|
items=tvshows.all()
|
|
|
|
)
|
|
|
|
assert collection in tvshows.collections()
|
|
|
|
assert collection.smart is False
|
|
|
|
finally:
|
|
|
|
collection.delete()
|
|
|
|
|
|
|
|
|
|
|
|
def test_Collection_createSmart(plex, tvshows):
|
|
|
|
title = "test_Collection_createSmart"
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
2021-06-18 22:26:24 +00:00
|
|
|
def test_Collection_smartFilters(plex, movies):
|
2021-06-18 21:34:53 +00:00
|
|
|
title = "test_Collection_smartFilters"
|
2021-06-18 22:26:24 +00:00
|
|
|
advancedFilters = {
|
|
|
|
'and': [
|
|
|
|
{
|
|
|
|
'or': [
|
|
|
|
{'title': 'elephant'},
|
|
|
|
{'title=': 'Big Buck Bunny'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{'year>>': 1990},
|
|
|
|
{'unwatched': True}
|
|
|
|
]
|
|
|
|
}
|
2021-06-18 21:34:53 +00:00
|
|
|
try:
|
|
|
|
collection = plex.createCollection(
|
|
|
|
title=title,
|
2021-06-18 22:26:24 +00:00
|
|
|
section=movies,
|
2021-06-18 21:34:53 +00:00
|
|
|
smart=True,
|
|
|
|
limit=5,
|
2021-06-18 22:26:24 +00:00
|
|
|
sort="year",
|
|
|
|
filters=advancedFilters
|
2021-06-18 21:34:53 +00:00
|
|
|
)
|
|
|
|
filters = collection.filters()
|
2021-06-18 22:26:24 +00:00
|
|
|
assert movies.search(**filters) == collection.items()
|
2021-06-18 21:34:53 +00:00
|
|
|
finally:
|
|
|
|
collection.delete()
|
|
|
|
|
|
|
|
|
2021-05-29 22:17:47 +00:00
|
|
|
def test_Collection_exceptions(plex, movies, movie, artist):
|
|
|
|
title = 'test_Collection_exceptions'
|
|
|
|
try:
|
2021-05-30 02:26:12 +00:00
|
|
|
collection = plex.createCollection(title, section=movies.title, items=movie)
|
2021-05-29 22:17:47 +00:00
|
|
|
with pytest.raises(BadRequest):
|
|
|
|
collection.updateFilters()
|
|
|
|
with pytest.raises(BadRequest):
|
|
|
|
collection.addItems(artist)
|
2022-02-27 06:50:04 +00:00
|
|
|
with pytest.raises(BadRequest):
|
|
|
|
collection.filterUserUpdate("user")
|
2021-05-29 22:17:47 +00:00
|
|
|
finally:
|
|
|
|
collection.delete()
|
2021-02-15 06:33:38 +00:00
|
|
|
|
2021-05-29 22:17:47 +00:00
|
|
|
with pytest.raises(BadRequest):
|
2021-05-30 01:05:42 +00:00
|
|
|
plex.createCollection(title, section=movies, items=[])
|
2021-05-29 22:17:47 +00:00
|
|
|
with pytest.raises(BadRequest):
|
2021-05-30 01:05:42 +00:00
|
|
|
plex.createCollection(title, section=movies, items=[movie, artist])
|
2021-02-15 06:33:38 +00:00
|
|
|
|
2021-05-29 22:17:47 +00:00
|
|
|
try:
|
2021-05-30 02:26:12 +00:00
|
|
|
collection = plex.createCollection(title, smart=True, section=movies.title, **{'year>>': 2000})
|
2021-05-29 22:17:47 +00:00
|
|
|
with pytest.raises(BadRequest):
|
|
|
|
collection.addItems(movie)
|
|
|
|
with pytest.raises(BadRequest):
|
|
|
|
collection.removeItems(movie)
|
2021-06-30 03:08:39 +00:00
|
|
|
with pytest.raises(BadRequest):
|
|
|
|
collection.moveItem(movie)
|
2022-02-27 06:50:04 +00:00
|
|
|
with pytest.raises(BadRequest):
|
|
|
|
collection.sortUpdate("custom")
|
2021-05-29 22:17:47 +00:00
|
|
|
finally:
|
|
|
|
collection.delete()
|
2021-02-15 06:33:38 +00:00
|
|
|
|
|
|
|
|
2021-02-24 17:07:40 +00:00
|
|
|
def test_Collection_posters(collection):
|
2021-02-15 06:33:38 +00:00
|
|
|
posters = collection.posters()
|
|
|
|
assert posters
|
|
|
|
|
|
|
|
|
2021-02-24 17:07:40 +00:00
|
|
|
def test_Collection_art(collection):
|
2021-02-15 06:33:38 +00:00
|
|
|
arts = collection.arts()
|
|
|
|
assert not arts # Collection has no default art
|
|
|
|
|
|
|
|
|
2021-11-21 01:14:34 +00:00
|
|
|
@pytest.mark.xfail(reason="Changing images fails randomly")
|
2021-02-24 17:07:40 +00:00
|
|
|
def test_Collection_mixins_images(collection):
|
2021-09-13 00:56:21 +00:00
|
|
|
test_mixins.lock_art(collection)
|
|
|
|
test_mixins.lock_poster(collection)
|
2021-02-24 17:04:52 +00:00
|
|
|
test_mixins.edit_art(collection)
|
|
|
|
test_mixins.edit_poster(collection)
|
|
|
|
test_mixins.attr_artUrl(collection)
|
|
|
|
test_mixins.attr_posterUrl(collection)
|
|
|
|
|
|
|
|
|
2022-02-27 05:05:43 +00:00
|
|
|
def test_Collection_mixins_themes(collection):
|
|
|
|
test_mixins.edit_theme(collection)
|
|
|
|
|
|
|
|
|
2021-05-30 22:49:28 +00:00
|
|
|
def test_Collection_mixins_rating(collection):
|
|
|
|
test_mixins.edit_rating(collection)
|
|
|
|
|
|
|
|
|
2022-02-27 05:40:51 +00:00
|
|
|
def test_Collection_mixins_fields(collection):
|
2023-03-09 23:22:56 +00:00
|
|
|
test_mixins.edit_added_at(collection)
|
2022-02-27 05:40:51 +00:00
|
|
|
test_mixins.edit_content_rating(collection)
|
|
|
|
test_mixins.edit_sort_title(collection)
|
|
|
|
test_mixins.edit_summary(collection)
|
|
|
|
test_mixins.edit_title(collection)
|
2023-07-27 21:45:23 +00:00
|
|
|
test_mixins.edit_user_rating(collection)
|
2022-02-27 05:40:51 +00:00
|
|
|
|
|
|
|
|
2021-02-24 17:07:40 +00:00
|
|
|
def test_Collection_mixins_tags(collection):
|
2021-02-15 06:33:38 +00:00
|
|
|
test_mixins.edit_label(collection)
|
2021-08-04 21:02:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_Collection_PlexWebURL(plex, collection):
|
|
|
|
url = collection.getWebURL()
|
|
|
|
assert url.startswith('https://app.plex.tv/desktop')
|
|
|
|
assert plex.machineIdentifier in url
|
|
|
|
assert 'details' in url
|
|
|
|
assert quote_plus(collection.key) in url
|