Started adding test runners.

This commit is contained in:
Justin Emter
2017-08-11 14:09:44 -07:00
parent 7f06384c2f
commit 8056c4b9ad
8 changed files with 95 additions and 4 deletions

1
.gitignore vendored
View File

@@ -12,3 +12,4 @@ env/
*.log
*.pid
*.json
.cache/

View File

@@ -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

View File

@@ -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

43
src/Helpers.py Normal file
View File

@@ -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

View File

@@ -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"

0
tests/__init__.py Normal file
View File

View File

@@ -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

View File

@@ -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