2017-01-09 14:21:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-01-09 14:08:18 +00:00
|
|
|
import pytest
|
2017-01-31 00:02:22 +00:00
|
|
|
from plexapi.exceptions import NotFound
|
2017-04-23 05:18:53 +00:00
|
|
|
from . import conftest as utils
|
2017-01-09 14:08:18 +00:00
|
|
|
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_section(plex):
|
|
|
|
sections = plex.library.sections()
|
2017-04-29 05:47:21 +00:00
|
|
|
assert len(sections) >= 3
|
2017-04-15 00:47:59 +00:00
|
|
|
section_name = plex.library.section('TV Shows')
|
|
|
|
assert section_name.title == 'TV Shows'
|
2017-01-31 00:02:22 +00:00
|
|
|
with pytest.raises(NotFound):
|
2017-04-15 00:47:59 +00:00
|
|
|
assert plex.library.section('cant-find-me')
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_sectionByID_is_equal_section(plex, plex2):
|
2017-01-31 00:02:22 +00:00
|
|
|
# test that sctionmyID refreshes the section if the key is missing
|
|
|
|
# this is needed if there isnt any cached sections
|
2017-04-15 00:47:59 +00:00
|
|
|
assert plex2.library.sectionByID('1')
|
|
|
|
assert plex.library.sectionByID('1').uuid == plex.library.section('Movies').uuid
|
|
|
|
|
|
|
|
|
|
|
|
def test_library_sectionByID_with_attrs(plex):
|
|
|
|
section = plex.library.sectionByID('1')
|
|
|
|
assert section.agent == 'com.plexapp.agents.imdb'
|
2017-04-29 05:47:21 +00:00
|
|
|
assert section.allowSync is ('sync' in plex.ownerFeatures)
|
2017-04-15 00:47:59 +00:00
|
|
|
assert section.art == '/:/resources/movie-fanart.jpg'
|
|
|
|
assert '/library/sections/1/composite/' in section.composite
|
2017-04-23 05:18:53 +00:00
|
|
|
assert utils.is_datetime(section.createdAt)
|
2017-04-15 00:47:59 +00:00
|
|
|
assert section.filters == '1'
|
|
|
|
assert section._initpath == '/library/sections'
|
|
|
|
assert section.key == '1'
|
|
|
|
assert section.language == 'en'
|
|
|
|
assert len(section.locations) == 1
|
|
|
|
assert len(section.locations[0]) >= 10
|
|
|
|
assert section.refreshing is False
|
|
|
|
assert section.scanner == 'Plex Movie Scanner'
|
2017-04-23 05:18:53 +00:00
|
|
|
assert section._server._baseurl == utils.SERVER_BASEURL
|
2017-04-15 00:47:59 +00:00
|
|
|
assert section.thumb == '/:/resources/movie.png'
|
|
|
|
assert section.title == 'Movies'
|
|
|
|
assert section.type == 'movie'
|
2017-04-23 05:18:53 +00:00
|
|
|
assert utils.is_datetime(section.updatedAt)
|
2017-04-15 00:47:59 +00:00
|
|
|
assert len(section.uuid) == 36
|
|
|
|
|
|
|
|
|
|
|
|
def test_library_section_get_movie(plex):
|
|
|
|
assert plex.library.section('Movies').get('16 blocks')
|
|
|
|
|
|
|
|
|
|
|
|
def test_library_section_delete(monkeypatch, movies):
|
2017-02-10 23:16:23 +00:00
|
|
|
monkeypatch.delattr("requests.sessions.Session.request")
|
|
|
|
try:
|
2017-04-15 00:47:59 +00:00
|
|
|
movies.delete()
|
2017-02-10 23:16:23 +00:00
|
|
|
except AttributeError:
|
2017-04-15 00:47:59 +00:00
|
|
|
# will always raise because there is no request
|
|
|
|
pass
|
2017-02-10 23:16:23 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_fetchItem(plex, movie):
|
|
|
|
item1 = plex.library.fetchItem('/library/metadata/%s' % movie.ratingKey)
|
|
|
|
item2 = plex.library.fetchItem(movie.ratingKey)
|
|
|
|
assert item1.title == '16 Blocks'
|
|
|
|
assert item1 == item2 == movie
|
2017-01-09 14:21:54 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_onDeck(plex):
|
|
|
|
assert len(list(plex.library.onDeck()))
|
2017-01-09 14:21:54 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_recentlyAdded(plex):
|
|
|
|
assert len(list(plex.library.recentlyAdded()))
|
2017-01-09 14:21:54 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_search(plex):
|
|
|
|
item = plex.library.search('16 blocks')[0]
|
|
|
|
assert item.title == '16 Blocks'
|
2017-01-09 14:21:54 +00:00
|
|
|
|
2017-02-27 22:16:02 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_add_edit_delete(plex):
|
|
|
|
# Dont add a location to prevent scanning scanning
|
|
|
|
plex.library.add(name='zomg strange11', type='movie', agent='com.plexapp.agents.imdb',
|
|
|
|
scanner='Plex Movie Scanner', language='en')
|
|
|
|
assert plex.library.section('zomg strange11')
|
|
|
|
edited_library = plex.library.section('zomg strange11').edit(name='a renamed lib',
|
|
|
|
type='movie', agent='com.plexapp.agents.imdb')
|
2017-02-27 22:16:02 +00:00
|
|
|
assert edited_library.title == 'a renamed lib'
|
2017-04-15 00:47:59 +00:00
|
|
|
plex.library.section('a renamed lib').delete()
|
2017-02-27 22:16:02 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_cleanBundle(plex):
|
|
|
|
plex.library.cleanBundles()
|
2017-02-02 04:47:22 +00:00
|
|
|
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_optimize(plex):
|
|
|
|
plex.library.optimize()
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_emptyTrash(plex):
|
|
|
|
plex.library.emptyTrash()
|
2017-02-02 04:47:22 +00:00
|
|
|
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def _test_library_Library_refresh(plex):
|
|
|
|
# TODO: fix mangle and proof the sections attrs
|
|
|
|
plex.library.refresh()
|
2017-02-02 04:47:22 +00:00
|
|
|
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_update(plex):
|
|
|
|
plex.library.update()
|
2017-02-14 22:36:21 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_cancelUpdate(plex):
|
|
|
|
plex.library.cancelUpdate()
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-02-18 21:15:49 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_deleteMediaPreviews(plex):
|
|
|
|
plex.library.deleteMediaPreviews()
|
2017-02-18 21:15:49 +00:00
|
|
|
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def _test_library_MovieSection_refresh(movies):
|
|
|
|
movies.refresh()
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-02-14 22:36:21 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_MovieSection_update(movies):
|
|
|
|
movies.update()
|
2017-02-14 22:36:21 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_MovieSection_cancelUpdate(movies):
|
|
|
|
movies.cancelUpdate()
|
2017-02-18 21:15:49 +00:00
|
|
|
|
2017-02-14 22:36:21 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_librarty_deleteMediaPreviews(movies):
|
|
|
|
movies.deleteMediaPreviews()
|
2017-02-14 22:36:21 +00:00
|
|
|
|
|
|
|
|
2017-04-29 05:47:21 +00:00
|
|
|
def test_library_MovieSection_onDeck(movies, tvshows):
|
|
|
|
assert len(movies.onDeck()) + len(tvshows.onDeck())
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_MovieSection_recentlyAdded(movies):
|
|
|
|
assert len(movies.recentlyAdded())
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_MovieSection_analyze(movies):
|
|
|
|
movies.analyze()
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_ShowSection_searchShows(tvshows):
|
|
|
|
assert tvshows.searchShows(title='The 100')
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_ShowSection_searchEpisodes(tvshows):
|
|
|
|
assert tvshows.searchEpisodes(title='Pilot')
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_ShowSection_recentlyAdded(tvshows):
|
|
|
|
assert len(tvshows.recentlyAdded())
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_MusicSection_albums(music):
|
|
|
|
assert len(music.albums())
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_MusicSection_searchTracks(music):
|
|
|
|
assert len(music.searchTracks(title='Holy Moment'))
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_MusicSection_searchAlbums(music):
|
|
|
|
assert len(music.searchAlbums(title='Unmastered Impulses'))
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-23 05:54:53 +00:00
|
|
|
def test_library_PhotoSection_searchAlbums(photos, photoalbum):
|
|
|
|
title = photoalbum.title
|
|
|
|
albums = photos.searchAlbums(title)
|
2017-01-31 00:02:22 +00:00
|
|
|
assert len(albums)
|
|
|
|
|
|
|
|
|
2017-04-23 05:54:53 +00:00
|
|
|
def test_library_PhotoSection_searchPhotos(photos, photoalbum):
|
|
|
|
title = photoalbum.photos()[0].title
|
|
|
|
assert len(photos.searchPhotos(title))
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_and_section_search_for_movie(plex):
|
2017-01-09 14:21:54 +00:00
|
|
|
find = '16 blocks'
|
2017-04-15 00:47:59 +00:00
|
|
|
l_search = plex.library.search(find)
|
|
|
|
s_search = plex.library.section('Movies').search(find)
|
2017-01-09 14:21:54 +00:00
|
|
|
assert l_search == s_search
|
|
|
|
|
|
|
|
|
2017-04-29 05:47:21 +00:00
|
|
|
# This started failing on more recent Plex Server builds
|
|
|
|
@pytest.mark.xfail
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_search_with_apostrophe(plex):
|
|
|
|
show_title = "Marvel's Daredevil"
|
|
|
|
result_root = plex.search(show_title)
|
|
|
|
result_shows = plex.library.section('TV Shows').search(show_title)
|
2017-02-07 07:14:49 +00:00
|
|
|
assert result_root
|
2017-01-09 14:21:54 +00:00
|
|
|
assert result_shows
|
2017-02-07 07:14:49 +00:00
|
|
|
assert result_root == result_shows
|
2017-01-09 14:08:18 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_crazy_search(plex, movie):
|
|
|
|
movies = plex.library.section('Movies')
|
2017-01-31 00:02:22 +00:00
|
|
|
assert movie in movies.search(actor=movie.actors[0], sort='titleSort'), 'Unable to search movie by actor.'
|
2017-01-09 14:21:54 +00:00
|
|
|
assert movie in movies.search(director=movie.directors[0]), 'Unable to search movie by director.'
|
|
|
|
assert movie in movies.search(year=['2006', '2007']), 'Unable to search movie by year.'
|
|
|
|
assert movie not in movies.search(year=2007), 'Unable to filter movie by year.'
|
2017-02-08 07:00:43 +00:00
|
|
|
assert movie in movies.search(actor=movie.actors[0].tag)
|