mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 06:04:15 +00:00
Update sync tests
Fix sync tests
This commit is contained in:
parent
d88d5f7290
commit
8ebe0c7f55
2 changed files with 54 additions and 52 deletions
|
@ -1,5 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from functools import partial
|
||||
from os import environ
|
||||
|
@ -8,8 +9,10 @@ import plexapi
|
|||
import pytest
|
||||
import requests
|
||||
from plexapi.client import PlexClient
|
||||
from plexapi.exceptions import NotFound
|
||||
from plexapi.myplex import MyPlexAccount
|
||||
from plexapi.server import PlexServer
|
||||
from plexapi.utils import createMyPlexDevice
|
||||
|
||||
from .payloads import ACCOUNT_XML
|
||||
|
||||
|
@ -47,6 +50,15 @@ ENTITLEMENTS = {
|
|||
"windows",
|
||||
"windows_phone",
|
||||
}
|
||||
SYNC_DEVICE_IDENTIFIER = "sync-client-%s" % plexapi.X_PLEX_IDENTIFIER
|
||||
SYNC_DEVICE_HEADERS = {
|
||||
"X-Plex-Provides": "sync-target",
|
||||
"X-Plex-Platform": "iOS",
|
||||
"X-Plex-Platform-Version": "11.4.1",
|
||||
"X-Plex-Device": "iPhone",
|
||||
"X-Plex-Device-Name": "Test Sync Device",
|
||||
"X-Plex-Client-Identifier": SYNC_DEVICE_IDENTIFIER
|
||||
}
|
||||
|
||||
TEST_AUTHENTICATED = "authenticated"
|
||||
TEST_ANONYMOUSLY = "anonymously"
|
||||
|
@ -125,19 +137,10 @@ def account_plexpass(account):
|
|||
|
||||
@pytest.fixture(scope="session")
|
||||
def account_synctarget(account_plexpass):
|
||||
assert "sync-target" in plexapi.X_PLEX_PROVIDES, (
|
||||
"You have to set env var " "PLEXAPI_HEADER_PROVIDES=sync-target,controller"
|
||||
)
|
||||
assert "sync-target" in plexapi.BASE_HEADERS["X-Plex-Provides"]
|
||||
assert (
|
||||
"iOS" == plexapi.X_PLEX_PLATFORM
|
||||
), "You have to set env var PLEXAPI_HEADER_PLATFORM=iOS"
|
||||
assert (
|
||||
"11.4.1" == plexapi.X_PLEX_PLATFORM_VERSION
|
||||
), "You have to set env var PLEXAPI_HEADER_PLATFORM_VERSION=11.4.1"
|
||||
assert (
|
||||
"iPhone" == plexapi.X_PLEX_DEVICE
|
||||
), "You have to set env var PLEXAPI_HEADER_DEVICE=iPhone"
|
||||
assert "sync-target" in SYNC_DEVICE_HEADERS["X-Plex-Provides"]
|
||||
assert "iOS" == SYNC_DEVICE_HEADERS["X-Plex-Platform"]
|
||||
assert "11.4.1" == SYNC_DEVICE_HEADERS["X-Plex-Platform-Version"]
|
||||
assert "iPhone" == SYNC_DEVICE_HEADERS["X-Plex-Device"]
|
||||
return account_plexpass
|
||||
|
||||
|
||||
|
@ -159,24 +162,23 @@ def plex(request):
|
|||
|
||||
|
||||
@pytest.fixture()
|
||||
def device(account):
|
||||
d = None
|
||||
for device in account.devices():
|
||||
if device.clientIdentifier == plexapi.X_PLEX_IDENTIFIER:
|
||||
d = device
|
||||
break
|
||||
|
||||
assert d
|
||||
return d
|
||||
def sync_device(account_synctarget):
|
||||
try:
|
||||
device = account_synctarget.device(clientIdentifier=SYNC_DEVICE_IDENTIFIER)
|
||||
except NotFound:
|
||||
device = createMyPlexDevice(SYNC_DEVICE_HEADERS, timeout=10)
|
||||
|
||||
assert device
|
||||
return device
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def clear_sync_device(device, account_synctarget, plex):
|
||||
sync_items = account_synctarget.syncItems(clientId=device.clientIdentifier)
|
||||
def clear_sync_device(sync_device, plex):
|
||||
sync_items = sync_device.syncItems()
|
||||
for item in sync_items.items:
|
||||
item.delete()
|
||||
plex.refreshSync()
|
||||
return device
|
||||
return sync_device
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
@ -5,15 +5,15 @@ from plexapi.sync import (AUDIO_BITRATE_192_KBPS, PHOTO_QUALITY_MEDIUM,
|
|||
from . import conftest as utils
|
||||
|
||||
|
||||
def get_sync_item_from_server(device, sync_item):
|
||||
sync_list = device.syncItems()
|
||||
def get_sync_item_from_server(sync_device, sync_item):
|
||||
sync_list = sync_device.syncItems()
|
||||
for item in sync_list.items:
|
||||
if item.id == sync_item.id:
|
||||
return item
|
||||
|
||||
|
||||
def is_sync_item_missing(device, sync_item):
|
||||
return not get_sync_item_from_server(device, sync_item)
|
||||
def is_sync_item_missing(sync_device, sync_item):
|
||||
return not get_sync_item_from_server(sync_device, sync_item)
|
||||
|
||||
|
||||
def test_current_device_got_sync_target(clear_sync_device):
|
||||
|
@ -38,7 +38,7 @@ def test_add_movie_to_sync(clear_sync_device, movie):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
media_list = utils.wait_until(
|
||||
|
@ -55,7 +55,7 @@ def test_delete_sync_item(clear_sync_device, movie):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
sync_items = clear_sync_device.syncItems()
|
||||
|
@ -65,7 +65,7 @@ def test_delete_sync_item(clear_sync_device, movie):
|
|||
is_sync_item_missing,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item_in_myplex,
|
||||
)
|
||||
|
||||
|
@ -77,7 +77,7 @@ def test_add_show_to_sync(clear_sync_device, show):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
episodes = show.episodes()
|
||||
|
@ -96,7 +96,7 @@ def test_add_season_to_sync(clear_sync_device, show):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
episodes = season.episodes()
|
||||
|
@ -114,7 +114,7 @@ def test_add_episode_to_sync(clear_sync_device, episode):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
media_list = utils.wait_until(
|
||||
|
@ -134,7 +134,7 @@ def test_limited_watched(clear_sync_device, show):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
episodes = show.episodes()[:5]
|
||||
|
@ -162,7 +162,7 @@ def test_limited_unwatched(clear_sync_device, show):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
episodes = show.episodes(viewCount=0)[:5]
|
||||
|
@ -191,7 +191,7 @@ def test_unlimited_and_watched(clear_sync_device, show):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
episodes = show.episodes()
|
||||
|
@ -220,7 +220,7 @@ def test_unlimited_and_unwatched(clear_sync_device, show):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
episodes = show.episodes(viewCount=0)
|
||||
|
@ -246,7 +246,7 @@ def test_add_music_artist_to_sync(clear_sync_device, artist):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
tracks = artist.tracks()
|
||||
|
@ -264,7 +264,7 @@ def test_add_music_album_to_sync(clear_sync_device, album):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
tracks = album.tracks()
|
||||
|
@ -282,7 +282,7 @@ def test_add_music_track_to_sync(clear_sync_device, track):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
media_list = utils.wait_until(
|
||||
|
@ -300,7 +300,7 @@ def test_add_photo_to_sync(clear_sync_device, photoalbum):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
media_list = utils.wait_until(
|
||||
|
@ -317,7 +317,7 @@ def test_sync_entire_library_movies(clear_sync_device, movies):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
section_content = movies.all()
|
||||
|
@ -335,7 +335,7 @@ def test_sync_entire_library_tvshows(clear_sync_device, tvshows):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
section_content = tvshows.searchEpisodes()
|
||||
|
@ -353,7 +353,7 @@ def test_sync_entire_library_music(clear_sync_device, music):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
section_content = music.searchTracks()
|
||||
|
@ -371,7 +371,7 @@ def test_sync_entire_library_photos(clear_sync_device, photos):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
# It's not that easy, to just get all the photos within the library, so let`s query for photos with device!=0x0
|
||||
|
@ -394,7 +394,7 @@ def test_playlist_movie_sync(plex, clear_sync_device, movies):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
media_list = utils.wait_until(
|
||||
|
@ -416,7 +416,7 @@ def test_playlist_tvshow_sync(plex, clear_sync_device, show):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
media_list = utils.wait_until(
|
||||
|
@ -438,7 +438,7 @@ def test_playlist_mixed_sync(plex, clear_sync_device, movie, episode):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
media_list = utils.wait_until(
|
||||
|
@ -460,7 +460,7 @@ def test_playlist_music_sync(plex, clear_sync_device, artist):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
media_list = utils.wait_until(
|
||||
|
@ -482,7 +482,7 @@ def test_playlist_photos_sync(plex, clear_sync_device, photoalbum):
|
|||
get_sync_item_from_server,
|
||||
delay=0.5,
|
||||
timeout=3,
|
||||
device=clear_sync_device,
|
||||
sync_device=clear_sync_device,
|
||||
sync_item=new_item,
|
||||
)
|
||||
media_list = utils.wait_until(
|
||||
|
|
Loading…
Reference in a new issue