Skip to content

Commit 3bebeaa

Browse files
committed
Add tests for Plex Web URLs
1 parent e10f96a commit 3bebeaa

File tree

7 files changed

+145
-0
lines changed

7 files changed

+145
-0
lines changed

tests/test_audio.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# -*- coding: utf-8 -*-
2+
from urllib.parse import quote_plus
3+
24
from . import conftest as utils
35
from . import test_media, test_mixins
46

@@ -103,6 +105,14 @@ def test_audio_Artist_media_tags(artist):
103105
test_media.tag_style(artist)
104106

105107

108+
def test_video_Artist_PlexWebURL(plex, artist):
109+
url = artist.getWebURL()
110+
assert url.startswith('https://app.plex.tv/desktop')
111+
assert plex.machineIdentifier in url
112+
assert 'details' in url
113+
assert quote_plus(artist.key) in url
114+
115+
106116
def test_audio_Album_attrs(album):
107117
assert utils.is_datetime(album.addedAt)
108118
if album.art:
@@ -196,6 +206,14 @@ def test_audio_Album_media_tags(album):
196206
test_media.tag_style(album)
197207

198208

209+
def test_video_Album_PlexWebURL(plex, album):
210+
url = album.getWebURL()
211+
assert url.startswith('https://app.plex.tv/desktop')
212+
assert plex.machineIdentifier in url
213+
assert 'details' in url
214+
assert quote_plus(album.key) in url
215+
216+
199217
def test_audio_Track_attrs(album):
200218
track = album.get("As Colourful As Ever").reload()
201219
assert utils.is_datetime(track.addedAt)
@@ -337,6 +355,14 @@ def test_audio_Track_media_tags(track):
337355
test_media.tag_mood(track)
338356

339357

358+
def test_video_Track_PlexWebURL(plex, track):
359+
url = track.getWebURL()
360+
assert url.startswith('https://app.plex.tv/desktop')
361+
assert plex.machineIdentifier in url
362+
assert 'details' in url
363+
assert quote_plus(track.parentKey) in url
364+
365+
340366
def test_audio_Audio_section(artist, album, track):
341367
assert artist.section()
342368
assert album.section()

tests/test_collection.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# -*- coding: utf-8 -*-
2+
from urllib.parse import quote_plus
3+
24
import pytest
35
from plexapi.exceptions import BadRequest, NotFound
46

@@ -283,3 +285,11 @@ def test_Collection_mixins_rating(collection):
283285

284286
def test_Collection_mixins_tags(collection):
285287
test_mixins.edit_label(collection)
288+
289+
290+
def test_Collection_PlexWebURL(plex, collection):
291+
url = collection.getWebURL()
292+
assert url.startswith('https://app.plex.tv/desktop')
293+
assert plex.machineIdentifier in url
294+
assert 'details' in url
295+
assert quote_plus(collection.key) in url

tests/test_library.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# -*- coding: utf-8 -*-
22
from collections import namedtuple
33
from datetime import datetime, timedelta
4+
from urllib.parse import quote_plus
5+
46
import pytest
57
from plexapi.exceptions import BadRequest, NotFound
68

@@ -212,6 +214,30 @@ def test_library_MovieSection_collection_exception(movies):
212214
movies.collection("Does Not Exists")
213215

214216

217+
def test_library_MovieSection_PlexWebURL(plex, movies):
218+
tab = 'library'
219+
url = movies.getWebURL(tab=tab)
220+
assert url.startswith('https://app.plex.tv/desktop')
221+
assert plex.machineIdentifier in url
222+
assert 'source=%s' % movies.key in url
223+
assert 'pivot=%s' % tab in url
224+
# Test a different base
225+
base = 'https://doesnotexist.com/plex'
226+
url = movies.getWebURL(base=base)
227+
assert url.startswith(base)
228+
229+
230+
def test_library_MovieSection_PlexWebURL_hub(plex, movies):
231+
hubs = movies.hubs()
232+
hub = next(iter(hubs), None)
233+
assert hub is not None
234+
url = hub.getWebURL()
235+
assert url.startswith('https://app.plex.tv/desktop')
236+
assert plex.machineIdentifier in url
237+
assert 'source=%s' % movies.key in url
238+
assert quote_plus(hub.key) in url
239+
240+
215241
def test_library_ShowSection_all(tvshows):
216242
assert len(tvshows.all(title__iexact="The 100"))
217243

tests/test_photo.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# -*- coding: utf-8 -*-
2+
from urllib.parse import quote_plus
3+
24
from . import test_media, test_mixins
35

46

@@ -22,6 +24,15 @@ def test_photo_Photoalbum_mixins_rating(photoalbum):
2224
test_mixins.edit_rating(photoalbum)
2325

2426

27+
def test_video_Photoalbum_PlexWebURL(plex, photoalbum):
28+
url = photoalbum.getWebURL()
29+
assert url.startswith('https://app.plex.tv/desktop')
30+
assert plex.machineIdentifier in url
31+
assert 'details' in url
32+
assert quote_plus(photoalbum.key) in url
33+
assert 'legacy=1' in url
34+
35+
2536
def test_photo_Photo_mixins_rating(photo):
2637
test_mixins.edit_rating(photo)
2738

