python-plexapi/tests/conftest.py

147 lines
3.5 KiB
Python
Raw Normal View History

2017-02-02 04:47:22 +00:00
# -*- coding: utf-8 -*-
import betamax, os, plexapi
import pytest, requests
2017-01-09 14:21:54 +00:00
from betamax_serializers import pretty_json
2017-02-02 04:47:22 +00:00
from functools import partial
2017-01-09 14:21:54 +00:00
test_baseurl = plexapi.CONFIG.get('auth.server_baseurl')
test_token = plexapi.CONFIG.get('auth.server_token')
test_username = plexapi.CONFIG.get('auth.myplex_username')
test_password = plexapi.CONFIG.get('auth.myplex_password')
2017-01-09 14:21:54 +00:00
@pytest.fixture(scope='session')
def pms(request):
from plexapi.server import PlexServer
sess = requests.Session()
2017-02-02 04:47:22 +00:00
# CASSETTE_LIBRARY_DIR = 'response/'
# betamax.Betamax.register_serializer(pretty_json.PrettyJSONSerializer)
# config = betamax.Betamax.configure()
# config.define_cassette_placeholder('MASKED', token)
# config.define_cassette_placeholder('MASKED', test_token)
# recorder = betamax.Betamax(sess, cassette_library_dir=CASSETTE_LIBRARY_DIR)
# recorder.use_cassette('http_responses', serialize_with='prettyjson') # record='new_episodes'
# recorder.start()
assert test_baseurl
2017-01-09 14:21:54 +00:00
assert test_token
pms = PlexServer(test_baseurl, test_token, session=sess)
2017-01-09 14:21:54 +00:00
#request.addfinalizer(recorder.stop)
return pms
2017-01-31 00:02:22 +00:00
@pytest.fixture()
def freshpms():
from plexapi.server import PlexServer
sess = requests.Session()
assert test_baseurl
2017-01-31 00:02:22 +00:00
assert test_token
pms = PlexServer(test_baseurl, test_token, session=sess)
2017-01-31 00:02:22 +00:00
return pms
2017-01-09 14:21:54 +00:00
def pytest_addoption(parser):
parser.addoption("--req_client", action="store_true",
2017-02-02 04:47:22 +00:00
help="Run tests that interact with a client")
2017-01-09 14:21:54 +00:00
def pytest_runtest_setup(item):
if 'req_client' in item.keywords and not item.config.getvalue("req_client"):
pytest.skip("need --req_client option to run")
else:
item.config.getvalue("req_client")
@pytest.fixture()
def plex_account():
from plexapi.myplex import MyPlexAccount
username = test_username
password = test_password
assert username and password
account = MyPlexAccount(username, password)
2017-01-09 14:21:54 +00:00
assert account
return account
@pytest.fixture()
def a_movie(pms):
m = pms.library.search('16 blocks')
assert m
return m[0]
@pytest.fixture()
def a_tv_section(pms):
sec = pms.library.section('TV Shows')
assert sec
return sec
@pytest.fixture()
def a_movie_section(pms):
sec = pms.library.section('Movies')
assert sec
return sec
@pytest.fixture()
def a_music_section(pms):
sec = pms.library.section('Music')
assert sec
2017-01-31 00:02:22 +00:00
return sec
@pytest.fixture()
def a_photo_section(pms):
sec = pms.library.section('Photos')
assert sec
2017-01-09 14:21:54 +00:00
return sec
@pytest.fixture()
def a_artist(a_music_section):
sec = a_music_section.get('Infinite State')
assert sec
return sec
@pytest.fixture()
def a_music_album(a_music_section):
sec = a_music_section.get('Infinite State').album('Unmastered Impulses')
assert sec
return sec
@pytest.fixture()
def a_track(a_music_album):
track = a_music_album.track('Holy Moment')
assert track
return track
@pytest.fixture()
def a_show(a_tv_section):
sec = a_tv_section.get('The 100')
assert sec
return sec
@pytest.fixture()
def a_episode(a_show):
ep = a_show.get('Pilot')
assert ep
return ep
@pytest.fixture()
def a_photo_album(pms):
sec = pms.library.section('Photos')
assert sec
album = sec.get('photo_album1')
assert album
return album
@pytest.fixture()
def monkeydownload(request, monkeypatch):
monkeypatch.setattr('plexapi.utils.download', partial(plexapi.utils.download, mocked=True))
yield
monkeypatch.undo()