Skip to content

Commit 7fedd01

Browse files
committed
Test locking/unlocking fields when adding/removing tags
1 parent 84f787a commit 7fedd01

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

plexapi/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,15 @@ def download(url, token, filename=None, savepath=None, session=None, chunksize=4
335335
return fullpath
336336

337337

338+
def tag_singular(tag):
339+
if tag == 'countries':
340+
return 'country'
341+
elif tag == 'similar':
342+
return 'similar'
343+
else:
344+
return tag[:-1]
345+
346+
338347
def tag_plural(tag):
339348
if tag == 'country':
340349
return 'countries'

tests/test_mixins.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
# -*- coding: utf-8 -*-
2+
from plexapi.utils import tag_singular
3+
24
TEST_MIXIN_TAG = "Test Tag"
35

46

57
def _test_mixins_tag(obj, attr, tag_method):
68
add_tag_method = getattr(obj, "add" + tag_method)
79
remove_tag_method = getattr(obj, "remove" + tag_method)
10+
field_name = tag_singular(attr)
11+
# Check tag is not present to begin with
812
assert TEST_MIXIN_TAG not in [tag.tag for tag in getattr(obj, attr)]
13+
# Add tag and lock the field
914
add_tag_method(TEST_MIXIN_TAG)
1015
obj.reload()
16+
field = [f for f in obj.fields if f.name == field_name]
1117
assert TEST_MIXIN_TAG in [tag.tag for tag in getattr(obj, attr)]
12-
remove_tag_method(TEST_MIXIN_TAG)
18+
assert field and field[0].locked
19+
# Remove tag and unlock to field to restore the clean state
20+
remove_tag_method(TEST_MIXIN_TAG, locked=False)
1321
obj.reload()
22+
field = [f for f in obj.fields if f.name == field_name]
1423
assert TEST_MIXIN_TAG not in [tag.tag for tag in getattr(obj, attr)]
24+
assert not field
1525

1626

1727
def edit_collection(obj):

0 commit comments

Comments
 (0)