diff --git a/bw_plex/plex.py b/bw_plex/plex.py index a865233..a9387fd 100644 --- a/bw_plex/plex.py +++ b/bw_plex/plex.py @@ -133,10 +133,6 @@ def process_to_db(media, theme=None, vid=None, start=None, end=None, ffmpeg_end= add_images = False edl_file = None - # Disable for now. - # if media.TYPE == 'movie': - # return - # This will download the theme and add it to # the hashtable if its missing if media.TYPE == 'episode' and theme is None: @@ -252,7 +248,7 @@ def process_to_db(media, theme=None, vid=None, start=None, end=None, ffmpeg_end= except NoResultFound: add_images = True - #if media.TYPE == 'episode' and CONFIG.get('hashing').get('check_frames') is True and add_images: + # if media.TYPE == 'episode' and CONFIG.get('hashing').get('check_frames') is True and add_images: # img_hashes = [] # Check this later TODO # for imghash, _, pos in hash_file(check_file_access(media)): # Add config option of get frames ever n. @@ -546,7 +542,7 @@ def ffmpeg_process(name, trim, dev, da, dv, pix_th, au_db): # pragma: no cover @click.option('-t', default='scene marker', type=click.Choice(['cut', 'scene marker', 'mute', 'commercial break']), help='What type of edl is this') @click.option('-sp', '--save_path', default=None) -def create_edl_from_db(t, save_path): +def create_edl_from_db(t, save_path): # pragma: no cover with session_scope() as se: db_items = se.query(Processed).all() for item in db_items: @@ -878,7 +874,7 @@ def export_db(format, save_path, write_file, show_html): click.echo(t) -def check_file_access(m): +def check_file_access(m): # pragma: no cover """Check if we can reach the file directly or if we have to download it via PMS. @@ -1388,7 +1384,7 @@ if os.name != 'nt': signal.signal(signal.SIGHUP, shutdown_handler) signal.signal(signal.SIGINT, shutdown_handler) -else: +else: # pragma: no cover signal.signal(signal.SIGINT, shutdown_handler) @@ -1400,7 +1396,7 @@ def real_main(): finally: pass # Make sure we save if we need it. - #if HT and HT.dirty: + # if HT and HT.dirty: # HT.save() diff --git a/tests/conftest.py b/tests/conftest.py index f3653aa..0e8b745 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,13 +1,13 @@ import os import shutil import sys +import time import tempfile from datetime import datetime as DT from plexapi.video import Episode, Show, Movie from plexapi.media import MediaPart -# from plexapi.compat import makedirs import pytest fp = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'bw_plex') @@ -17,8 +17,14 @@ sys.path.insert(1, fp) import bw_plex -bw_plex.init(folder=os.path.join(tempfile.gettempdir(), 'bw_plex_test_root'), debug=True) +TEST_ROOT = os.path.join(tempfile.gettempdir(), 'bw_plex_test_root') +# Delete any old test this was this shit keeps filling my disks. +# cba with travis. +if 'TRAVIS' not in os.environ and os.path.exists(TEST_ROOT): + shutil.rmtree(TEST_ROOT) + +bw_plex.init(folder=os.path.join(tempfile.gettempdir(), 'bw_plex_test_root'), debug=True) # Do not remove these imports.. import bw_plex.plex as plex diff --git a/tests/test_cli.py b/tests/test_cli.py index a380ea6..c0f30d6 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -68,13 +68,20 @@ def test_check(episode, film, intro_file, cli_runner, tmpdir, monkeypatch, HT, m #plex.POOL.close() #plex.POOL.join() + # Lets try again is the added same shit + # as the the same info will come each tick. + rr = plex.check(data) + if rr is not None: + rr.get() + with plex.session_scope() as se: assert se.query(plex.Processed).filter_by(ratingKey=episode.ratingKey).one() # lets check that we can export db shit too. tmp = str(tmpdir) res = cli_runner.invoke(plex.export_db, ['-f', 'json', '-fp', tmp, '-wf']) - print(res.output) + assert res.exit_code == 0 + # print(res.output) fp = os.path.join(tmp, 'Processed.json') assert os.path.exists(fp) @@ -176,71 +183,29 @@ def test_process(cli_runner, monkeypatch, episode, film, media, HT, intro_file, monkeypatch.setattr(plex, 'find_next', lambda k: None) res = cli_runner.invoke(plex.process, ['-n', 'dexter', '-s', '1', '-t', '2']) - #print(res.output) + print(res.output) monkeypatch.setattr(plex, 'PMS', mf) res = cli_runner.invoke(plex.process, ['-n', 'Random', '-s', '1', '-sd']) + print(res.output) def test_add_theme_to_hashtable(cli_runner, monkeypatch, HT): # We just want to check that this doesnt blow up.. monkeypatch.setattr(plex, 'get_hashtable', HT) - cli_runner.invoke(plex.add_theme_to_hashtable, [2, None]) + ret = cli_runner.invoke(plex.add_theme_to_hashtable, [2, None]) + assert ret.exit_code == 0 + def test_ffmpeg_process(cli_runner, intro_file): res = cli_runner.invoke(plex.ffmpeg_process, [intro_file]) assert len(res.output) + assert res.exit_code == 0 # In short we miss on this episode as we find the start of the theme, not the end. # correct value should be sec ~217. # we dont care about the result. This file is already test other places. -def test_manually_correct_theme(): +def _test_manually_correct_theme(): pass - - -# Disable for now. Add this to test_check. -def _test_timeline(intro_file, HT, monkeypatch, mocker, episode): - - def fetchItem(i): - return episode - m = mocker.Mock() - m.fetchItem = fetchItem - - monkeypatch.setitem(plex.CONFIG, 'theme_source', 'tvtunes') - monkeypatch.setattr(plex, 'check_file_access', lambda k: intro_file) - monkeypatch.setattr(plex, 'HT', HT) - monkeypatch.setattr(plex, 'PMS', m) - monkeypatch.setattr(plex, 'find_next', lambda k: None) - - data = {"type": "timeline", - "size": 1, - "TimelineEntry": [{"identifier": "com.plexapp.plugins.library", - "sectionID": 2, - "itemID": 1337, - "type": 4, - "title": "Dexter S01 E01", - "state": 0, - "mediaState": "created", - "queueSize": 8, - "updatedAt": 1526744644}] - } - - deleted_dict = {'type': 'timeline', - 'size': 1, - 'TimelineEntry': [{'identifier': 'com.plexapp.plugins.library', - 'sectionID': 2, - 'itemID': 2041, - 'parentItemID': 2035, - 'rootItemID': 2032, - 'type': 4, - 'title': '2 Broke Girls S01 E06', - 'state': 9, - 'metadataState': 'deleted', - 'updatedAt': 1526859691}]} - - plex.timeline(data) - plex.POOL.close() - plex.POOL.join() - assert len(HT.get_theme(episode)) diff --git a/tests/test_data/test_config.ini b/tests/test_data/test_config.ini index c0b8ac3..e90ed24 100644 --- a/tests/test_data/test_config.ini +++ b/tests/test_data/test_config.ini @@ -8,13 +8,10 @@ ignore_outro_ratingkeys = , # this is used add to the progress we we can start skip faster. no_wait_tick = 0 -# The level if removed but its left in the test_config to to check the migrate -level = info - # Clients and users are a whitelist! empty allows all. clients = , users = , -loglevel = debug +loglevel = info [server] url =