Skip to content

Commit a568819

Browse files
authored
Add tests for theme mixin (#897)
* Add lockTheme and unlockTheme methods * Change setTheme to raise NotImplementedError * Add tests for theme mixins
1 parent caf3910 commit a568819

File tree

5 files changed

+242
-153
lines changed

5 files changed

+242
-153
lines changed

plexapi/mixins.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,18 @@ def uploadTheme(self, url=None, filepath=None):
244244
self._server.query(key, method=self._server._session.post, data=data)
245245

246246
def setTheme(self, theme):
247-
""" Set the theme for a Plex object.
248-
249-
Parameters:
250-
theme (:class:`~plexapi.media.Theme`): The theme object to select.
251-
"""
252-
theme.select()
247+
raise NotImplementedError(
248+
'Themes cannot be set through the API. '
249+
'Re-upload the theme using "uploadTheme" to set it.'
250+
)
251+
252+
def lockTheme(self):
253+
""" Lock the theme for a Plex object. """
254+
self._edit(**{'theme.locked': 1})
255+
256+
def unlockTheme(self):
257+
""" Unlock the theme for a Plex object. """
258+
self._edit(**{'theme.locked': 0})
253259

254260

255261
class RatingMixin(object):

tests/test_audio.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_audio_Artist_attr(artist):
3232
assert isinstance(artist.similar, list)
3333
if artist.summary:
3434
assert "Alias" in artist.summary
35+
assert artist.theme is None
3536
if artist.thumb:
3637
assert utils.is_thumb(artist.thumb)
3738
assert artist.title == "Broke For Free"
@@ -95,6 +96,10 @@ def test_audio_Artist_mixins_images(artist):
9596
test_mixins.attr_posterUrl(artist)
9697

9798

99+
def test_audio_Artist_mixins_themes(artist):
100+
test_mixins.edit_theme(artist)
101+
102+
98103
def test_audio_Artist_mixins_rating(artist):
99104
test_mixins.edit_rating(artist)
100105

@@ -143,6 +148,7 @@ def test_audio_Album_attrs(album):
143148
assert utils.is_datetime(album.originallyAvailableAt)
144149
assert utils.is_metadata(album.parentKey)
145150
assert utils.is_int(album.parentRatingKey)
151+
assert album.parentTheme is None or utils.is_metadata(album.parentTheme)
146152
if album.parentThumb:
147153
assert utils.is_thumb(album.parentThumb)
148154
assert album.parentTitle == "Broke For Free"
@@ -206,6 +212,10 @@ def test_audio_Album_mixins_images(album):
206212
test_mixins.attr_posterUrl(album)
207213

208214

215+
def test_audio_Album_mixins_themes(album):
216+
test_mixins.attr_themeUrl(album)
217+
218+
209219
def test_audio_Album_mixins_rating(album):
210220
test_mixins.edit_rating(album)
211221

@@ -246,6 +256,7 @@ def test_audio_Track_attrs(album):
246256
assert utils.is_art(track.grandparentArt)
247257
assert utils.is_metadata(track.grandparentKey)
248258
assert utils.is_int(track.grandparentRatingKey)
259+
assert track.grandparentTheme is None or utils.is_metadata(track.grandparentTheme)
249260
if track.grandparentThumb:
250261
assert utils.is_thumb(track.grandparentThumb)
251262
assert track.grandparentTitle == "Broke For Free"
@@ -363,6 +374,10 @@ def test_audio_Track_mixins_images(track):
363374
test_mixins.attr_posterUrl(track)
364375

365376

377+
def test_audio_Track_mixins_themes(track):
378+
test_mixins.attr_themeUrl(track)
379+
380+
366381
def test_audio_Track_mixins_rating(track):
367382
test_mixins.edit_rating(track)
368383

tests/test_collection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_Collection_attrs(collection):
3333
assert collection.smart is False
3434
assert collection.subtype == "movie"
3535
assert collection.summary == ""
36+
assert collection.theme is None
3637
assert collection.thumb.startswith("/library/collections/%s/composite" % collection.ratingKey)
3738
assert collection.thumbBlurHash is None
3839
assert collection.title == "Test Collection"
@@ -282,6 +283,10 @@ def test_Collection_mixins_images(collection):
282283
test_mixins.attr_posterUrl(collection)
283284

284285

286+
def test_Collection_mixins_themes(collection):
287+
test_mixins.edit_theme(collection)
288+
289+
285290
def test_Collection_mixins_rating(collection):
286291
test_mixins.edit_rating(collection)
287292

tests/test_mixins.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
TEST_MIXIN_TAG = "Test Tag"
99
CUTE_CAT_SHA1 = "9f7003fc401761d8e0b0364d428b2dab2f789dbb"
10+
AUDIO_STUB_SHA1 = "1abc20d5fdc904201bf8988ca6ef30f96bb73617"
1011

1112

1213
def _test_mixins_tag(obj, attr, tag_method):
@@ -180,6 +181,48 @@ def attr_posterUrl(obj):
180181
_test_mixins_imageUrl(obj, "thumb")
181182

182183

184+
def _test_mixins_edit_theme(obj):
185+
_fields = lambda: [f.name for f in obj.fields]
186+
# Test upload theme from file
187+
obj.uploadTheme(filepath=utils.STUB_MP3_PATH)
188+
themes = obj.themes()
189+
file_theme = [
190+
t for t in themes
191+
if t.ratingKey.startswith("upload://") and t.ratingKey.endswith(AUDIO_STUB_SHA1)
192+
]
193+
assert file_theme
194+
obj.reload()
195+
assert "theme" in _fields()
196+
# Unlock the theme
197+
obj.unlockTheme()
198+
obj.reload()
199+
assert "theme" not in _fields()
200+
# Lock the theme
201+
obj.lockTheme()
202+
obj.reload()
203+
assert "theme" in _fields()
204+
with pytest.raises(NotImplementedError):
205+
obj.setTheme(themes[0])
206+
207+
208+
def edit_theme(obj):
209+
_test_mixins_edit_theme(obj)
210+
211+
212+
def _test_mixins_themeUrl(obj):
213+
url = obj.themeUrl
214+
if url:
215+
assert url.startswith(utils.SERVER_BASEURL)
216+
assert "/library/metadata/" in url
217+
assert "theme" in url
218+
else:
219+
assert url is None
220+
221+
222+
def attr_themeUrl(obj):
223+
_test_mixins_themeUrl(obj)
224+
225+
183226
def _test_mixins_editAdvanced(obj):
184227
for pref in obj.preferences():
185228
currentPref = obj.preference(pref.id)

0 commit comments

Comments
 (0)