|
| 1 | +""" |
| 2 | +Test Library Functions |
| 3 | +
|
| 4 | +As of Plex version 0.9.11 I noticed that you must be logged in |
| 5 | +to browse even the plex server locatewd at localhost. You can |
| 6 | +run this test suite with the following command: |
| 7 | +
|
| 8 | +>> python tests.py -u <USERNAME> -p <PASSWORD> -s <SERVERNAME> |
| 9 | +""" |
| 10 | +import argparse, sys, time |
| 11 | +from os.path import dirname, abspath |
| 12 | +sys.path.append(dirname(dirname(abspath(__file__)))) |
| 13 | +from utils import log, run_tests |
| 14 | + |
| 15 | +SHOW_SECTION = 'TV Shows' |
| 16 | +SHOW_TITLE = 'Game of Thrones' |
| 17 | +SHOW_SEASON = 'Season 1' |
| 18 | +SHOW_EPISODE = 'Winter Is Coming' |
| 19 | +MOVIE_SECTION = 'Movies' |
| 20 | +MOVIE_TITLE = 'Jurassic Park' |
| 21 | +PLEX_CLIENT = "Michael's iPhone" |
| 22 | + |
| 23 | + |
| 24 | +def test_001_server(plex): |
| 25 | + log(2, 'Username: %s' % plex.myPlexUsername) |
| 26 | + log(2, 'Platform: %s' % plex.platform) |
| 27 | + log(2, 'Version: %s' % plex.version) |
| 28 | + assert plex.myPlexUsername is not None, 'Unknown username.' |
| 29 | + assert plex.platform is not None, 'Unknown platform.' |
| 30 | + assert plex.version is not None, 'Unknown version.' |
| 31 | + |
| 32 | + |
| 33 | +def test_002_list_sections(plex): |
| 34 | + sections = [s.title for s in plex.library.sections()] |
| 35 | + log(2, 'Sections: %s' % sections) |
| 36 | + assert SHOW_SECTION in sections, '%s not a library section.' % SHOW_SECTION |
| 37 | + assert MOVIE_SECTION in sections, '%s not a library section.' % MOVIE_SECTION |
| 38 | + plex.library.section(SHOW_SECTION) |
| 39 | + plex.library.section(MOVIE_SECTION) |
| 40 | + |
| 41 | + |
| 42 | +def test_003_search_show(plex): |
| 43 | + result_server = plex.search(SHOW_TITLE) |
| 44 | + result_library = plex.library.search(SHOW_TITLE) |
| 45 | + result_shows = plex.library.section(SHOW_SECTION).search(SHOW_TITLE) |
| 46 | + result_movies = plex.library.section(MOVIE_SECTION).search(SHOW_TITLE) |
| 47 | + log(2, 'Searching for: %s' % SHOW_TITLE) |
| 48 | + log(4, 'Result Server: %s' % result_server) |
| 49 | + log(4, 'Result Library: %s' % result_library) |
| 50 | + log(4, 'Result Shows: %s' % result_shows) |
| 51 | + log(4, 'Result Movies: %s' % result_movies) |
| 52 | + assert result_server, 'Show not found.' |
| 53 | + assert result_server == result_library == result_shows, 'Show searches not consistent.' |
| 54 | + assert not result_movies, 'Movie search returned show title.' |
| 55 | + |
| 56 | + |
| 57 | +def test_004_search_movie(plex): |
| 58 | + result_server = plex.search(MOVIE_TITLE) |
| 59 | + result_library = plex.library.search(MOVIE_TITLE) |
| 60 | + result_shows = plex.library.section(SHOW_SECTION).search(MOVIE_TITLE) |
| 61 | + result_movies = plex.library.section(MOVIE_SECTION).search(MOVIE_TITLE) |
| 62 | + log(2, 'Searching for: %s' % MOVIE_TITLE) |
| 63 | + log(4, 'Result Server: %s' % result_server) |
| 64 | + log(4, 'Result Library: %s' % result_library) |
| 65 | + log(4, 'Result Shows: %s' % result_shows) |
| 66 | + log(4, 'Result Movies: %s' % result_movies) |
| 67 | + assert result_server, 'Movie not found.' |
| 68 | + assert result_server == result_library == result_movies, 'Movie searches not consistent.' |
| 69 | + assert not result_shows, 'Show search returned show title.' |
| 70 | + |
| 71 | + |
| 72 | +def test_005_navigate_to_show(plex): |
| 73 | + result_library = plex.library.get(SHOW_TITLE) |
| 74 | + result_shows = plex.library.section(SHOW_SECTION).get(SHOW_TITLE) |
| 75 | + try: |
| 76 | + result_movies = plex.library.section(MOVIE_SECTION).get(SHOW_TITLE) |
| 77 | + except: |
| 78 | + result_movies = None |
| 79 | + log(2, 'Navigating to: %s' % SHOW_TITLE) |
| 80 | + log(4, 'Result Library: %s' % result_library) |
| 81 | + log(4, 'Result Shows: %s' % result_shows) |
| 82 | + log(4, 'Result Movies: %s' % result_movies) |
| 83 | + assert result_library == result_shows, 'Show navigation not consistent.' |
| 84 | + assert not result_movies, 'Movie navigation returned show title.' |
| 85 | + |
| 86 | + |
| 87 | +def test_006_navigate_to_movie(plex): |
| 88 | + result_library = plex.library.get(MOVIE_TITLE) |
| 89 | + result_movies = plex.library.section(MOVIE_SECTION).get(MOVIE_TITLE) |
| 90 | + try: |
| 91 | + result_shows = plex.library.section(SHOW_SECTION).get(MOVIE_TITLE) |
| 92 | + except: |
| 93 | + result_shows = None |
| 94 | + log(2, 'Navigating to: %s' % MOVIE_TITLE) |
| 95 | + log(4, 'Result Library: %s' % result_library) |
| 96 | + log(4, 'Result Shows: %s' % result_shows) |
| 97 | + log(4, 'Result Movies: %s' % result_movies) |
| 98 | + assert result_library == result_movies, 'Movie navigation not consistent.' |
| 99 | + assert not result_shows, 'Show navigation returned show title.' |
| 100 | + |
| 101 | + |
| 102 | +def test_007_navigate_around_show(plex): |
| 103 | + show = plex.library.get(SHOW_TITLE) |
| 104 | + seasons = show.seasons() |
| 105 | + season = show.season(SHOW_SEASON) |
| 106 | + episodes = show.episodes() |
| 107 | + episode = show.episode(SHOW_EPISODE) |
| 108 | + log(2, 'Navigating around show: %s' % show) |
| 109 | + log(4, 'Seasons: %s...' % seasons[:3]) |
| 110 | + log(4, 'Season: %s' % season) |
| 111 | + log(4, 'Episodes: %s...' % episodes[:3]) |
| 112 | + log(4, 'Episode: %s' % episode) |
| 113 | + assert SHOW_SEASON in [s.title for s in seasons], 'Unable to get season: %s' % SHOW_SEASON |
| 114 | + assert SHOW_EPISODE in [e.title for e in episodes], 'Unable to get episode: %s' % SHOW_EPISODE |
| 115 | + assert season.show() == show, 'season.show() doesnt match expected show.' |
| 116 | + assert episode.show() == show, 'episode.show() doesnt match expected show.' |
| 117 | + assert episode.season() == season, 'episode.season() doesnt match expected season.' |
| 118 | + |
| 119 | + |
| 120 | +def test_008_mark_movie_watched(plex): |
| 121 | + movie = plex.library.section(MOVIE_SECTION).get(MOVIE_TITLE) |
| 122 | + movie.markUnwatched() |
| 123 | + log(2, 'Marking movie watched: %s' % movie) |
| 124 | + log(2, 'View count: %s' % movie.viewCount) |
| 125 | + movie.markWatched() |
| 126 | + log(2, 'View count: %s' % movie.viewCount) |
| 127 | + assert movie.viewCount == 1, 'View count 0 after watched.' |
| 128 | + movie.markUnwatched() |
| 129 | + log(2, 'View count: %s' % movie.viewCount) |
| 130 | + assert movie.viewCount == 0, 'View count 1 after unwatched.' |
| 131 | + |
| 132 | + |
| 133 | +def test_009_refresh(plex): |
| 134 | + shows = plex.library.section(MOVIE_SECTION) |
| 135 | + shows.refresh() |
| 136 | + |
| 137 | + |
| 138 | +def test_010_playQueues(plex): |
| 139 | + episode = plex.library.get(SHOW_TITLE).get(SHOW_EPISODE) |
| 140 | + playqueue = plex.createPlayQueue(episode) |
| 141 | + assert len(playqueue.items) == 1, 'No items in play queue.' |
| 142 | + assert playqueue.items[0].title == SHOW_EPISODE, 'Wrong show queued.' |
| 143 | + assert playqueue.playQueueID, 'Play queue ID not set.' |
| 144 | + |
| 145 | + |
| 146 | +def test_011_play_media(plex): |
| 147 | + # Make sure the client is turned on! |
| 148 | + episode = plex.library.get(SHOW_TITLE).get(SHOW_EPISODE) |
| 149 | + client = plex.client(PLEX_CLIENT) |
| 150 | + client.playMedia(episode); time.sleep(10) |
| 151 | + client.pause(); time.sleep(3) |
| 152 | + client.stepForward(); time.sleep(3) |
| 153 | + client.play(); time.sleep(3) |
| 154 | + client.stop(); time.sleep(3) |
| 155 | + movie = plex.library.get(MOVIE_TITLE) |
| 156 | + movie.play(client); time.sleep(10) |
| 157 | + client.stop() |
| 158 | + |
| 159 | + |
| 160 | +def test_012_myplex_account(plex): |
| 161 | + account = plex.account() |
| 162 | + print account.__dict__ |
| 163 | + |
| 164 | + |
| 165 | +def test_013_list_media_files(plex): |
| 166 | + # Fetch file names from the tv show |
| 167 | + episode_files = [] |
| 168 | + episode = plex.library.get(SHOW_TITLE).episodes()[-1] |
| 169 | + log(2, 'Episode Files: %s' % episode) |
| 170 | + for media in episode.media: |
| 171 | + for part in media.parts: |
| 172 | + log(4, part.file) |
| 173 | + episode_files.append(part.file) |
| 174 | + assert filter(None, episode_files), 'No show files have been listed.' |
| 175 | + # Fetch file names from the movie |
| 176 | + movie_files = [] |
| 177 | + movie = plex.library.get(MOVIE_TITLE) |
| 178 | + log(2, 'Movie Files: %s' % movie) |
| 179 | + for media in movie.media: |
| 180 | + for part in media.parts: |
| 181 | + log(4, part.file) |
| 182 | + movie_files.append(part.file) |
| 183 | + assert filter(None, movie_files), 'No movie files have been listed.' |
| 184 | + |
| 185 | + |
| 186 | +def test_014_list_video_tags(plex): |
| 187 | + movie = plex.library.get(MOVIE_TITLE) |
| 188 | + log(2, 'Countries: %s' % movie.countries[0:3]) |
| 189 | + log(2, 'Directors: %s' % movie.directors[0:3]) |
| 190 | + log(2, 'Genres: %s' % movie.genres[0:3]) |
| 191 | + log(2, 'Producers: %s' % movie.producers[0:3]) |
| 192 | + log(2, 'Actors: %s' % movie.actors[0:3]) |
| 193 | + log(2, 'Writers: %s' % movie.writers[0:3]) |
| 194 | + assert filter(None, movie.countries), 'No countries listed for movie.' |
| 195 | + assert filter(None, movie.directors), 'No directors listed for movie.' |
| 196 | + assert filter(None, movie.genres), 'No genres listed for movie.' |
| 197 | + assert filter(None, movie.producers), 'No producers listed for movie.' |
| 198 | + assert filter(None, movie.actors), 'No actors listed for movie.' |
| 199 | + assert filter(None, movie.writers), 'No writers listed for movie.' |
| 200 | + log(2, 'List movies with same director: %s' % movie.directors[0]) |
| 201 | + related = movie.directors[0].related() |
| 202 | + log(4, related[0:3]) |
| 203 | + assert movie in related, 'Movie was not found in related directors search.' |
| 204 | + |
| 205 | + |
| 206 | +if __name__ == '__main__': |
| 207 | + parser = argparse.ArgumentParser(description='Run PlexAPI tests.') |
| 208 | + parser.add_argument('-s', '--server', help='Name of the Plex server (requires user/pass).') |
| 209 | + parser.add_argument('-u', '--username', help='Username for the Plex server.') |
| 210 | + parser.add_argument('-p', '--password', help='Password for the Plex server.') |
| 211 | + parser.add_argument('-n', '--name', help='Only run tests containing this string. Leave blank to run all tests.') |
| 212 | + args = parser.parse_args() |
| 213 | + run_tests(__name__, args) |
0 commit comments