Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.

Commit

Permalink
Add subfolder path test
Browse files Browse the repository at this point in the history
  • Loading branch information
RuudBurger committed Jun 24, 2014
1 parent 5c586fb commit 7401201
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion couchpotato/core/plugins/file.py
Expand Up @@ -5,7 +5,7 @@
from couchpotato.api import addApiView
from couchpotato.core.event import addEvent, fireEvent
from couchpotato.core.helpers.encoding import toUnicode
from couchpotato.core.helpers.variable import md5, getExt
from couchpotato.core.helpers.variable import md5, getExt, isSubFolder
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env
Expand All @@ -32,6 +32,8 @@ def __init__(self):

fireEvent('schedule.interval', 'file.cleanup', self.cleanup, hours = 24)

addEvent('app.test', self.doSubfolderTest)

def cleanup(self):

# Wait a bit after starting before cleanup
Expand Down Expand Up @@ -76,3 +78,32 @@ def download(self, url = '', dest = None, overwrite = False, urlopen_kwargs = No

self.createFile(dest, filedata, binary = True)
return dest

def doSubfolderTest(self):

tests = {
('/test/sub/folder', '/test/sub'): True,
('/test/sub/folder', '/test/sub2'): False,
('/sub/fold', '/test/sub/fold'): False,
('/sub/fold', '/test/sub/folder'): False,
('/opt/couchpotato', '/var/opt/couchpotato'): False,
('/var/opt', '/var/opt/couchpotato'): False,
('/CapItaLs/Are/OK', '/CapItaLs/Are/OK'): True,
('/CapItaLs/Are/OK', '/CapItaLs/Are/OK2'): False,
('/capitals/are/not/OK', '/capitals/are/NOT'): False,
('\\\\Mounted\\Volume\\Test', '\\\\Mounted\\Volume'): True,
('C:\\\\test\\path', 'C:\\\\test2'): False
}

failed = 0
for x in tests:
if isSubFolder(x[0], x[1]) is not tests[x]:
log.error('Failed subfolder test %s %s', x)
failed += 1

if failed > 0:
log.error('Subfolder test failed %s tests', failed)
else:
log.info('Subfolder test succeeded')

return failed == 0

0 comments on commit 7401201

Please sign in to comment.