@@ -33,3 +44,12 @@ def test_photo_Photo_mixins_tags(photo):
3344
def test_photo_Photo_media_tags(photo):
3445
photo.reload()
3546
test_media.tag_tag(photo)
47+
48+
49+
def test_video_Photo_PlexWebURL(plex, photo):
50+
url = photo.getWebURL()
51+
assert url.startswith('https://app.plex.tv/desktop')
52+
assert plex.machineIdentifier in url
53+
assert 'details' in url
54+
assert quote_plus(photo.parentKey) in url
55+
assert 'legacy=1' in url

tests/test_playlist.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import time
3+
from urllib.parse import quote_plus
34

45
import pytest
56
from plexapi.exceptions import BadRequest, NotFound, Unsupported
@@ -255,3 +256,17 @@ def test_Playlist_exceptions(plex, movies, movie, artist):
255256
playlist.moveItem(movie)
256257
finally:
257258
playlist.delete()
259+
260+
261+
def test_Playlist_PlexWebURL(plex, show):
262+
title = 'test_playlist_plexweburl'
263+
episodes = show.episodes()
264+
playlist = plex.createPlaylist(title, items=episodes[:3])
265+
try:
266+
url = playlist.getWebURL()
267+
assert url.startswith('https://app.plex.tv/desktop')
268+
assert plex.machineIdentifier in url
269+
assert 'playlist' in url
270+
assert quote_plus(playlist.key) in url
271+
finally:
272+
playlist.delete()

tests/test_server.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,16 @@ def test_server_transcode_sessions(plex, requests_mock):
512512
assert session.videoCodec in utils.CODECS
513513
assert session.videoDecision == "transcode"
514514
assert utils.is_int(session.width, gte=852)
515+
516+
517+
def test_server_PlaylistsPlexWebURL(plex):
518+
tab = 'audio'
519+
url = plex.getPlaylistsWebURL(tab=tab)
520+
assert url.startswith('https://app.plex.tv/desktop')
521+
assert plex.machineIdentifier in url
522+
assert 'source=playlists' in url
523+
assert 'pivot=playlists.%s' % tab in url
524+
# Test a different base
525+
base = 'https://doesnotexist.com/plex'
526+
url = plex.getPlaylistsWebURL(base=base)
527+
assert url.startswith(base)

tests/test_video.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,17 @@ def test_video_Movie_extras(movies):
608608
assert extra.type == 'clip'
609609
assert extra.section() == movies
610610

611+
def test_video_Movie_PlexWebURL(plex, movie):
612+
url = movie.getWebURL()
613+
assert url.startswith('https://app.plex.tv/desktop')
614+
assert plex.machineIdentifier in url
615+
assert 'details' in url
616+
assert quote_plus(movie.key) in url
617+
# Test a different base
618+
base = 'https://doesnotexist.com/plex'
619+
url = movie.getWebURL(base=base)
620+
assert url.startswith(base)
621+
611622

612623
def test_video_Show_attrs(show):
613624
assert utils.is_datetime(show.addedAt)
@@ -801,6 +812,14 @@ def test_video_Show_media_tags(show):
801812
test_media.tag_similar(show)
802813

803814

815+
def test_video_Show_PlexWebURL(plex, show):
816+
url = show.getWebURL()
817+
assert url.startswith('https://app.plex.tv/desktop')
818+
assert plex.machineIdentifier in url
819+
assert 'details' in url
820+
assert quote_plus(show.key) in url
821+
822+
804823
def test_video_Season(show):
805824
seasons = show.seasons()
806825
assert len(seasons) == 2
@@ -912,6 +931,14 @@ def test_video_Season_mixins_tags(show):
912931
test_mixins.edit_collection(season)
913932

914933

934+
def test_video_Season_PlexWebURL(plex, season):
935+
url = season.getWebURL()
936+
assert url.startswith('https://app.plex.tv/desktop')
937+
assert plex.machineIdentifier in url
938+
assert 'details' in url
939+
assert quote_plus(season.key) in url
940+
941+
915942
def test_video_Episode_updateProgress(episode, patched_http_call):
916943
episode.updateProgress(2 * 60 * 1000) # 2 minutes.
917944

@@ -1119,6 +1146,14 @@ def test_video_Episode_media_tags(episode):
11191146
test_media.tag_writer(episode)
11201147

11211148

1149+
def test_video_Episode_PlexWebURL(plex, episode):
1150+
url = episode.getWebURL()
1151+
assert url.startswith('https://app.plex.tv/desktop')
1152+
assert plex.machineIdentifier in url
1153+
assert 'details' in url
1154+
assert quote_plus(episode.key) in url
1155+
1156+
11221157
def test_that_reload_return_the_same_object(plex):
11231158
# we want to check this that all the urls are correct
11241159
movie_library_search = plex.library.section("Movies").search("Elephants Dream")[0]

0 commit comments

Comments
 (0)