From 8056c4b9ad7e6a3529f26c70c3492de021415b8a Mon Sep 17 00:00:00 2001 From: Justin Emter Date: Fri, 11 Aug 2017 14:09:44 -0700 Subject: [PATCH] Started adding test runners. --- .gitignore | 1 + pseudo_config.py | 8 ++++-- requirements.txt | 2 ++ src/Helpers.py | 43 +++++++++++++++++++++++++++++ startstop.sh | 3 +- tests/__init__.py | 0 tests/test_commercial_injection.py | 17 ++++++++++++ tests/test_update_daily_schedule.py | 25 +++++++++++++++++ 8 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 src/Helpers.py create mode 100644 tests/__init__.py create mode 100644 tests/test_commercial_injection.py create mode 100644 tests/test_update_daily_schedule.py diff --git a/.gitignore b/.gitignore index 5f26756..33d01ce 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ env/ *.log *.pid *.json +.cache/ diff --git a/pseudo_config.py b/pseudo_config.py index 7f625a3..c07c8f9 100644 --- a/pseudo_config.py +++ b/pseudo_config.py @@ -5,7 +5,7 @@ touch ../plex_token.py - 2) add this line to the newly created file: + 2) add these lines to the newly created file: baseurl = 'the url to your server' token = 'your plex token' @@ -20,7 +20,7 @@ "Movies" : ["Films"], - 6) For Google Calendar integration add your "gkey" to the "plex_token.py" file + 6) *Skip this feature for now* For Google Calendar integration add your "gkey" to the "plex_token.py" file ...(https://docs.simplecalendar.io/find-google-calendar-id/): gkey = "the key" @@ -61,7 +61,7 @@ plexLibraries = { useCommercialInjection = True -# How many seconds to pad commercials between each other / other media +"""How many seconds to pad commercials between each other / other media""" commercialPadding = 5 """ @@ -83,6 +83,8 @@ useDailyOverlapCache = True dailyUpdateTime = "12:00 AM" +"""Debug mode will give you more output in your terminal to help problem solve issues.s""" debug_mode = True +"""---""" useGoogleCalendar = False \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index c9b7400..81dec23 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,8 +8,10 @@ idna==2.5 kombu==4.1.0 oauth2client==4.1.2 PlexAPI==2.0.2 +py==1.4.34 pyasn1==0.3.2 pyasn1-modules==0.0.11 +pytest==3.2.1 pytz==2017.2 requests==2.18.3 rsa==3.4.2 diff --git a/src/Helpers.py b/src/Helpers.py new file mode 100644 index 0000000..b75eea2 --- /dev/null +++ b/src/Helpers.py @@ -0,0 +1,43 @@ +import os + +import logging + +class Helpers(): + """Class for consolidating helper methods""" + + def __init__(self): + + pass + + def save_file(self, data, filename, path, overwrite=True): + + fileName = filename + + writepath = path + + if not os.path.exists(writepath): + + os.makedirs(writepath) + + if os.path.exists(writepath+fileName) and overwrite: + + os.remove(writepath+fileName) + + mode = 'a' if os.path.exists(writepath) else 'w' + + with open(writepath+fileName, mode) as f: + + f.write(data) + + def get_file(self, filename, path): + + if not os.path.exists(writepath): + + raise IOError("{}, doesn't exist").format(writepath) + + if not os.path.exists(writepath+fileName): + + raise IOError("{}, doesn't exist").format(fileName) + + return None + diff --git a/startstop.sh b/startstop.sh index 2e97c34..358be58 100755 --- a/startstop.sh +++ b/startstop.sh @@ -27,6 +27,7 @@ if [ ! -e $output_pid_path/$pid_file ]; then nohup $python_to_use ./PseudoChannel.py -m -r > /dev/null 2>&1 & echo $! > $output_pid_path/$pid_file echo "Started PseudoChannel.py @ Process: $!" + sleep .7 echo "Created $pid_file file in $output_pid_path dir" else @@ -39,7 +40,7 @@ else while [ -e /proc/$the_pid ] do echo "PseudoChannel.py @: $the_pid is still running" - sleep .6 + sleep .7 done echo "PseudoChannel.py @: $the_pid has finished" diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_commercial_injection.py b/tests/test_commercial_injection.py new file mode 100644 index 0000000..42d93d2 --- /dev/null +++ b/tests/test_commercial_injection.py @@ -0,0 +1,17 @@ +import pytest +import datetime + +@pytest.mark.parametrize("commercial, expected", [ + (["1", "1501900754", "3", "001 - Kit_Kat_Commercial_-_Give_Me_A_Break_1988", "30890", "/library/metadata/3854"], 35890) +]) +def test_pad_the_commercial_dur(commercial, expected): + + commercial_as_list = list(commercial) + + commercial_as_list[4] = int(commercial_as_list[4]) + (5 * 1000) + + assert int(commercial_as_list[4]) == expected + +def test_inject_commercials(): + + pass \ No newline at end of file diff --git a/tests/test_update_daily_schedule.py b/tests/test_update_daily_schedule.py new file mode 100644 index 0000000..9788b85 --- /dev/null +++ b/tests/test_update_daily_schedule.py @@ -0,0 +1,25 @@ +import pytest +import datetime + +@pytest.mark.parametrize("prevstartime, prevendtime, nowtime, expected", [ + ("04:55:00 PM", "1900-01-01 17:23:42.304000", "1900-01-01 17:10:42.304000", True), + ("04:55:00 PM", "1900-01-01 17:23:42.304000", "1900-01-01 16:56:42.304000", True), + ("04:55:00 PM", "1900-01-01 17:23:42.304000", "1900-01-01 16:59:42.304000", True), + ("04:55:00 PM", "1900-01-01 17:23:42.304000", "1900-01-01 17:02:42.304000", True), + ("04:55:00 PM", "1900-01-01 17:23:42.304000", "1900-01-01 17:15:42.304000", True), + ("04:55:00 PM", "1900-01-01 17:23:42.304000", "1900-01-01 17:23:43.304000", False), + ("04:55:00 PM", "1900-01-01 17:23:42.304000", "1900-01-01 17:25:00.304000", False), +]) +def test_prev_day_media_still_playing_on_update(prevendtime, prevstartime, nowtime, expected): + + prev_end_time_to_watch_for = None + + now = datetime.datetime.strptime(nowtime, '%Y-%m-%d %H:%M:%S.%f') + + prev_start_time = datetime.datetime.strptime(prevstartime, "%I:%M:%S %p") + + prev_end_time_format = '%Y-%m-%d %H:%M:%S.%f' if '.' in prevendtime else '%Y-%m-%d %H:%M:%S' + + prev_end_time = datetime.datetime.strptime(prevendtime, prev_end_time_format) + + assert (prev_start_time < now and prev_end_time > now) == expected \ No newline at end of file